Adam Goldsmith
02986bdabc
https://bluesock.org/~willkg/blog/dev/bleach_6_0_0_deprecation.html nh3/ammonia is faster anyway. django-nh3 is not yet feature complete, but cmsmanage was only using the template tag anyway
28 lines
610 B
Python
28 lines
610 B
Python
import nh3
|
|
from markdownx.utils import markdownify
|
|
|
|
# fmt: off
|
|
MARKDOWN_TAGS = [
|
|
"h1", "h2", "h3", "h4", "h5", "h6",
|
|
"b", "i", "strong", "em", "tt", "sub", "sup",
|
|
"p", "br", "span", "div",
|
|
"blockquote", "code", "pre",
|
|
"hr",
|
|
"ul", "ol", "li",
|
|
"dl", "dd", "dt",
|
|
"img",
|
|
"a",
|
|
"table", "thead", "tbody", "tr", "th", "td",
|
|
]
|
|
|
|
MARKDOWN_ATTRS = {
|
|
"*": ["id"],
|
|
"img": ["src", "alt", "title"],
|
|
"a": ["href", "alt", "title"],
|
|
}
|
|
|
|
|
|
def markdown_to_clean_html(md: str) -> str:
|
|
x = nh3.clean(markdownify(md), tags=MARKDOWN_TAGS, attributes=MARKDOWN_ATTRS)
|
|
return x
|