markdown: support disabling the sanitizer

Now that the sanitizer has become pretty strict, this will be needed for
the root wiki, where sanitization is not a concern, as the content comes
from the admin(s).
This commit is contained in:
Conrad Hoffmann 2024-01-09 11:31:53 +01:00
parent b4cdcb0d60
commit aa38fcfc88
1 changed files with 5 additions and 4 deletions

View File

@ -242,19 +242,20 @@ def add_noopener(html):
a['rel'] = 'nofollow noopener'
return str(soup)
def markdown(text, baselevel=1, link_prefix=None, with_styles=True):
def markdown(text, baselevel=1, link_prefix=None, with_styles=True, sanitize=True):
text = text.replace("\r\n", "\n") # https://github.com/miyuchina/mistletoe/issues/124
with SrhtRenderer(link_prefix, baselevel) as renderer:
html = renderer.render(m.Document(text))
formatter = HtmlFormatter()
if sanitize:
html = sanitize(html)
if with_styles:
style = ".highlight { background: inherit; }"
return Markup(f"<style>{style}</style>"
+ "<div class='markdown'>"
+ sanitize(html)
+ html
+ "</div>")
else:
return Markup(sanitize(html))
return Markup(html)
Heading = namedtuple("Header", ["level", "name", "id", "children", "parent"])