Skip to content

Commit d1cf04b

Browse files
committed
Insert suggestion to use MkDocs-Macros for variables and macros
- bump version number
1 parent 4959ee4 commit d1cf04b

2 files changed

Lines changed: 62 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,14 @@ name = "mkdocs-mermaid2-plugin"
33

44
# This version number is the REFERENCE for the rest of the project,
55
# particularly for update_pypi.sh
6-
version = "1.2.2"
6+
version = "1.2.3"
77

88
description = "A MkDocs plugin for including mermaid graphs in markdown sources"
99
readme = "README.md"
1010
license = { text = "MIT" }
1111
requires-python = ">=3.8"
12-
authors = [
13-
{ name = "Laurent Franceschetti"},
14-
]
15-
keywords = [
16-
"markdown",
17-
"mermaid",
18-
"mkdocs",
19-
"python",
20-
]
12+
authors = [{ name = "Laurent Franceschetti" }]
13+
keywords = ["markdown", "mermaid", "mkdocs", "python"]
2114
classifiers = [
2215
"Development Status :: 5 - Production/Stable",
2316
"Intended Audience :: Developers",
@@ -42,17 +35,10 @@ dependencies = [
4235
packages = { find = { exclude = ["*.tests"] } }
4336

4437
[project.optional-dependencies]
45-
test = [
46-
"mkdocs-macros-test",
47-
"mkdocs-material",
48-
"packaging",
49-
"requests-html",
50-
]
38+
test = ["mkdocs-macros-test", "mkdocs-material", "packaging", "requests-html"]
5139

5240
[project.entry-points."mkdocs.plugins"]
5341
mermaid2 = "mermaid2.plugin:MarkdownMermaidPlugin"
5442

5543
[project.urls]
5644
Homepage = "https://github.com/fralau/mkdocs-mermaid2-plugin"
57-
58-

webdoc/docs/tips.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,64 @@
11
# Tips and Tricks
22

33

4+
## Using variables and macros in diagrams (MkDocs-Macros)
5+
6+
What if your diagrams contain a repetitive string, like the URL of a website?
7+
8+
Instead of writing:
9+
10+
```
11+
graph TD;
12+
Platform-->Gaming;
13+
click Gaming "http://127.0.0.1:8000/Gaming/";
14+
```
15+
16+
You might want to use a **variable**:
17+
18+
```
19+
graph TD;
20+
Platform-->Gaming;
21+
click Gaming "{{ my_website }}/Gaming/";
22+
```
23+
24+
With the variable defined in your project's config file:
25+
26+
```yaml
27+
extra:
28+
my_website: http://127.0.0.1:8000
29+
```
30+
31+
32+
In this way, you will be able to change that value whenenever you need it.
33+
34+
To do that, you would have to use the [Mkdocs-Macros plugin](https://mkdocs-macros-plugin.readthedocs.io/).
35+
36+
37+
38+
This requires [installing the plugin](https://mkdocs-macros-plugin.readthedocs.io/en/latest/#standard-installation), and declaring it in the config file.
39+
40+
!!! Caution
41+
Variables are **not** part of the Mermaid specification. The Macros plugin simply expands the variables in the
42+
Markdown page, so that the result is a standard Mermaid diagram.
43+
44+
The same variables can be used in any part of the page, outside of Mermaid diagrams.
45+
46+
47+
Declare the plugins in the config file, in that order:
48+
49+
```yaml
50+
plugins:
51+
- search
52+
- macros
53+
- mermaid2
54+
```
55+
56+
!!! Tip "Using macros to generate diagrams"
57+
If you can program in Python, you could go further than that: you could use a Python module (`main.py`) to define
58+
[**macros** (functions)](https://mkdocs-macros-plugin.readthedocs.io/en/latest/macros/)
59+
that produce hyperlinks or pieces of diagrams from data,
60+
or even complete diagrams from a source file.
61+
462

563
## Setting the security level to "loose"
664

0 commit comments

Comments
 (0)