Add id tags to chapters/sections missing them
[exim-website.git] / script / gen.pl
index 4c545f52cdf477158d5a2a3c044c8f186e47758f..1fbb0268173690533fe70dfc2793116456f00a11 100755 (executable)
@@ -163,7 +163,11 @@ sub xref_fixup {
     foreach my $chapter ( $xml->findnodes('/book/chapter') ) {
         ++$chapter_counter;
 
-        my $chapter_id    = $chapter->getAttribute('id');
+        my $chapter_id = $chapter->getAttribute('id');
+        unless ($chapter_id) {    # synthesise missing id
+            $chapter_id = sprintf( 'chapter_noid_%04d', $chapter_counter );
+            $chapter->setAttribute( 'id', $chapter_id );
+        }
         my $chapter_title = $chapter->findvalue('title');
 
         $index{$chapter_id} = { chapter_id => $chapter_counter, chapter_title => $chapter_title };
@@ -173,7 +177,11 @@ sub xref_fixup {
         foreach my $section ( $chapter->findnodes('section') ) {
             ++$section_counter;
 
-            my $section_id    = $section->getAttribute('id');
+            my $section_id = $section->getAttribute('id');
+            unless ($section_id) {    # synthesise missing id
+                $section_id = sprintf( 'section_noid_%04d_%04d', $chapter_counter, $section_counter );
+                $section->setAttribute( 'id', $section_id );
+            }
             my $section_title = $section->findvalue('title');
 
             $index{$section_id} =