Skip to content

Commit

Permalink
Support mkdocs material tags, closes #92
Browse files Browse the repository at this point in the history
timvink authored May 23, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent a1ca60d commit 11a7fe7
Showing 4 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mkdocs_print_site_plugin/renderer.py
Original file line number Diff line number Diff line change
@@ -102,6 +102,16 @@ def get_html_from_items(
item_html = f"<h1 id=\"{to_snake_case(item.title)}\">{item.title}</h1>{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 = "<nav class='md-tags'>"
for tag in tags:
tags_html += f"<span class='md-tag'>{tag}</span>"
tags_html += "</nav>"
item_html = tags_html + item_html

# Update internal anchor links, image urls, etc
items_html += fix_internal_links(
item_html, item.url, directory_urls=dir_urls
10 changes: 10 additions & 0 deletions tests/fixtures/projects/mkdocs_material_tags/docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
tags:
- HTML5
- JavaScript
- CSS
---

# Hello there

Testing [tags](https://squidfunk.github.io/mkdocs-material/plugins/tags/?h=tags#usage) plugin.
12 changes: 12 additions & 0 deletions tests/fixtures/projects/mkdocs_material_tags/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
site_name: Test

theme:
name: material

plugins:
- tags
- print-site:
add_to_navigation: true

markdown_extensions:
- attr_list
5 changes: 5 additions & 0 deletions tests/test_building.py
Original file line number Diff line number Diff line change
@@ -275,6 +275,11 @@ def test_basic_build7(tmp_path):
"""
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):
"""

0 comments on commit 11a7fe7

Please sign in to comment.