Skip to content

Anchors links to headers containing emojis are reported as invalid URLs #64

@johnthagen

Description

@johnthagen

Describe the bug

Material for MkDocs supports emojis

These can be placed in the body of text or in section headers, and have the form :emoji-identifier:.

This same syntax can also be used for custom icons:

Currently, anchor validation will fail for anchor links that are valid, but point to headers that contain an emoji.

To Reproduce

Environment (please complete the following information):

  • OS (e.g. Windows 10/Ubuntu 20.04/macOS): macOS
  • Python version (python --version): 3.10.11
  • Package versions (pip list):
Package                    Version
-------------------------- --------
beautifulsoup4             4.12.2
certifi                    2023.5.7
charset-normalizer         3.2.0
click                      8.1.4
colorama                   0.4.6
ghp-import                 2.1.0
idna                       3.4
Jinja2                     3.1.2
Markdown                   3.3.7
MarkupSafe                 2.1.3
mergedeep                  1.3.4
mkdocs                     1.4.3
mkdocs-htmlproofer-plugin  0.13.1
mkdocs-material            9.1.18
mkdocs-material-extensions 1.1.1
packaging                  23.1
pip                        23.0.1
Pygments                   2.15.1
pymdown-extensions         10.0.1
python-dateutil            2.8.2
PyYAML                     6.0
pyyaml_env_tag             0.1
regex                      2023.6.3
requests                   2.31.0
setuptools                 67.2.0
six                        1.16.0
soupsieve                  2.4.1
urllib3                    2.0.3
watchdog                   3.0.0
wheel                      0.38.4

Contents of mkdocs.yml:

site_name: My Docs
strict: true
theme:
  name: material
use_directory_urls: false
plugins:
    - search
    - htmlproofer:
        enabled: true
        raise_error: true
markdown_extensions:
  - attr_list
  - pymdownx.emoji:
      emoji_index: !!python/name:materialx.emoji.twemoji
      emoji_generator: !!python/name:materialx.emoji.to_svg

`index.md:

# Index

[Link](page.md#heading-2)

page.md:

# Heading

## Heading 2 :material-star:
Screen Shot 2023-07-11 at 11 52 21 AM

Error:

$ mkdocs build    
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory:
            material-for-mkdocs-test/site
WARNING  -  htmlproofer: Unable to locate source file for: page.html#heading-2
ERROR    -  Error building page 'index.md':
ERROR    -  invalid url - page.html#heading-2 [404] [index.md]

Aborted with a BuildError!

Disabling htmlproofer plugin shows that the links are in fact valid.

Context

This is similar to the following issues, where I believe we simply need to strip out/ignore words in the headers that are surrounded by : :.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions