Skip to content

Commit f322b1f

Browse files
committed
Update mkdocs macro glossary to take optional link text
This allows linking to a glossary term with custom text for the link. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 8acfc11 commit f322b1f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

docs/_scripts/macros.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ def define_env(env: macros.MacrosPlugin) -> None:
4545
env.variables["code_annotation_marker"] = _CODE_ANNOTATION_MARKER
4646

4747
@env.macro # type: ignore[misc]
48-
def glossary(term: str) -> str:
48+
def glossary(term: str, text: str | None = None) -> str:
4949
"""Create a link to the glossary entry for the given term.
5050
5151
Args:
5252
term: The term to link to.
53+
text: The text to display for the link. Defaults to the term.
5354
5455
Returns:
5556
The Markdown link to the glossary entry for the given term.
5657
"""
5758
current_path = pathlib.Path(env.page.file.src_uri)
5859
glossary_path = pathlib.Path("user-guide/glossary.md")
5960
link_path = glossary_path.relative_to(current_path.parent)
60-
return f"[{term}]({link_path}#{_slugify(term)})"
61+
return f"[{text or term}]({link_path}#{_slugify(term)})"
6162

6263
# The code below is a temporary workaround to make `mkdocs-macros` work with
6364
# `mkdocstrings` until a proper `mkdocs-macros` *pluglet* is available. See

0 commit comments

Comments
 (0)