diff --git a/hooks/kroki.py b/hooks/kroki.py index 5cf1b15..5e2eec4 100644 --- a/hooks/kroki.py +++ b/hooks/kroki.py @@ -11,14 +11,10 @@ import os from py_svg_hush import filter_svg from scour.scour import scourString from slugify import slugify +import json logger = get_plugin_logger("kroki") -DIAGRAM_TYPES = { - "blockdiag", - "mermaid" -} - DIAGRAM_CACHE_TIME = timedelta(days=7) @@ -62,13 +58,22 @@ def fence_div_format(site_dir, source, language, *args, attrs, **kwargs): return f"{title}" 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 = [ { "name": 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"] = {