Skip to content

Commit 75f0777

Browse files
committed
Add a macro to easily display a code annotation
This is to encourage users to expand annotations, which might not be that obvious otherwise. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 98d9c7e commit 75f0777

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/_scripts/macros.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
from markdown.extensions import toc
99
from mkdocs_macros import plugin as macros
1010

11+
_CODE_ANNOTATION_MARKER: str = (
12+
r'<span class="md-annotation">'
13+
r'<span class="md-annotation__index" tabindex="-1">'
14+
r'<span data-md-annotation-id="1"></span>'
15+
r"</span>"
16+
r"</span>"
17+
)
18+
1119

1220
def _slugify(text: str) -> str:
1321
"""Slugify a text.
@@ -30,6 +38,9 @@ def define_env(env: macros.MacrosPlugin) -> None:
3038
Args:
3139
env: The environment to define the macro functions in.
3240
"""
41+
# A variable to easily show an example code annotation from mkdocs-material.
42+
# https://squidfunk.github.io/mkdocs-material/reference/code-blocks/#adding-annotations
43+
env.variables["code_annotation_marker"] = _CODE_ANNOTATION_MARKER
3344

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

0 commit comments

Comments
 (0)