@@ -775,13 +775,28 @@ function getFileModificationHistory(): array {
775775echo "done. \n" ;
776776
777777echo "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}
786801flush ();
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+
802849echo "Validating {$ ac ["INPUT_FILENAME " ]}... " ;
803850flush ();
804851if ($ ac ['PARTIAL ' ] != '' && $ ac ['PARTIAL ' ] != 'no ' ) { // {{{
0 commit comments