2019-08-28 04:13:02 +00:00
|
|
|
import logging
|
2019-12-14 07:39:10 +00:00
|
|
|
logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
2019-08-28 04:13:02 +00:00
|
|
|
level=logging.DEBUG)
|
|
|
|
|
|
|
|
import commonmark
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
2019-12-01 22:18:41 +00:00
|
|
|
from bleach.sanitizer import Cleaner
|
|
|
|
|
2019-08-28 04:13:02 +00:00
|
|
|
def gen_rand_id():
|
2020-11-21 21:21:31 +00:00
|
|
|
return ''.join(random.choice(string.ascii_uppercase) for _ in range(5))
|
2019-08-28 04:13:02 +00:00
|
|
|
|
|
|
|
def render_md(md):
|
|
|
|
if md:
|
|
|
|
return commonmark.commonmark(md)
|
|
|
|
else:
|
|
|
|
return ''
|
2019-12-01 22:18:41 +00:00
|
|
|
|
|
|
|
ALLOWED_TAGS = [
|
|
|
|
'a',
|
|
|
|
'abbr',
|
|
|
|
'acronym',
|
|
|
|
'b',
|
|
|
|
'blockquote',
|
2020-01-04 23:37:41 +00:00
|
|
|
'br',
|
2019-12-01 22:18:41 +00:00
|
|
|
'code',
|
2020-01-04 23:37:41 +00:00
|
|
|
'del',
|
|
|
|
'details',
|
2019-12-01 22:18:41 +00:00
|
|
|
'em',
|
2020-01-04 23:37:41 +00:00
|
|
|
'h1',
|
|
|
|
'h2',
|
|
|
|
'h3',
|
|
|
|
'h4',
|
|
|
|
'h5',
|
|
|
|
'h6',
|
|
|
|
'hr',
|
2019-12-01 22:18:41 +00:00
|
|
|
'i',
|
2020-01-04 23:37:41 +00:00
|
|
|
'ins',
|
2019-12-01 22:18:41 +00:00
|
|
|
'li',
|
|
|
|
'ol',
|
|
|
|
'p',
|
2020-01-04 23:37:41 +00:00
|
|
|
'pre',
|
2019-12-01 22:18:41 +00:00
|
|
|
'small',
|
2020-01-04 23:37:41 +00:00
|
|
|
'strong',
|
2019-12-01 22:18:41 +00:00
|
|
|
'sub',
|
|
|
|
'summary',
|
2020-01-04 23:37:41 +00:00
|
|
|
'sup',
|
2019-12-14 07:39:10 +00:00
|
|
|
'table',
|
2020-01-04 23:37:41 +00:00
|
|
|
'tbody',
|
|
|
|
'td',
|
|
|
|
'th',
|
2019-12-14 07:39:10 +00:00
|
|
|
'thead',
|
|
|
|
'tr',
|
2020-01-04 23:37:41 +00:00
|
|
|
'ul',
|
2019-12-01 22:18:41 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
clean = Cleaner(tags=ALLOWED_TAGS).clean
|