Skip to content

Commit 15005e2

Browse files
authored
2 parents dcd3f99 + 83eb35d commit 15005e2

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

mkdocs_print_site_plugin/renderer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ def get_html_from_items(
102102
item_html = f"<h1 id=\"{to_snake_case(item.title)}\">{item.title}</h1>{item_html}"
103103
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}'")
104104

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+
105115
# Update internal anchor links, image urls, etc
106116
items_html += fix_internal_links(
107117
item_html, item.url, directory_urls=dir_urls
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
tags:
3+
- HTML5
4+
- JavaScript
5+
- CSS
6+
---
7+
8+
# Hello there
9+
10+
Testing [tags](https://squidfunk.github.io/mkdocs-material/plugins/tags/?h=tags#usage) plugin.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
site_name: Test
2+
3+
theme:
4+
name: material
5+
6+
plugins:
7+
- tags
8+
- print-site:
9+
add_to_navigation: true
10+
11+
markdown_extensions:
12+
- attr_list

tests/test_building.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ def test_basic_build7(tmp_path):
275275
"""
276276
check_build(tmp_path, "bad_headings/mkdocs.yml", exit_code=0)
277277

278+
def test_build_with_material_tags(tmp_path):
279+
"""
280+
Test support with tags.
281+
"""
282+
check_build(tmp_path, "mkdocs_material_tags/mkdocs.yml", exit_code=0)
278283

279284
def test_basic_disable_plugin(tmp_path):
280285
"""

0 commit comments

Comments
 (0)