=== modified file 'django/contrib/markup/templatetags/markup.py'
|
|
|
32 | 32 | return mark_safe(force_unicode(textile.textile(smart_str(value), encoding='utf-8', output='utf-8'))) |
33 | 33 | textile.is_safe = True |
34 | 34 | |
35 | | def markdown(value): |
| 35 | def markdown(value, arg=''): |
| 36 | """ |
| 37 | Runs Markdown over a given value, optionally using various |
| 38 | extensions python-markdown supports. |
| 39 | |
| 40 | Syntax:: |
| 41 | |
| 42 | {{ value|markdown:"extension1_name,extension2_name..." }} |
| 43 | |
| 44 | To enable safe mode, which strips raw HTML and only returns HTML |
| 45 | generated by actual Markdown syntax, pass "safe" as the first |
| 46 | extension in the list. |
| 47 | |
| 48 | If the version of Markdown in use does not support extensions, |
| 49 | they will be silently ignored. |
| 50 | |
| 51 | """ |
36 | 52 | try: |
37 | 53 | import markdown |
38 | 54 | except ImportError: |
… |
… |
|
40 | 56 | raise template.TemplateSyntaxError, "Error in {% markdown %} filter: The Python markdown library isn't installed." |
41 | 57 | return force_unicode(value) |
42 | 58 | else: |
43 | | return mark_safe(force_unicode(markdown.markdown(smart_str(value)))) |
| 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'): |
| 62 | extensions = [e for e in arg.split(",") if e] |
| 63 | if len(extensions) > 0 and extensions[0] == "safe": |
| 64 | extensions = extensions[1:] |
| 65 | safe_mode = True |
| 66 | else: |
| 67 | safe_mode = False |
| 68 | return mark_safe(force_unicode(markdown.markdown(smart_str(value), extensions, safe_mode=safe_mode))) |
| 69 | else: |
| 70 | return mark_safe(force_unicode(markdown.markdown(smart_str(value)))) |
44 | 71 | markdown.is_safe = True |
45 | 72 | |
46 | 73 | def restructuredtext(value): |