qotnews/apiserver/utils.py

59 lines
1013 B
Python
Raw Normal View History

import logging
2019-12-14 07:39:10 +00:00
logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.DEBUG)
import commonmark
import random
import string
2019-12-01 22:18:41 +00:00
from bleach.sanitizer import Cleaner
def gen_rand_id():
return ''.join(random.choice(string.ascii_uppercase) for _ in range(4))
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