Changes formatter.

This commit is contained in:
retoor 2025-02-07 18:06:48 +01:00
parent d4aaa2d66b
commit a301e2c5bf

View File

@ -1,7 +1,7 @@
# Original source: https://brandonjay.dev/posts/2021/render-markdown-html-in-python-with-jinja2 # Original source: https://brandonjay.dev/posts/2021/render-markdown-html-in-python-with-jinja2
from types import SimpleNamespace from types import SimpleNamespace
from html.parser import escape
from app.cache import time_cache_async from app.cache import time_cache_async
from mistune import HTMLRenderer, Markdown from mistune import HTMLRenderer, Markdown
from pygments import highlight from pygments import highlight
@ -34,7 +34,7 @@ class MarkdownRenderer(HTMLRenderer):
formatter = html.HtmlFormatter(lineseparator="<br>") formatter = html.HtmlFormatter(lineseparator="<br>")
result = highlight(code, lexer, formatter) result = highlight(code, lexer, formatter)
if not result: if not result:
return f"<pre>{code}</pre>" return f"<pre>{escape(code)}</pre>"
return result return result
def render(self): def render(self):