[damned-lies] Include markdown filter deprecated in Django
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Include markdown filter deprecated in Django
- Date: Wed, 23 Oct 2013 16:23:12 +0000 (UTC)
commit 792bd05559dd1ea360511024aa5cabe7df2eb761
Author: Claude Paroz <claude 2xlibre net>
Date: Wed Oct 23 18:16:44 2013 +0200
Include markdown filter deprecated in Django
The markdown filter will be removed along with django.contrib.markup
in Django 1.6.
settings.py | 1 -
stats/templatetags/stats_extras.py | 33 +++++++++++++++++++++++++++++++++
templates/teams/team_detail.html | 2 +-
3 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/settings.py b/settings.py
index 1bfdb56..c42aa37 100644
--- a/settings.py
+++ b/settings.py
@@ -129,7 +129,6 @@ INSTALLED_APPS = (
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.humanize',
- 'django.contrib.markup',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
diff --git a/stats/templatetags/stats_extras.py b/stats/templatetags/stats_extras.py
index eae110f..bc5149a 100644
--- a/stats/templatetags/stats_extras.py
+++ b/stats/templatetags/stats_extras.py
@@ -3,6 +3,7 @@ import re
from django import template
from django.conf import settings
+from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from django.utils.translation import get_language_bidi
@@ -237,3 +238,35 @@ def bugzilla_linkify(text):
result = bug_id.sub(repl, text)
result = result.replace('.cgi?id=#', '.cgi?id=')
return mark_safe(result)
+
+
+ register filter(is_safe=True)
+def markdown(value, arg=''):
+ """
+ Copy of deprecated django.contrib.markup
+ Runs Markdown over a given value, optionally using various
+ extensions python-markdown supports.
+
+ Syntax::
+
+ {{ value|markdown:"extension1_name,extension2_name..." }}
+
+ To enable safe mode, which strips raw HTML and only returns HTML
+ generated by actual Markdown syntax, pass "safe" as the first
+ extension in the list.
+ """
+ try:
+ import markdown
+ except ImportError:
+ if settings.DEBUG:
+ raise template.TemplateSyntaxError("Error in 'markdown' filter: The Python markdown library
isn't installed.")
+ return force_text(value)
+ else:
+ extensions = [e for e in arg.split(",") if e]
+ if extensions and extensions[0] == "safe":
+ extensions = extensions[1:]
+ return mark_safe(markdown.markdown(
+ force_text(value), extensions, safe_mode=True, enable_attributes=False))
+ else:
+ return mark_safe(markdown.markdown(
+ force_text(value), extensions, safe_mode=False))
diff --git a/templates/teams/team_detail.html b/templates/teams/team_detail.html
index e2ea022..6985f4a 100644
--- a/templates/teams/team_detail.html
+++ b/templates/teams/team_detail.html
@@ -1,5 +1,5 @@
{% extends "base.html" %}
-{% load i18n stats_extras markup %}
+{% load i18n stats_extras %}
{% load url from future %}
{% block extrahead %}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]