qotnews/apiserver/utils.py

58 lines
998 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',
'code',
'em',
'i',
'li',
'ol',
'strong',
'ul',
'p',
'hr',
'small',
'ins',
'sup',
'sub',
'details',
'summary',
'br',
'pre',
2019-12-14 07:39:10 +00:00
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'table',
'thead',
'tr',
'th',
'td',
'tbody',
2019-12-01 22:18:41 +00:00
]
clean = Cleaner(tags=ALLOWED_TAGS).clean