Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive XInclude support and some automatix fixups for translations #194

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,28 @@ function getFileModificationHistory(): array {
echo "done.\n";

echo "Running XInclude/XPointer... ";
$status = $dom->xinclude();
if ($status === -1) {
$total = 0;
$maxrun = 10; //LIBXML_VERSION >= 21100 ? 1 : 10;
for( $run = 0 ; $run < $maxrun ; $run++ )
{
if ( $run > 0 )
echo "$run ";
libxml_clear_errors();
$status = (int) $dom->xinclude();
if ( $status <= 0 )
break;
$total += $status;
if ( $maxrun > 1 && $run + 1 >= $maxrun )
{
echo "Recursive XInclude is too deep.\n";
errors_are_bad(-1);
}
}

if ($total == 0) {
echo "failed.\n";
} else {
/* For some dumb reason when no substitution are made it returns false instead of 0... */
$status = (int) $status;
echo "done. Performed $status XIncludes\n";
echo "done. Performed $total XIncludes.\n";
}
flush();

Expand All @@ -799,6 +814,38 @@ function getFileModificationHistory(): array {
}
}

{ # Automatic xi:include / xi:fallback fixups

$xpath = new DOMXPath( $dom );
$nodes = $xpath->query( "//*[local-name()='include']" );
foreach( $nodes as $node )
{
$fixup = null;
$parent = $node->parentNode;
$tagName = $parent->nodeName;
switch( $tagName )
{
case "refentry":
$fixup = "";
break;
case "refsect1":
$fixup = "<title></title>";
break;
default:
echo "Unknown parent element, validation may fail: $tagName\n";
continue 2;
}
if ( $fixup != "" )
{
$other = new DOMDocument( '1.0' , 'utf8' );
$other->loadXML( $fixup );
$insert = $dom->importNode( $other->documentElement , true );
$node->parentNode->insertBefore( $insert , $node );
}
$node->parentNode->removeChild( $node );
}
}

echo "Validating {$ac["INPUT_FILENAME"]}... ";
flush();
if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{
Expand Down
Loading