summaryrefslogtreecommitdiffhomepage
path: root/apioforum/mdrender.py
blob: 20e86bb4c9a8d0b056908e6ebb9dc8e48f765ca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import bleach

allowed_tags = [
    'p',
    'h1',
    'h2',
    'h3',
    'h4',
    'h5',
    'pre',
    'del',
]
allowed_tags.extend(bleach.sanitizer.ALLOWED_TAGS)

cleaner = bleach.sanitizer.Cleaner(tags=allowed_tags)

import markdown
md = markdown.Markdown(extensions=['pymdownx.tilde'])

def render(text):
    text = md.reset().convert(text)
    text = cleaner.clean(text)
    return text