Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / Template / LaTeX.pm
index 4915c86..293db2e 100644 (file)
@@ -83,6 +83,8 @@ sub _format_html {
   $content =~ s{ (?:\ |\s)+ }{ }gx;
   $content =~ s{ (?:\ |\s)+$ }{}gx;
   $content =~ s{ (?: <br/?> )+$ }{}gx;
+  $content =~ s{ <ul>\s*</ul> | <ol>\s*</ol> }{}igx;
+  $content =~ s{ (?: <p>\s*</p>\s* )+ \Z }{}imgx;
 
   my @parts = grep { $_ } map {
     if (substr($_, 0, 1) eq '<') {
@@ -394,12 +396,16 @@ sub _embed_file_directive {
   my ($self, $file) = @_;
 
   # { source      => $xmlfile,
-  #   name        => 'ZUGFeRD-invoice.xml',
-  #   description => $::locale->text('ZUGFeRD invoice'), }
+  #   name        => 'factur-x.xml',
+  #   description => $::locale->text('Factur-X/ZUGFeRD invoice'), }
 
   my $file_name  =  blessed($file->{source}) && $file->{source}->can('filename') ? $file->{source}->filename : "" . $file->{source}->filename;
   my $embed_name =  $file->{name} // $file_name;
   $embed_name    =~ s{.*/}{};
+
+  my $embed_name_ascii = $::locale->quote_special_chars('filenames', $embed_name);
+  $embed_name_ascii    =~ s{[^a-z0-9!@#$%^&*(){}[\],.+'"=_-]+}{}gi;
+
   my @options;
 
   my $add_opt = sub {
@@ -408,6 +414,7 @@ sub _embed_file_directive {
     push @options, sprintf('%s={%s}', $name, $value); # TODO: escaping
   };
 
+  $add_opt->('filespec',       $embed_name_ascii);
   $add_opt->('ucfilespec',     $embed_name);
   $add_opt->('desc',           $file->{description});
   $add_opt->('afrelationship', $file->{relationship});