File tree Expand file tree Collapse file tree 5 files changed +57
-5
lines changed
Expand file tree Collapse file tree 5 files changed +57
-5
lines changed Original file line number Diff line number Diff line change 1+ # License: MIT
2+ # Copyright © 2023 Frequenz Energy-as-a-Service GmbH
3+
4+ """This module defines macros for use in Markdown files."""
5+
6+ import pathlib
7+
8+ from markdown .extensions import toc
9+ from mkdocs_macros import plugin as macros
10+
11+
12+ def define_env (env : macros .MacrosPlugin ) -> None :
13+ """Define the hook to create macro functions for use in Markdown.
14+
15+ Args:
16+ env: The environment to define the macro functions in.
17+ """
18+
19+ def _slugify (text : str ) -> str :
20+ """Slugify a text.
21+
22+ Args:
23+ text: The text to slugify.
24+
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]
32+
33+ @env .macro # type: ignore[misc]
34+ def glossary (term : str ) -> str :
35+ """Create a link to the glossary entry for the given term.
36+
37+ Args:
38+ term: The term to link to.
39+
40+ Returns:
41+ The Markdown link to the glossary entry for the given term.
42+ """
43+ current_path = pathlib .Path (env .page .file .src_uri )
44+ glossary_path = pathlib .Path ("intro/glossary.md" )
45+ link_path = glossary_path .relative_to (current_path .parent )
46+ return f"[{ term } ]({ link_path } #{ _slugify (term )} )"
File renamed without changes.
Original file line number Diff line number Diff line change @@ -49,7 +49,9 @@ python3 -m venv .venv
4949
5050 This will create the virtual environment and activate it automatically for you.
5151
52- Now you can install the SDK by using ` pip ` :
52+ Now you can install the SDK by using ` pip ` (if you don't have ` pip ` installed
53+ you can follow [ the official
54+ instructions] ( https://pip.pypa.io/en/stable/installation/ ) ):
5355
5456``` sh
5557python3 -m pip install frequenz-sdk
@@ -63,5 +65,5 @@ $ python3
6365Python 3.11.4 (main, Jun 7 2023, 10:13:09) [GCC 12.2.0] on linux
6466Type "help", "copyright", "credits" or "license" for more information.
6567>>> import frequenz.sdk
66- >>>
68+ >>>
6769```
Original file line number Diff line number Diff line change @@ -85,9 +85,13 @@ markdown_extensions:
8585plugins :
8686 - gen-files :
8787 scripts :
88- - docs/mkdocstrings_autoapi.py
88+ - docs/_scripts/ mkdocstrings_autoapi.py
8989 - literate-nav :
9090 nav_file : SUMMARY.md
91+ - macros :
92+ module_name : docs/_scripts/macros
93+ on_undefined : strict
94+ on_error_fail : true
9195 - mike :
9296 canonical_version : latest
9397 - mkdocstrings :
@@ -120,5 +124,4 @@ plugins:
120124# Preview controls
121125watch :
122126 - " src"
123- - README.md
124127 - CONTRIBUTING.md
Original file line number Diff line number Diff line change @@ -62,8 +62,8 @@ dev-mkdocs = [
6262 " mike == 1.1.2" ,
6363 " mkdocs-gen-files == 0.5.0" ,
6464 " mkdocs-literate-nav == 0.6.1" ,
65+ " mkdocs-macros-plugin == 1.0.4" ,
6566 " mkdocs-material == 9.3.1" ,
66- " mkdocs-section-index == 0.3.7" ,
6767 " mkdocstrings[python] == 0.23.0" ,
6868 " frequenz-repo-config[lib] == 0.6.1" ,
6969]
@@ -176,6 +176,7 @@ module = [
176176 " async_solipsism.*" ,
177177 " grpc.aio" ,
178178 " grpc.aio.*" ,
179+ " mkdocs_macros.*" ,
179180 # There is a stubs package available, but it's not working:
180181 # https://github.com/eggplants/networkx-stubs/issues/1
181182 " networkx" ,
You can’t perform that action at this time.
0 commit comments