summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-04-15 22:03:47 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-04-15 22:03:47 -0400
commit3c640cb94438dda317198843f5b498306a2bf989 (patch)
tree67ce7dc393383d5205a9e1fa56db3aa9ff18d893 /main
parent2ea4e6f4d5245dd5e43c90d54635477c6e7dd6a7 (diff)
parent1a2709552704a91f9601a13c350153b3daf3a455 (diff)
Merge tag 'release_2014-12-08' into archweb-generic
Minor fixes and package updates
Diffstat (limited to 'main')
-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