@@ -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,31 @@ 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+
105+ # Support mkdocs-material tags
106+ # See https://squidfunk.github.io/mkdocs-material/plugins/tags
107+ if "tags" in item .meta :
108+ tags = item .meta ["tags" ]
109+ tags_html = "<nav class='md-tags'>"
110+ for tag in tags :
111+ tags_html += f"<span class='md-tag'>{ tag } </span>"
112+ tags_html += "</nav>"
113+ item_html = tags_html + item_html
114+
97115 # Update internal anchor links, image urls, etc
98- item_html += fix_internal_links (
99- item . html , item .url , directory_urls = dir_urls
116+ items_html += fix_internal_links (
117+ item_html , item .url , directory_urls = dir_urls
100118 )
101119
102120 if item .is_section :
103- item_html += """
121+ items_html += """
104122 <h%s class='nav-section-title' id='section-%s'>
105123 %s <a class='headerlink' href='#section-%s' title='Permanent link'>↵</a>
106124 </h%s>
@@ -111,16 +129,16 @@ def get_html_from_items(
111129 to_snake_case (item .title ),
112130 min (6 , section_depth + 1 ),
113131 )
114- item_html += get_html_from_items (
132+ items_html += get_html_from_items (
115133 item .children , dir_urls , excluded_pages , section_depth + 1
116134 )
117135 # We also need to indicate the end of section page
118136 # We do that using a h1 with a specific class
119137 # In CSS we display:none, in JS we can use it for formatting the table of contents.
120- item_html += (
138+ items_html += (
121139 "<h1 class='nav-section-title-end'>Ended: %s</h1>" % item .title
122140 )
123- return item_html
141+ return items_html
124142
125143 html += get_html_from_items (
126144 self ._get_items (),
0 commit comments