diff --git a/mkdocs_print_site_plugin/plugin.py b/mkdocs_print_site_plugin/plugin.py index 1820828..51f7f1a 100644 --- a/mkdocs_print_site_plugin/plugin.py +++ b/mkdocs_print_site_plugin/plugin.py @@ -216,19 +216,6 @@ def on_page_content(self, html, page, config, files, **kwargs): if page != self.print_page: page.html = html - # We need to validate that the first heading on each page is a h1 - # This is required for the print page table of contents and enumeration logic - if self.config.get("add_table_of_contents") or self.config.get( - "enumerate_headings" - ): - if page in self.all_pages_in_nav: - match = re.search(r"\{item.title}{item_html}" + 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}'") + + # Support mkdocs-material tags + # See https://squidfunk.github.io/mkdocs-material/plugins/tags + if "tags" in item.meta: + tags = item.meta["tags"] + tags_html = "" + item_html = tags_html + item_html + # Update internal anchor links, image urls, etc - item_html += fix_internal_links( - item.html, item.url, directory_urls=dir_urls + items_html += fix_internal_links( + item_html, item.url, directory_urls=dir_urls ) if item.is_section: - item_html += """ + items_html += """ %s @@ -111,16 +129,16 @@ def get_html_from_items( to_snake_case(item.title), min(6, section_depth + 1), ) - item_html += get_html_from_items( + items_html += get_html_from_items( item.children, dir_urls, excluded_pages, section_depth + 1 ) # We also need to indicate the end of section page # We do that using a h1 with a specific class # In CSS we display:none, in JS we can use it for formatting the table of contents. - item_html += ( + items_html += ( "

Ended: %s

" % item.title ) - return item_html + return items_html html += get_html_from_items( self._get_items(), diff --git a/setup.py b/setup.py index e562e3a..e64a683 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name="mkdocs-print-site-plugin", - version="2.4.1", + version="2.5.0", description="MkDocs plugin that combines all pages into one, allowing for easy export to PDF and standalone HTML.", long_description=long_description, long_description_content_type="text/markdown", diff --git a/tests/fixtures/projects/mkdocs_material_tags/docs/index.md b/tests/fixtures/projects/mkdocs_material_tags/docs/index.md new file mode 100644 index 0000000..8903870 --- /dev/null +++ b/tests/fixtures/projects/mkdocs_material_tags/docs/index.md @@ -0,0 +1,10 @@ +--- +tags: + - HTML5 + - JavaScript + - CSS +--- + +# Hello there + +Testing [tags](https://squidfunk.github.io/mkdocs-material/plugins/tags/?h=tags#usage) plugin. \ No newline at end of file diff --git a/tests/fixtures/projects/mkdocs_material_tags/mkdocs.yml b/tests/fixtures/projects/mkdocs_material_tags/mkdocs.yml new file mode 100644 index 0000000..939d653 --- /dev/null +++ b/tests/fixtures/projects/mkdocs_material_tags/mkdocs.yml @@ -0,0 +1,12 @@ +site_name: Test + +theme: + name: material + +plugins: + - tags + - print-site: + add_to_navigation: true + +markdown_extensions: + - attr_list \ No newline at end of file diff --git a/tests/test_building.py b/tests/test_building.py index 10f6c94..4c1b7bf 100644 --- a/tests/test_building.py +++ b/tests/test_building.py @@ -269,10 +269,17 @@ def test_basic_build6(tmp_path): def test_basic_build7(tmp_path): """ - Test error when page does not start with h1 heading. + Test when page does not start with h1 heading. + + As of v2.5.0, this is allowed (the plugin will add a heading to the print page) """ - check_build(tmp_path, "bad_headings/mkdocs.yml", exit_code=1) + check_build(tmp_path, "bad_headings/mkdocs.yml", exit_code=0) +def test_build_with_material_tags(tmp_path): + """ + Test support with tags. + """ + check_build(tmp_path, "mkdocs_material_tags/mkdocs.yml", exit_code=0) def test_basic_disable_plugin(tmp_path): """