Fix #923: Use same markdown widget for all content fields (rules, description, reports, notes, etc.)

This commit is contained in:
Eliot Berriot 2020-02-06 15:52:08 +01:00
parent 8d29adf6be
commit 7850ca3e1c
No known key found for this signature in database
GPG key ID: 6B501DFD73514E14
12 changed files with 128 additions and 75 deletions

View file

@ -250,36 +250,42 @@ def join_queries_or(left, right):
def render_markdown(text):
return markdown.markdown(text, extensions=["nl2br"])
return markdown.markdown(text, extensions=["nl2br", "extra"])
HTMl_CLEANER = bleach.sanitizer.Cleaner(
SAFE_TAGS = [
"p",
"a",
"abbr",
"acronym",
"b",
"blockquote",
"code",
"em",
"i",
"li",
"ol",
"strong",
"ul",
]
HTMl_CLEANER = bleach.sanitizer.Cleaner(strip=True, tags=SAFE_TAGS)
HTML_PERMISSIVE_CLEANER = bleach.sanitizer.Cleaner(
strip=True,
tags=[
"p",
"a",
"abbr",
"acronym",
"b",
"blockquote",
"code",
"em",
"i",
"li",
"ol",
"strong",
"ul",
],
tags=SAFE_TAGS + ["h1", "h2", "h3", "h4", "h5", "h6", "div", "section", "article"],
attributes=["class", "rel", "alt", "title"],
)
HTML_LINKER = bleach.linkifier.Linker()
def clean_html(html):
return HTMl_CLEANER.clean(html)
def clean_html(html, permissive=False):
return (
HTML_PERMISSIVE_CLEANER.clean(html) if permissive else HTMl_CLEANER.clean(html)
)
def render_html(text, content_type):
def render_html(text, content_type, permissive=False):
rendered = render_markdown(text)
if content_type == "text/html":
rendered = text
@ -288,7 +294,7 @@ def render_html(text, content_type):
else:
rendered = render_markdown(text)
rendered = HTML_LINKER.linkify(rendered)
return clean_html(rendered).strip().replace("\n", "")
return clean_html(rendered, permissive=permissive).strip().replace("\n", "")
def render_plain_text(html):