1
Fork 0

Allow reading diagrams from file

This commit is contained in:
Jake Howard 2023-09-15 18:05:28 +01:00
parent fa3cfce34a
commit d247f39d0b
Signed by: jake
GPG key ID: 57AFB45680EDD477
5 changed files with 47 additions and 5 deletions

View 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!

View file

@ -4,3 +4,7 @@ tags:
- tag2
---
# Nested
```mermaid
{% include_file "./diagram.mmd" %}
```

19
hooks/include-file.py Normal file
View 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()

View file

@ -47,11 +47,18 @@ def on_config(config):
opener.addheaders = [('User-Agent','mkdocs')]
install_opener(opener)
custom_fences = [{
"name": "blockdiag",
"class": "blockdiag",
"format": partial(fence_div_format, config["site_dir"])
}]
custom_fences = [
{
"name": "blockdiag",
"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"] = {
"custom_fences": custom_fences

View file

@ -18,6 +18,7 @@ hooks:
- hooks/globals.py
- hooks/pygments-styles.py
- hooks/kroki.py
- hooks/include-file.py
markdown_extensions:
- attr_list