1
0
Fork 0
mirror of https://github.com/Findus23/lw1.at.git synced 2024-09-09 04:03:45 +02:00
lw1.at/lw1/tomarkdown.py
2023-02-27 00:44:18 +01:00

29 lines
677 B
Python

import markdown_katex
from markdown import markdown
from markupsafe import Markup
from lw1.cache import cache
from lw1.utils import long_hash
def markdown2html(md: str) -> Markup:
key = "md" + long_hash(md)
cached = cache.get(key)
if cached:
return Markup(cached)
html = markdown(
md,
extensions=[
"codehilite",
"fenced_code",
"tables",
markdown_katex.KatexExtension(insert_fonts_css=False),
]
)
cache.set(key, html)
return Markup(html)
if __name__ == '__main__':
with open("content/numba-timing/en.md") as f:
md = f.read()
print(markdown2html(md))