Fix: Markdown-Filter liefert jetzt Markup, sonst escaped Jinja2 die HTML-Tags
Symptom: auf /lektion/1 waren <strong>, <h3>, <ul>, <p> als Text zu sehen
statt gerendert. Ursache: markdown_filter gab einen normalen str zurueck,
und Jinja2 escaped str-Werte per Default fuer XSS-Schutz.
Fix: Rueckgabe als markupsafe.Markup() — markiert das Ergebnis als
'bereits escaped, hands off'.
Betrifft auch andere Stellen, die {{ ...|markdown }} nutzen
(cockpit.html bei Projekt-Beschreibung).
This commit is contained in:
7
app.py
7
app.py
@@ -41,17 +41,22 @@ app.register_blueprint(bp_api)
|
||||
# Markdown-Filter fuer Templates (Pattern wie arduino.lehrstun.de)
|
||||
# ===========================================================================
|
||||
import markdown as _markdown
|
||||
from markupsafe import Markup
|
||||
|
||||
|
||||
@app.template_filter("markdown")
|
||||
def markdown_filter(text):
|
||||
"""Rendert Markdown zu HTML und markiert das Ergebnis als 'safe',
|
||||
damit Jinja2 die HTML-Tags nicht escaped (sonst sieht man <strong>
|
||||
statt fettem Text)."""
|
||||
if not text:
|
||||
return ""
|
||||
return _markdown.markdown(
|
||||
html = _markdown.markdown(
|
||||
text,
|
||||
extensions=["fenced_code", "tables", "nl2br"],
|
||||
output_format="html5",
|
||||
)
|
||||
return Markup(html)
|
||||
|
||||
|
||||
# ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user