X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate%2FPlugin%2FKiviLatex.pm;h=920dee49bee42b4c2d260a1dfa872ba758075065;hb=b293ff8ad52fc76ba0c44783e3982418114d6b08;hp=21b0779df6e5d2c9ef8ade9b59e18d4d7441d964;hpb=f623b7217e996bf49442c7aa8266c0c468c88e99;p=kivitendo-erp.git diff --git a/SL/Template/Plugin/KiviLatex.pm b/SL/Template/Plugin/KiviLatex.pm index 21b0779df..920dee49b 100644 --- a/SL/Template/Plugin/KiviLatex.pm +++ b/SL/Template/Plugin/KiviLatex.pm @@ -3,6 +3,8 @@ package SL::Template::Plugin::KiviLatex; use strict; use parent qw( Template::Plugin::Filter ); +use SL::Template::LaTeX; + my $cached_instance; sub new { @@ -40,7 +42,7 @@ my %html_replace = ( '' => "}", '' => "\\textit{", '' => "}", - '' => "\\underline{", + '' => "\\uline{", '' => "}", '' => "\\sout{", '' => "}", @@ -55,21 +57,110 @@ my %html_replace = ( 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{$_} || ''; + return SL::Template::LaTeX->new->_format_html($text); +} - } else { - $::locale->quote_special_chars('Template/LaTeX', HTML::Entities::decode_entities($_)); - } - } split(m{(<.*?>)}x, $text); +sub required_packages_for_html { + my ($self) = @_; - return join('', @parts); + return <: + + % config: use-template-toolkit=1 + % config: tag-style=$( )$ + $( USE KiviLatex )$ + +Later escape some text: + + $( KiviLatex.format(longdescription) )$ + +=head1 FUNCTIONS + +=over 4 + +=item C + +Escapes characters in C<$text> with the appropriate LaTeX +constructs. Expects normal text without any markup (no HTML, no XML +etc). Returns the whole escaped text. + +=item C + +Converts HTML markup in C<$html> to the appropriate LaTeX +constructs. Only the following HTML elements are supported: + +=over 2 + +=item * C, C – bold text + +=item * C, C – italic text + +=item * C
    – underlined text + +=item * C – striked out text + +=item * C, C – subscripted and superscripted text + +=item * C
      , C
        , C
      1. – unordered lists (converted to an itemized +list), ordered lists (converted to enumerated lists) and their list +items + +=item * C

        , C
        – Paragraph markers and line breaks + +=back + +This function is tailored for working on the input of CKEditor, not on +arbitrary HTML content. It works nicely in tandem with the +Rose::DB::Object helper functions C<…_as_restricted_html> (see +L). + +Attributes are silently removed and ignored. All other markup and the +normal text are escaped the same as in L. + +=item C + +=item C + +Initializes the plugin. Automatically called by Template::Toolkit when +the plugin is loaded. + +=item C + +Returns LaTeX code loading packages that are required for the +formatting done with L. This function must be called and +its output inserted before the C<\begin{document}> line if that +function is used within the document. + +It is not required for normal text escaping with L. + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut