From 60327d96a687669d8b8842ecf0ac16c11a8f6483 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 8 Dec 2014 19:52:55 -0600 Subject: Upgrade to python-markdown 2.5.2 safe_mode is now deprecated, so adjust things accordingly. Signed-off-by: Dan McGee --- main/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'main') 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 -- cgit v1.2.3