Skip to content

Commit 98d9c7e

Browse files
committed
Move _slugify() to the top-level
This function doesn't need to access the `env` object, so it can be defined at the top-level. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 2c8f61f commit 98d9c7e

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

docs/_scripts/macros.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,27 @@
99
from mkdocs_macros import plugin as macros
1010

1111

12-
def define_env(env: macros.MacrosPlugin) -> None:
13-
"""Define the hook to create macro functions for use in Markdown.
12+
def _slugify(text: str) -> str:
13+
"""Slugify a text.
1414
1515
Args:
16-
env: The environment to define the macro functions in.
16+
text: The text to slugify.
17+
18+
Returns:
19+
The slugified text.
1720
"""
21+
# The type of the return value is not defined for the markdown library.
22+
# Also for some reason `mypy` thinks the `toc` module doesn't have a
23+
# `slugify_unicode` function, but it definitely does.
24+
return toc.slugify_unicode(text, "-") # type: ignore[attr-defined,no-any-return]
1825

19-
def _slugify(text: str) -> str:
20-
"""Slugify a text.
2126

22-
Args:
23-
text: The text to slugify.
27+
def define_env(env: macros.MacrosPlugin) -> None:
28+
"""Define the hook to create macro functions for use in Markdown.
2429
25-
Returns:
26-
The slugified text.
27-
"""
28-
# The type of the return value is not defined for the markdown library.
29-
# Also for some reason `mypy` thinks the `toc` module doesn't have a
30-
# `slugify_unicode` function, but it definitely does.
31-
return toc.slugify_unicode(text, "-") # type: ignore[attr-defined,no-any-return]
30+
Args:
31+
env: The environment to define the macro functions in.
32+
"""
3233

3334
@env.macro # type: ignore[misc]
3435
def glossary(term: str) -> str:

0 commit comments

Comments
 (0)