diff --git a/marko/ext/toc.py b/marko/ext/toc.py index c4a40a6..5bfc026 100644 --- a/marko/ext/toc.py +++ b/marko/ext/toc.py @@ -25,11 +25,16 @@ import re -from slugify import slugify - from marko.helpers import MarkoExtension, render_dispatch # type: ignore from marko.html_renderer import HTMLRenderer +try: + from slugify import slugify +except ImportError: + + def slugify(source: str) -> str: # type: ignore[misc] + return re.sub(r"[^\w\- ]+", "", source).strip().lower().replace(" ", "-") + class TocRendererMixin: opening = "