Allow reading diagrams from file
This commit is contained in:
parent
fa3cfce34a
commit
d247f39d0b
5 changed files with 47 additions and 5 deletions
11
content/nested/diagram.mmd
Normal file
11
content/nested/diagram.mmd
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
sequenceDiagram
|
||||||
|
participant Alice
|
||||||
|
participant Bob
|
||||||
|
Alice->John: Hello John, how are you?
|
||||||
|
loop Healthcheck
|
||||||
|
John->John: Fight against hypochondria
|
||||||
|
end
|
||||||
|
Note right of John: Rational thoughts prevail...
|
||||||
|
John-->Alice: Great!
|
||||||
|
John->Bob: How about you?
|
||||||
|
Bob-->John: Jolly good!
|
|
@ -4,3 +4,7 @@ tags:
|
||||||
- tag2
|
- tag2
|
||||||
---
|
---
|
||||||
# Nested
|
# Nested
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
{% include_file "./diagram.mmd" %}
|
||||||
|
```
|
||||||
|
|
19
hooks/include-file.py
Normal file
19
hooks/include-file.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from jinja2_simple_tags import StandaloneTag
|
||||||
|
import os
|
||||||
|
|
||||||
|
def on_env(env, config, files):
|
||||||
|
env.add_extension(IncludeFileTag)
|
||||||
|
|
||||||
|
return env
|
||||||
|
|
||||||
|
class IncludeFileTag(StandaloneTag):
|
||||||
|
tags = {"include_file"}
|
||||||
|
|
||||||
|
def render(self, path):
|
||||||
|
if path.startswith("/"):
|
||||||
|
file_path = os.path.join(self.context["config"]["site_dir"], path.removeprefix("/"))
|
||||||
|
else:
|
||||||
|
file_path = os.path.join(os.path.dirname(self.context["page"].file.abs_src_path), path)
|
||||||
|
|
||||||
|
with open(file_path) as f:
|
||||||
|
return f.read()
|
|
@ -47,11 +47,18 @@ def on_config(config):
|
||||||
opener.addheaders = [('User-Agent','mkdocs')]
|
opener.addheaders = [('User-Agent','mkdocs')]
|
||||||
install_opener(opener)
|
install_opener(opener)
|
||||||
|
|
||||||
custom_fences = [{
|
custom_fences = [
|
||||||
"name": "blockdiag",
|
{
|
||||||
"class": "blockdiag",
|
"name": "blockdiag",
|
||||||
"format": partial(fence_div_format, config["site_dir"])
|
"class": "blockdiag",
|
||||||
}]
|
"format": partial(fence_div_format, config["site_dir"])
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mermaid",
|
||||||
|
"class": "mermaid",
|
||||||
|
"format": partial(fence_div_format, config["site_dir"])
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
config.mdx_configs["pymdownx.superfences"] = {
|
config.mdx_configs["pymdownx.superfences"] = {
|
||||||
"custom_fences": custom_fences
|
"custom_fences": custom_fences
|
||||||
|
|
|
@ -18,6 +18,7 @@ hooks:
|
||||||
- hooks/globals.py
|
- hooks/globals.py
|
||||||
- hooks/pygments-styles.py
|
- hooks/pygments-styles.py
|
||||||
- hooks/kroki.py
|
- hooks/kroki.py
|
||||||
|
- hooks/include-file.py
|
||||||
|
|
||||||
markdown_extensions:
|
markdown_extensions:
|
||||||
- attr_list
|
- attr_list
|
||||||
|
|
Loading…
Reference in a new issue