diff --git a/.gitignore b/.gitignore index 6ec8804..2f4be1c 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ test/integration/site # PyCharm .idea + +# Project specfic +tests/integration/site diff --git a/htmlproofer/plugin.py b/htmlproofer/plugin.py index b1be385..a550dc9 100644 --- a/htmlproofer/plugin.py +++ b/htmlproofer/plugin.py @@ -33,6 +33,13 @@ ATTRLIST_ANCHOR_PATTERN = re.compile(r'\{.*?\#([^\s\}]*).*?\}') ATTRLIST_PATTERN = re.compile(r'\{.*?\}') +# Example emojis: +# :banana: +# :smiley_cat: +# :octicons-apps-16: +# :material-star: +EMOJI_PATTERN = re.compile(r'\:[a-z0-9_-]+\:') + urllib3.disable_warnings() @@ -225,7 +232,7 @@ def contains_anchor(markdown: str, anchor: str) -> bool: # # Heading {: #testanchor .testclass } # # Heading {.testclass #testanchor} # # Heading {.testclass} - # these can override the headings anchor id, or alternativly just provide additional class etc. + # these can override the headings anchor id, or alternatively just provide additional class etc. attr_list_anchor_match = ATTRLIST_ANCHOR_PATTERN.match(heading) if attr_list_anchor_match is not None: attr_list_anchor = heading_match.groups()[1] @@ -239,6 +246,10 @@ def contains_anchor(markdown: str, anchor: str) -> bool: # But these images are not included in the generated anchor, so remove them. heading = re.sub(IMAGE_PATTERN, '', heading) + # Headings are allowed to have emojis in them under certain Mkdocs themes. + # https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/#emoji + heading = re.sub(EMOJI_PATTERN, '', heading) + anchor_slug = slugify(heading, '-') if anchor == anchor_slug: return True diff --git a/tests/integration/docs/nested/page1.md b/tests/integration/docs/nested/page1.md index c96b242..338df37 100644 --- a/tests/integration/docs/nested/page1.md +++ b/tests/integration/docs/nested/page1.md @@ -21,8 +21,9 @@ or to a nested page [Invalid Anchor](./page2.md#BAD_ANCHOR). But allows valid anchors such as -[Main Page](../index.md#mkdocs-htmlproofer-plugin) and -[Table of Contents](../index.md#table-of-contents). +[Main Page](../index.md#mkdocs-htmlproofer-plugin), +[Table of Contents](../index.md#table-of-contents), and +[Emoji Anchor](./page2.md#title-with-emojis). ## Image Link absolute/relative diff --git a/tests/integration/docs/nested/page2.md b/tests/integration/docs/nested/page2.md index 1ca7311..a6a4be1 100644 --- a/tests/integration/docs/nested/page2.md +++ b/tests/integration/docs/nested/page2.md @@ -1 +1,3 @@ # Second Nested Test Page + +## :smile_cat: Title with Emojis :material-star: :octicons-apps-16: