| 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 | """ |
|---|
| 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)))) |
|---|