@@ -76,7 +76,7 @@ def get_html_from_items(
7676 """
7777 Get all the HTML from the pages.
7878 """
79- item_html = ""
79+ items_html = ""
8080
8181 for item in items :
8282 if item .is_page :
@@ -94,13 +94,21 @@ def get_html_from_items(
9494 % item .file .src_path
9595 )
9696 continue
97+
98+ item_html = item .html
99+
100+ # Add missing h1 tag if it doesn't exist
101+ if not item_html .startswith ("<h1" ):
102+ item_html = f"<h1 id=\" { to_snake_case (item .title )} \" >{ item .title } </h1>{ item_html } "
103+ logger .warning (f"[mkdocs-print-site] '{ item .file .src_path } ' file is missing a leading h1 tag. Added to the print-page with title '{ item .title } '" )
104+
97105 # Update internal anchor links, image urls, etc
98- item_html += fix_internal_links (
99- item . html , item .url , directory_urls = dir_urls
106+ items_html += fix_internal_links (
107+ item_html , item .url , directory_urls = dir_urls
100108 )
101109
102110 if item .is_section :
103- item_html += """
111+ items_html += """
104112 <h%s class='nav-section-title' id='section-%s'>
105113 %s <a class='headerlink' href='#section-%s' title='Permanent link'>↵</a>
106114 </h%s>
@@ -111,16 +119,16 @@ def get_html_from_items(
111119 to_snake_case (item .title ),
112120 min (6 , section_depth + 1 ),
113121 )
114- item_html += get_html_from_items (
122+ items_html += get_html_from_items (
115123 item .children , dir_urls , excluded_pages , section_depth + 1
116124 )
117125 # We also need to indicate the end of section page
118126 # We do that using a h1 with a specific class
119127 # In CSS we display:none, in JS we can use it for formatting the table of contents.
120- item_html += (
128+ items_html += (
121129 "<h1 class='nav-section-title-end'>Ended: %s</h1>" % item .title
122130 )
123- return item_html
131+ return items_html
124132
125133 html += get_html_from_items (
126134 self ._get_items (),
0 commit comments