| 33 | | def markdown(value): |
|---|
| | 33 | def markdown(value, arg=''): |
|---|
| | 34 | """ |
|---|
| | 35 | Runs Markdown over a given value, optionally using various |
|---|
| | 36 | extensions python-markdown supports. |
|---|
| | 37 | |
|---|
| | 38 | Syntax:: |
|---|
| | 39 | |
|---|
| | 40 | {{ value|markdown:"extension1_name,extension2_name..." }} |
|---|
| | 41 | |
|---|
| | 42 | To enable safe mode, which strips raw HTML and only returns HTML |
|---|
| | 43 | generated by actual Markdown syntax, pass "safe" as the first |
|---|
| | 44 | extension in the list. |
|---|
| | 45 | |
|---|
| | 46 | If the version of Markdown in use does not support extensions, |
|---|
| | 47 | they will be silently ignored. |
|---|
| | 48 | |
|---|
| | 49 | """ |
|---|
| 38 | | raise template.TemplateSyntaxError, "Error in {% markdown %} filter: The Python markdown library isn't installed." |
|---|
| 39 | | return force_unicode(value) |
|---|
| | 54 | raise template.TemplateSyntaxError('Error in markdown filter: Markdown could not be imported.') |
|---|
| | 55 | else: |
|---|
| | 56 | # Try to salvage this; whatever we do, we shouldn't |
|---|
| | 57 | # return potentially unsafe HTML. |
|---|
| | 58 | from django.utils.html import escape, linebreaks |
|---|
| | 59 | return linebreaks(escape(value)) |
|---|