Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 880ad4db

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 880ad4dbf26833b8591b0a63f32d4a864d3caa25
  • Vorgänger f7551e1c
  • Nachfolger 8d21fecc

Template-Plugin LxLatex: neue Funktion filter_html()

Konvertiert HTML nach LaTeX.

Unterschiede anzeigen:

SL/Template/Plugin/LxLatex.pm
24 24
  return $::locale->quote_special_chars('Template/LaTeX', $text);
25 25
}
26 26

  
27
my %html_replace = (
28
  '</p>'      => "\n\n",
29
  '<ul>'      => "\\begin{itemize} ",
30
  '</ul>'     => "\\end{itemize} ",
31
  '<ol>'      => "\\begin{enumerate} ",
32
  '</ol>'     => "\\end{enumerate} ",
33
  '<li>'      => "\\item ",
34
  '</li>'     => " ",
35
  '<b>'       => "\\textbf{",
36
  '</b>'      => "}",
37
  '<strong>'  => "\\textbf{",
38
  '</strong>' => "}",
39
  '<i>'       => "\\textit{",
40
  '</i>'      => "}",
41
  '<em>'      => "\\textit{",
42
  '</em>'     => "}",
43
  '<u>'       => "\\underline{",
44
  '</u>'      => "}",
45
  '<s>'       => "\\sout{",
46
  '</s>'      => "}",
47
  '<sub>'     => "\\textsubscript{",
48
  '</sub>'    => "}",
49
  '<sup>'     => "\\textsuperscript{",
50
  '</sup>'    => "}",
51
  '<br/>'     => "\\newline ",
52
  '<br>'      => "\\newline ",
53
);
54

  
55
sub filter_html {
56
  my ($self, $text, $args) = @_;
57

  
58
  $text =~ s{ \r+ }{}gx;
59
  $text =~ s{ \n+ }{ }gx;
60
  $text =~ s{ (?:\&nbsp;|\s)+ }{ }gx;
61

  
62
  my @parts = map {
63
    if (substr($_, 0, 1) eq '<') {
64
      s{ +}{}g;
65
      $html_replace{$_} || '';
66

  
67
    } else {
68
      $::locale->quote_special_chars('Template/LaTeX', HTML::Entities::decode_entities($_));
69
    }
70
  } split(m{(<.*?>)}x, $text);
71

  
72
  return join('', @parts);
73
}
74

  
27 75
return 'SL::Template::Plugin::LxLatex';

Auch abrufbar als: Unified diff