mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
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"'
This commit is contained in:
parent
857036c0c1
commit
4ec788ce3f
@ -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)
|
||||
|
96
development/autotests/filterXml4Sax.pl
Normal file
96
development/autotests/filterXml4Sax.pl
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user