summaryrefslogtreecommitdiff
path: root/main/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'main/utils.py')
-rw-r--r--main/utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/main/utils.py b/main/utils.py
index cf156566..f94f314d 100644
--- a/main/utils.py
+++ b/main/utils.py
@@ -4,6 +4,8 @@ except ImportError:
import pickle
import hashlib
+import markdown
+from markdown.extensions import Extension
from django.core.cache import cache
from django.db import connections, router
@@ -109,6 +111,19 @@ def database_vendor(model, mode='read'):
return connections[database].vendor
+class EscapeHtml(Extension):
+ def extendMarkdown(self, md, md_globals):
+ del md.preprocessors['html_block']
+ del md.inlinePatterns['html']
+
+
+def parse_markdown(text, allow_html=False):
+ if allow_html:
+ return markdown.markdown(text, enable_attributes=False)
+ ext = [EscapeHtml()]
+ return markdown.markdown(text, extensions=ext, enable_attributes=False)
+
+
def groupby_preserve_order(iterable, keyfunc):
'''Take an iterable and regroup using keyfunc to determine whether items
belong to the same group. The order of the iterable is preserved and