Skip to content

Commit 9d68f54

Browse files
authored
Recursive XInclude support and some automatix fixups for translations (#194)
1 parent b31cc91 commit 9d68f54

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

configure.php

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,28 @@ function getFileModificationHistory(): array {
775775
echo "done.\n";
776776

777777
echo "Running XInclude/XPointer... ";
778-
$status = $dom->xinclude();
779-
if ($status === -1) {
778+
$total = 0;
779+
$maxrun = 10; //LIBXML_VERSION >= 21100 ? 1 : 10;
780+
for( $run = 0 ; $run < $maxrun ; $run++ )
781+
{
782+
if ( $run > 0 )
783+
echo "$run ";
784+
libxml_clear_errors();
785+
$status = (int) $dom->xinclude();
786+
if ( $status <= 0 )
787+
break;
788+
$total += $status;
789+
if ( $maxrun > 1 && $run + 1 >= $maxrun )
790+
{
791+
echo "Recursive XInclude is too deep.\n";
792+
errors_are_bad(-1);
793+
}
794+
}
795+
796+
if ($total == 0) {
780797
echo "failed.\n";
781798
} else {
782-
/* For some dumb reason when no substitution are made it returns false instead of 0... */
783-
$status = (int) $status;
784-
echo "done. Performed $status XIncludes\n";
799+
echo "done. Performed $total XIncludes.\n";
785800
}
786801
flush();
787802

@@ -799,6 +814,38 @@ function getFileModificationHistory(): array {
799814
}
800815
}
801816

817+
{ # Automatic xi:include / xi:fallback fixups
818+
819+
$xpath = new DOMXPath( $dom );
820+
$nodes = $xpath->query( "//*[local-name()='include']" );
821+
foreach( $nodes as $node )
822+
{
823+
$fixup = null;
824+
$parent = $node->parentNode;
825+
$tagName = $parent->nodeName;
826+
switch( $tagName )
827+
{
828+
case "refentry":
829+
$fixup = "";
830+
break;
831+
case "refsect1":
832+
$fixup = "<title></title>";
833+
break;
834+
default:
835+
echo "Unknown parent element, validation may fail: $tagName\n";
836+
continue 2;
837+
}
838+
if ( $fixup != "" )
839+
{
840+
$other = new DOMDocument( '1.0' , 'utf8' );
841+
$other->loadXML( $fixup );
842+
$insert = $dom->importNode( $other->documentElement , true );
843+
$node->parentNode->insertBefore( $insert , $node );
844+
}
845+
$node->parentNode->removeChild( $node );
846+
}
847+
}
848+
802849
echo "Validating {$ac["INPUT_FILENAME"]}... ";
803850
flush();
804851
if ($ac['PARTIAL'] != '' && $ac['PARTIAL'] != 'no') { // {{{

0 commit comments

Comments
 (0)