aboutsummaryrefslogtreecommitdiffhomepage
path: root/apioforum/mdrender.py
diff options
context:
space:
mode:
authorubq323 <ubq323>2021-06-14 14:33:36 +0000
committerubq323 <ubq323>2021-06-14 14:33:36 +0000
commit9e505bc638e0eb7d40f0ce18afdfeb1077a98075 (patch)
tree639b554dfc6d3289278c72fcf4cc9fe0ea55814c /apioforum/mdrender.py
parentee2c781e132dbf97fb493eb1453af03f4beb2279 (diff)
improve markdown rendering and html saniti(s/z)ation; enable strikethrough with tildes
Diffstat (limited to 'apioforum/mdrender.py')
-rw-r--r--apioforum/mdrender.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/apioforum/mdrender.py b/apioforum/mdrender.py
new file mode 100644
index 0000000..20e86bb
--- /dev/null
+++ b/apioforum/mdrender.py
@@ -0,0 +1,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