symposion_app/symposion/markdown_parser.py
Carlos Henrique Romano 36ab6d599f Fix flake8 warnings
2014-07-30 15:19:26 -03:00

16 lines
431 B
Python

from html5lib import html5parser, sanitizer
import markdown
def parse(text):
# First run through the Markdown parser
text = markdown.markdown(text, extensions=["extra"], safe_mode=False)
# Sanitize using html5lib
bits = []
parser = html5parser.HTMLParser(tokenizer=sanitizer.HTMLSanitizer)
for token in parser.parseFragment(text).childNodes:
bits.append(token.toxml())
return "".join(bits)