From: Moritz Bunkus Date: Wed, 22 Jan 2014 13:45:45 +0000 (+0100) Subject: Template-Plugin LxLatex: neue Funktion filter_html() X-Git-Tag: release-3.2.0beta~467^2~24 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=880ad4dbf26833b8591b0a63f32d4a864d3caa25;p=kivitendo-erp.git Template-Plugin LxLatex: neue Funktion filter_html() Konvertiert HTML nach LaTeX. --- diff --git a/SL/Template/Plugin/LxLatex.pm b/SL/Template/Plugin/LxLatex.pm index fbbd53c2d..13687fb1e 100644 --- a/SL/Template/Plugin/LxLatex.pm +++ b/SL/Template/Plugin/LxLatex.pm @@ -24,4 +24,52 @@ sub filter { return $::locale->quote_special_chars('Template/LaTeX', $text); } +my %html_replace = ( + '

' => "\n\n", + '' => "\\end{itemize} ", + '
    ' => "\\begin{enumerate} ", + '
' => "\\end{enumerate} ", + '
  • ' => "\\item ", + '
  • ' => " ", + '' => "\\textbf{", + '' => "}", + '' => "\\textbf{", + '' => "}", + '' => "\\textit{", + '' => "}", + '' => "\\textit{", + '' => "}", + '' => "\\underline{", + '' => "}", + '' => "\\sout{", + '' => "}", + '' => "\\textsubscript{", + '' => "}", + '' => "\\textsuperscript{", + '' => "}", + '
    ' => "\\newline ", + '
    ' => "\\newline ", +); + +sub filter_html { + my ($self, $text, $args) = @_; + + $text =~ s{ \r+ }{}gx; + $text =~ s{ \n+ }{ }gx; + $text =~ s{ (?:\ |\s)+ }{ }gx; + + my @parts = map { + if (substr($_, 0, 1) eq '<') { + s{ +}{}g; + $html_replace{$_} || ''; + + } else { + $::locale->quote_special_chars('Template/LaTeX', HTML::Entities::decode_entities($_)); + } + } split(m{(<.*?>)}x, $text); + + return join('', @parts); +} + return 'SL::Template::Plugin::LxLatex';