Dynamically get supported kroki languages
This commit is contained in:
parent
61f0bd2a43
commit
8da317e061
1 changed files with 12 additions and 7 deletions
|
@ -11,14 +11,10 @@ import os
|
||||||
from py_svg_hush import filter_svg
|
from py_svg_hush import filter_svg
|
||||||
from scour.scour import scourString
|
from scour.scour import scourString
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
|
import json
|
||||||
|
|
||||||
logger = get_plugin_logger("kroki")
|
logger = get_plugin_logger("kroki")
|
||||||
|
|
||||||
DIAGRAM_TYPES = {
|
|
||||||
"blockdiag",
|
|
||||||
"mermaid"
|
|
||||||
}
|
|
||||||
|
|
||||||
DIAGRAM_CACHE_TIME = timedelta(days=7)
|
DIAGRAM_CACHE_TIME = timedelta(days=7)
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,13 +58,22 @@ def fence_div_format(site_dir, source, language, *args, attrs, **kwargs):
|
||||||
return f"<img src='{image_url}' alt='{title}' />"
|
return f"<img src='{image_url}' alt='{title}' />"
|
||||||
|
|
||||||
def on_config(config):
|
def on_config(config):
|
||||||
|
kroki_langs = [
|
||||||
|
lang
|
||||||
|
for lang, version
|
||||||
|
in json.loads(download_and_cache_url("https://kroki.io/health", DIAGRAM_CACHE_TIME))["version"].items()
|
||||||
|
if isinstance(version, str)
|
||||||
|
]
|
||||||
|
|
||||||
|
format_kroki_diagram = partial(fence_div_format, config["site_dir"])
|
||||||
|
|
||||||
custom_fences = [
|
custom_fences = [
|
||||||
{
|
{
|
||||||
"name": diagram,
|
"name": diagram,
|
||||||
"class": diagram,
|
"class": diagram,
|
||||||
"format": partial(fence_div_format, config["site_dir"])
|
"format": format_kroki_diagram
|
||||||
}
|
}
|
||||||
for diagram in DIAGRAM_TYPES
|
for diagram in kroki_langs
|
||||||
]
|
]
|
||||||
|
|
||||||
config.mdx_configs["pymdownx.superfences"] = {
|
config.mdx_configs["pymdownx.superfences"] = {
|
||||||
|
|
Loading…
Reference in a new issue