Ticket #2910: 2910.diff
File 2910.diff, 1.9 KB (added by , 18 years ago) |
---|
-
django/contrib/markup/templatetags/markup.py
29 29 else: 30 30 return textile.textile(value, encoding=settings.DEFAULT_CHARSET, output=settings.DEFAULT_CHARSET) 31 31 32 def markdown(value): 32 def markdown(value, arg=''): 33 """ 34 Runs Markdown over a given value, optionally using various 35 extensions python-markdown supports. 36 37 Syntax:: 38 39 {{ value|markdown:"extension1_name,extension2_name..." }} 40 41 To enable safe mode, which strips raw HTML and only returns HTML 42 generated by actual Markdown syntax, pass "safe" as the first 43 extension in the list. 44 45 If the version of Markdown in use does not support extensions, 46 they will be silently ignored. 47 48 """ 33 49 try: 34 50 import markdown 35 51 except ImportError: 36 52 if settings.DEBUG: 37 raise template.TemplateSyntaxError, "Error in {% markdown %} filter: The Python markdown library isn't installed." 38 return value 53 raise template.TemplateSyntaxError('Error in markdown filter: Markdown could not be imported.') 54 else: 55 # Try to salvage this; whatever we do, we shouldn't 56 # return potentially unsafe HTML. 57 from django.utils.html import escape, linebreaks 58 return linebreaks(escape(value)) 39 59 else: 40 return markdown.markdown(value) 60 extensions=arg.split(",") 61 if len(extensions) > 0 and extensions[0] == "safe": 62 extensions = extensions[1:] 63 safe_mode = True 64 else: 65 safe_mode = False 66 return markdown.markdown(value, extensions, safe_mode=safe_mode) 41 67 42 68 def restructuredtext(value): 43 69 try: