Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pages/extensions/markdown_toc_patch/custom_toc_tree_processor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import re
import unicodedata
from markdown import util
from markdown.extensions.toc import TocExtension
from markdown.extensions.toc import TocTreeprocessor


def slugify(value: str, separator: str = '-', unicode: bool = False) -> str:
""" Slugify a string, to make it URL friendly. """
slug = value.strip().lower()
slug = slug.replace(' ', '-')
slug = re.sub(r'[^\w-]', '', slug, flags=re.UNICODE)
return slug


class CustomTocTreeProcessor(TocTreeprocessor):
"""
Since html code that may be inside the headlines causes problems in the TOC we remove them
"""

def __init__(self, md, config):
super(CustomTocTreeProcessor, self).__init__(md, config)
self.slugify = slugify

def strip_html_from_names(self, toc_list):
for item in toc_list:
text = item.get('name', '')
Expand Down