1
Fork 0

Compress and filter SVGs before saving

This commit is contained in:
Jake Howard 2023-09-15 17:41:31 +01:00
parent bbdaebfcb0
commit fa3cfce34a
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 7 additions and 1 deletions

View file

@ -8,6 +8,8 @@ import hashlib
from functools import partial from functools import partial
from mkdocs.utils import write_file from mkdocs.utils import write_file
import os import os
from py_svg_hush import filter_svg
from scour.scour import scourString
logger = get_plugin_logger("kroki") logger = get_plugin_logger("kroki")
@ -16,7 +18,9 @@ DIAGRAM_CACHE_TIME = timedelta(days=7)
def get_kroki_diagram(source, language): def get_kroki_diagram(source, language):
encoded_diagram = base64.urlsafe_b64encode(zlib.compress(source.encode(), 9)).decode() 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): def fence_div_format(site_dir, source, language, *args, attrs, **kwargs):

View file

@ -4,3 +4,5 @@ pymdown-extensions
pygments pygments
minify-html minify-html
beautifulsoup4 beautifulsoup4
py-svg-hush
scour