Ticket #18041: 18041.diff
File 18041.diff, 6.0 KB (added by , 13 years ago) |
---|
-
django/contrib/markup/templatetags/markup.py
diff --git a/django/contrib/markup/templatetags/markup.py b/django/contrib/markup/templatetags/markup.py index b9fdce8..161a06b 100644
a b markup syntaxes to HTML; currently there is support for: 11 11 * reStructuredText, which requires docutils from http://docutils.sf.net/ 12 12 """ 13 13 14 import warnings15 16 14 from django import template 17 15 from django.conf import settings 18 16 from django.utils.encoding import smart_str, force_unicode … … def markdown(value, arg=''): 56 54 raise template.TemplateSyntaxError("Error in 'markdown' filter: The Python markdown library isn't installed.") 57 55 return force_unicode(value) 58 56 else: 59 # markdown.version was first added in 1.6b. The only version of markdown 60 # to fully support extensions before 1.6b was the shortlived 1.6a. 61 if hasattr(markdown, 'version'): 57 markdown_vers = getattr(markdown, "version_info", 0) 58 if markdown_vers < (2,1): 59 if settings.DEBUG: 60 raise template.TemplateSyntaxError( 61 "Error in 'markdown' filter: Django does not support versions of the Python markdown library < 2.1.") 62 return force_unicode(value) 63 else: 62 64 extensions = [e for e in arg.split(",") if e] 63 65 if len(extensions) > 0 and extensions[0] == "safe": 64 66 extensions = extensions[1:] 65 safe_mode = True 67 return mark_safe(markdown.markdown( 68 force_unicode(value), extensions, safe_mode=True, enable_attributes=False)) 66 69 else: 67 safe_mode = False 68 python_markdown_deprecation = "The use of Python-Markdown " 69 "< 2.1 in Django is deprecated; please update to the current version" 70 # Unicode support only in markdown v1.7 or above. Version_info 71 # exist only in markdown v1.6.2rc-2 or above. 72 markdown_vers = getattr(markdown, "version_info", None) 73 if markdown_vers < (1,7): 74 warnings.warn(python_markdown_deprecation, DeprecationWarning) 75 return mark_safe(force_unicode(markdown.markdown(smart_str(value), extensions, safe_mode=safe_mode))) 76 else: 77 if markdown_vers >= (2,1): 78 if safe_mode: 79 return mark_safe(markdown.markdown(force_unicode(value), extensions, safe_mode=safe_mode, enable_attributes=False)) 80 else: 81 return mark_safe(markdown.markdown(force_unicode(value), extensions, safe_mode=safe_mode)) 82 else: 83 warnings.warn(python_markdown_deprecation, DeprecationWarning) 84 return mark_safe(markdown.markdown(force_unicode(value), extensions, safe_mode=safe_mode)) 85 else: 86 warnings.warn(python_markdown_deprecation, DeprecationWarning) 87 return mark_safe(force_unicode(markdown.markdown(smart_str(value)))) 70 return mark_safe(markdown.markdown( 71 force_unicode(value), extensions, safe_mode=False)) 88 72 89 73 @register.filter(is_safe=True) 90 74 def restructuredtext(value): -
django/contrib/markup/tests.py
diff --git a/django/contrib/markup/tests.py b/django/contrib/markup/tests.py index cccb5c8..d3e4e1d 100644
a b Paragraph 2 with a link_ 37 37 38 38 .. _link: http://www.example.com/""" 39 39 40 @unittest.skipUnless(textile, 'text tile not installed')40 @unittest.skipUnless(textile, 'textile not installed') 41 41 def test_textile(self): 42 42 t = Template("{% load markup %}{{ textile_content|textile }}") 43 43 rendered = t.render(Context({'textile_content':self.textile_content})).strip() … … Paragraph 2 with a link_ 45 45 46 46 <p>Paragraph 2 with “quotes” and <code>code</code></p>""") 47 47 48 @unittest.skipIf(textile, 'text tile is installed')48 @unittest.skipIf(textile, 'textile is installed') 49 49 def test_no_textile(self): 50 50 t = Template("{% load markup %}{{ textile_content|textile }}") 51 51 rendered = t.render(Context({'textile_content':self.textile_content})).strip() 52 52 self.assertEqual(rendered, escape(self.textile_content)) 53 53 54 @unittest.skipUnless(markdown , 'markdownnot installed')54 @unittest.skipUnless(markdown and markdown_version >= (2,1), 'markdown >= 2.1 not installed') 55 55 def test_markdown(self): 56 56 t = Template("{% load markup %}{{ markdown_content|markdown }}") 57 57 rendered = t.render(Context({'markdown_content':self.markdown_content})).strip() -
docs/ref/contrib/markup.txt
diff --git a/docs/ref/contrib/markup.txt b/docs/ref/contrib/markup.txt index 3abc27b..4ee2f94 100644
a b Django provides template filters that implement the following markup 9 9 languages: 10 10 11 11 * ``textile`` -- implements `Textile`_ -- requires `PyTextile`_ 12 * ``markdown`` -- implements `Markdown`_ -- requires `Python-markdown`_ 12 * ``markdown`` -- implements `Markdown`_ -- requires `Python-markdown`_ (>=2.1) 13 13 * ``restructuredtext`` -- implements `reST (reStructured Text)`_ 14 14 -- requires `doc-utils`_ 15 15 … … Markdown 53 53 54 54 The Python Markdown library supports options named "safe_mode" and 55 55 "enable_attributes". Both relate to the security of the output. To enable both 56 options in tandem, the markdown filter supports the "safe" argument .56 options in tandem, the markdown filter supports the "safe" argument:: 57 57 58 58 {{ markdown_content_var|markdown:"safe" }} 59 59 60 60 .. warning:: 61 61 62 62 Versions of the Python-Markdown library prior to 2.1 do not support the 63 optional disabling of attributes and by default they will be included in64 any output from the markdown filter - a warning is issued if this is the65 case.63 optional disabling of attributes. This is a security flaw. Therefore, 64 ``django.contrib.markup`` has dropped support for versions of 65 Python-Markdown < 2.1 in Django 1.5.