Ticket #2910: markup.3.diff

File markup.3.diff, 1.2 KB (added by Waylan Limberg <waylan@…>, 18 years ago)

Added check for older versions of Markdown, in which case the extensions are ignored silently.

  • contrib/markup/templatetags/markup.py

     
    2929    else:
    3030        return textile.textile(value, encoding=settings.DEFAULT_CHARSET, output=settings.DEFAULT_CHARSET)
    3131
    32 def markdown(value):
     32def markdown(value, arg = ''):
    3333    try:
    3434        import markdown
    3535    except ImportError:
     
    3737            raise template.TemplateSyntaxError, "Error in {% markdown %} filter: The Python markdown library isn't installed."
    3838        return value
    3939    else:
    40         return markdown.markdown(value)
     40        extensions = arg.split(',')
     41        if len(extensions) > 0 and extensions[0] == 'safe' :
     42            extensions = extensions[1:]
     43            safe_mode = True
     44        else:
     45            safe_mode = False
     46        try:
     47            return markdown.markdown(value, extensions, safe_mode = safe_mode)
     48        except TypeError:
     49            #older version of Markdown - run without  extensions
     50            return markdown.markdown(value)
    4151
    4252def restructuredtext(value):
    4353    try:
Back to Top