]> git.lyx.org Git - features.git/commitdiff
Cmake export tests: Export to docbook5
authorKornel Benko <kornel@lyx.org>
Fri, 31 Jul 2020 13:24:48 +0000 (15:24 +0200)
committerKornel Benko <kornel@lyx.org>
Fri, 31 Jul 2020 13:24:48 +0000 (15:24 +0200)
The sax-parser is choking on tags like 'section*' or 'Braille (default)'.
Also setting parameters like 'height=12pt' are not valid.

The added filter tries to 'correct' the input for the sax parser.
E.g. 'Braille (default)' ==> 'Braille__default_', 'section*' ==> 'section_'
and 'height =12pt' ==> 'height="12pt"'

development/autotests/export.cmake
development/autotests/filterXml4Sax.pl [new file with mode: 0644]

index 33a45253820cad0fe499b65b11f10b370aeeb9a3..a9f2a0154021e85d48a665b4e125758c511d6ddc 100755 (executable)
@@ -222,14 +222,16 @@ else()
       if (extension MATCHES "^x(ht)?ml$")
        if (format MATCHES "xhtml")
          set(xmllint_params --sax --html --valid)
+         set(executable_ ${XMLLINT_EXECUTABLE})
        else()
-         set(xmllint_params --sax --valid)
+         set(xmllint_params)
+         set(executable_ ${PERL_EXECUTABLE} "${TOP_SRC_DIR}/development/autotests/filterXml4Sax.pl")
        endif()
         if (XMLLINT_EXECUTABLE)
           message(STATUS "Calling: ${XMLLINT_EXECUTABLE} " ${xmllint_params})
           # check the created xhtml file
           execute_process(
-            COMMAND ${XMLLINT_EXECUTABLE} ${xmllint_params}  "${result_file_name}"
+            COMMAND ${executable_} ${xmllint_params}  "${result_file_name}"
             OUTPUT_VARIABLE xmlout
             ERROR_VARIABLE xmlerr
             RESULT_VARIABLE _err)
diff --git a/development/autotests/filterXml4Sax.pl b/development/autotests/filterXml4Sax.pl
new file mode 100644 (file)
index 0000000..7004b33
--- /dev/null
@@ -0,0 +1,96 @@
+#! /usr/bin/env perl
+
+use strict;
+use File::Temp qw/ tempfile tempdir /;
+
+sub convert($);
+sub handlePara($);
+
+die("No xml file specified") if (! defined($ARGV[0]));
+my $f = $ARGV[0];
+die("Bad extension of $f") if ($f !~ /\.xml$/);
+die("Could not read $f") if (!open(FI, $f));
+my ($fh, $filename) = tempfile("tempXXXX", SUFFIX => '.xml', DIR => '/tmp', UNLINK => 0);
+while (my $l = <FI>) {
+  chomp($l);
+  $l = convert($l);
+  print $fh "$l\n";
+}
+close(FI);
+close($fh);
+my $err = 0;
+my @errors = ();
+if (open(FI, "xmllint --sax $filename|")) {
+  while (my $l = <FI>) {
+    print $l;
+  }
+}
+else {
+  $err = 1;
+  @errors = ("Could not run xmllint\n");
+}
+#unlink($filename);
+print "Not unlinking $filename\n";
+if ($err > 0) {
+  die(join('', @errors));
+}
+exit(0);
+
+#########################################################################
+sub convert($)
+{
+  my ($l) = @_;
+  if ($l =~ /^(.*)\<(\/?[a-zA-Z]+(:[a-zA-Z]+)?)([^\>\<]*)\>(.*)$/) {
+    my ($prev,$tag,$para,$rest) = ($1,$2,$4,$5);
+    $prev = &convert($prev);
+    $rest = &convert($rest);
+    if ($para !~ /^\s*\/?$/) {
+      if ($para !~ /^\s+[a-z]+(:[a-z]+)?\s*=/) {
+       $para =~ s/[^a-z_]/_/g;
+      }
+      else {
+       $para = " " . &handlePara($para);
+      }
+    }
+    if ($para =~ s/\s*\/$//) {
+      return "$prev<$tag$para\>\</$tag\>$rest";
+    }
+    else {
+      return "$prev<$tag$para>$rest";
+    }
+  }
+  else {
+    return($l);
+  }
+}
+
+sub handlePara($)
+{
+  my ($para) = @_;
+  if ($para =~ /^\s*([a-z]+(:[a-z]+)?)\s*=\s*(.*)$/) {
+    my $val;
+    my ($p, $rest) = ($1, $3);
+    if ($rest =~ /^(\'[^\']*\')(.*)$/) {
+      $val = $1;
+      $rest = $2;
+    }
+    elsif ($rest =~ /^(\"[^\"]*\")(.*)$/) {
+      $val = $1;
+      $rest = $2;
+    }
+    elsif ($rest =~ /^([^\s]+)(.*)$/) {
+      $val = '"' . $1 . '"';
+      $rest = $2;
+    }
+    else {
+      die("param error for rest = $rest");
+    }
+    if ($rest !~ /^\s*$/) {
+      return "$p=$val " . &handlePara($rest);
+    }
+    else {
+      return "$p=$val";
+    }
+  }
+  return $para;
+}