Ticket #18041: 18041.diff

File 18041.diff, 6.0 KB (added by Claude Paroz, 12 years ago)

Do not support python-markdown < 2.1

  • 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:  
    1111    * reStructuredText, which requires docutils from http://docutils.sf.net/
    1212"""
    1313
    14 import warnings
    15 
    1614from django import template
    1715from django.conf import settings
    1816from django.utils.encoding import smart_str, force_unicode
    def markdown(value, arg=''):  
    5654            raise template.TemplateSyntaxError("Error in 'markdown' filter: The Python markdown library isn't installed.")
    5755        return force_unicode(value)
    5856    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:
    6264            extensions = [e for e in arg.split(",") if e]
    6365            if len(extensions) > 0 and extensions[0] == "safe":
    6466                extensions = extensions[1:]
    65                 safe_mode = True
     67                return mark_safe(markdown.markdown(
     68                    force_unicode(value), extensions, safe_mode=True, enable_attributes=False))
    6669            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))
    8872
    8973@register.filter(is_safe=True)
    9074def 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_  
    3737
    3838.. _link: http://www.example.com/"""
    3939
    40     @unittest.skipUnless(textile, 'texttile not installed')
     40    @unittest.skipUnless(textile, 'textile not installed')
    4141    def test_textile(self):
    4242        t = Template("{% load markup %}{{ textile_content|textile }}")
    4343        rendered = t.render(Context({'textile_content':self.textile_content})).strip()
    Paragraph 2 with a link_  
    4545
    4646<p>Paragraph 2 with &#8220;quotes&#8221; and <code>code</code></p>""")
    4747
    48     @unittest.skipIf(textile, 'texttile is installed')
     48    @unittest.skipIf(textile, 'textile is installed')
    4949    def test_no_textile(self):
    5050        t = Template("{% load markup %}{{ textile_content|textile }}")
    5151        rendered = t.render(Context({'textile_content':self.textile_content})).strip()
    5252        self.assertEqual(rendered, escape(self.textile_content))
    5353
    54     @unittest.skipUnless(markdown, 'markdown not installed')
     54    @unittest.skipUnless(markdown and markdown_version >= (2,1), 'markdown >= 2.1 not installed')
    5555    def test_markdown(self):
    5656        t = Template("{% load markup %}{{ markdown_content|markdown }}")
    5757        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  
    99languages:
    1010
    1111* ``textile`` -- implements `Textile`_ -- requires `PyTextile`_
    12 * ``markdown`` -- implements `Markdown`_ -- requires `Python-markdown`_
     12* ``markdown`` -- implements `Markdown`_ -- requires `Python-markdown`_ (>=2.1)
    1313* ``restructuredtext`` -- implements `reST (reStructured Text)`_
    1414  -- requires `doc-utils`_
    1515
    Markdown  
    5353
    5454The Python Markdown library supports options named "safe_mode" and
    5555"enable_attributes". Both relate to the security of the output. To enable both
    56 options in tandem, the markdown filter supports the "safe" argument.
     56options in tandem, the markdown filter supports the "safe" argument::
    5757
    5858    {{ markdown_content_var|markdown:"safe" }}
    5959
    6060.. warning::
    6161
    6262    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 in
    64     any output from the markdown filter - a warning is issued if this is the
    65     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.
Back to Top