From 880ad4dbf26833b8591b0a63f32d4a864d3caa25 Mon Sep 17 00:00:00 2001
From: Moritz Bunkus
Date: Wed, 22 Jan 2014 14:45:45 +0100
Subject: [PATCH] Template-Plugin LxLatex: neue Funktion filter_html()
Konvertiert HTML nach LaTeX.
---
SL/Template/Plugin/LxLatex.pm | 48 +++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
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",
+ '' => "\\begin{itemize} ",
+ '
' => "\\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';
--
2.20.1