3333ATTRLIST_ANCHOR_PATTERN = re .compile (r'\{.*?\#([^\s\}]*).*?\}' )
3434ATTRLIST_PATTERN = re .compile (r'\{.*?\}' )
3535
36+ # Example emojis:
37+ # :banana:
38+ # :smiley_cat:
39+ # :octicons-apps-16:
40+ # :material-star:
41+ EMOJI_PATTERN = re .compile (r'\:[a-z0-9_-]+\:' )
42+
3643urllib3 .disable_warnings ()
3744
3845
@@ -225,7 +232,7 @@ def contains_anchor(markdown: str, anchor: str) -> bool:
225232 # # Heading {: #testanchor .testclass }
226233 # # Heading {.testclass #testanchor}
227234 # # Heading {.testclass}
228- # these can override the headings anchor id, or alternativly just provide additional class etc.
235+ # these can override the headings anchor id, or alternatively just provide additional class etc.
229236 attr_list_anchor_match = ATTRLIST_ANCHOR_PATTERN .match (heading )
230237 if attr_list_anchor_match is not None :
231238 attr_list_anchor = heading_match .groups ()[1 ]
@@ -239,6 +246,10 @@ def contains_anchor(markdown: str, anchor: str) -> bool:
239246 # But these images are not included in the generated anchor, so remove them.
240247 heading = re .sub (IMAGE_PATTERN , '' , heading )
241248
249+ # Headings are allowed to have emojis in them under certain Mkdocs themes.
250+ # https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown-extensions/#emoji
251+ heading = re .sub (EMOJI_PATTERN , '' , heading )
252+
242253 anchor_slug = slugify (heading , '-' )
243254 if anchor == anchor_slug :
244255 return True
0 commit comments