diff --git a/hooks/kroki.py b/hooks/kroki.py index c05de6f..a8bcbaf 100644 --- a/hooks/kroki.py +++ b/hooks/kroki.py @@ -8,6 +8,8 @@ import hashlib from functools import partial from mkdocs.utils import write_file import os +from py_svg_hush import filter_svg +from scour.scour import scourString logger = get_plugin_logger("kroki") @@ -16,7 +18,9 @@ DIAGRAM_CACHE_TIME = timedelta(days=7) def get_kroki_diagram(source, language): encoded_diagram = base64.urlsafe_b64encode(zlib.compress(source.encode(), 9)).decode() - return download_and_cache_url(f"https://kroki.io/{language}/svg/{encoded_diagram}", DIAGRAM_CACHE_TIME) + svg = download_and_cache_url(f"https://kroki.io/{language}/svg/{encoded_diagram}", DIAGRAM_CACHE_TIME) + + return scourString(filter_svg(svg)).encode() def fence_div_format(site_dir, source, language, *args, attrs, **kwargs): diff --git a/requirements.txt b/requirements.txt index 06bdea3..41b807c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ pymdown-extensions pygments minify-html beautifulsoup4 +py-svg-hush +scour