deeily 5024bf9a8d init: full mail stack — phases 0..8 (web client, admin, IMAP/SMTP,
sieve, search, sessions, dramatiq, deploy/install, ELK, monitoring)
2026-04-29 16:30:43 +03:00

21 lines
654 B
Python

"""Markdown → безопасный HTML для тел писем."""
import bleach
import markdown as md
ALLOWED_TAGS = [
"p", "br", "strong", "em", "u", "s", "code", "pre", "blockquote",
"h1", "h2", "h3", "h4", "ul", "ol", "li", "a", "img", "hr",
"table", "thead", "tbody", "tr", "th", "td",
]
ALLOWED_ATTRS = {
"a": ["href", "title", "rel"],
"img": ["src", "alt", "title"],
}
def render(body_md: str) -> str:
if not body_md:
return ""
html = md.markdown(body_md, extensions=["fenced_code", "tables", "nl2br", "sane_lists"])
return bleach.clean(html, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRS, strip=True)