diff options
author | Dan McGee <dan@archlinux.org> | 2014-12-08 19:52:55 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2014-12-08 19:52:55 -0600 |
commit | 60327d96a687669d8b8842ecf0ac16c11a8f6483 (patch) | |
tree | fe8f5a15f994fd21251bcd9dd41f62e76a7958ad /main | |
parent | 9faa6d580e73adfe0f3a194b09d7f6b91b80aae9 (diff) |
Upgrade to python-markdown 2.5.2
safe_mode is now deprecated, so adjust things accordingly.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'main')
-rw-r--r-- | main/utils.py | 15 |
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 |