From 142aa9dc641a5b5b348a8cbdf82e53792a25c26f Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sat, 19 Jul 2025 00:52:13 +0200 Subject: [PATCH] chore: make slugify dependency optional Makes it possible to run pytest on a freshly checked out project without having to set up a venv. --- marko/ext/toc.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 = "