from __future__ import unicode_literals import bleach import markdown tags = bleach.sanitizer.ALLOWED_TAGS[:] tags.extend(['p', 'pre']) def parse(text): md = markdown.markdown(text, extensions=['extra']) text = bleach.clean(md, tags=tags) return text