From 4ec788ce3fe5be2abc983ed13254904c06d9e7f4 Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Fri, 31 Jul 2020 15:24:48 +0200 Subject: [PATCH] Cmake export tests: Export to docbook5 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 | 6 +- development/autotests/filterXml4Sax.pl | 96 ++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 development/autotests/filterXml4Sax.pl diff --git a/development/autotests/export.cmake b/development/autotests/export.cmake index 33a4525382..a9f2a01540 100755 --- a/development/autotests/export.cmake +++ b/development/autotests/export.cmake @@ -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 index 0000000000..7004b3315f --- /dev/null +++ b/development/autotests/filterXml4Sax.pl @@ -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 = ) { + 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 = ) { + 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\>\$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; +} -- 2.39.2