Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom extension set in filters
- Loading branch information
Showing
15 changed files
with
58 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+304 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/bold.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+859 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/code.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+223 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/italic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+343 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+344 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/list-bullet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+357 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/list-numeric.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+606 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/picture.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+537 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/preview.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+743 Bytes
django_markdown/static/django_markdown/sets/markdown-extra/images/quotes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
""" Support 'markdown' filter. """ | ||
import markdown as markdown_module | ||
from django import template | ||
from django.utils.encoding import force_text | ||
from django.utils.safestring import mark_safe | ||
|
||
from ..settings import MARKDOWN_EXTENSIONS | ||
from ..utils import markdown as _markdown, MARKDOWN_EXTENSIONS | ||
|
||
|
||
register = template.Library() | ||
|
||
|
||
@register.filter(is_safe=True) | ||
def markdown(value): | ||
""" Render markdown. | ||
def markdown(value, arg=None): | ||
""" Render markdown over a given value, optionally using varios extensions. | ||
:returns: A rendered string | ||
Default extensions could be defined which MARKDOWN_EXTENSIONS option. | ||
Syntax: :: | ||
{{value|markdown}} | ||
{{value|markdown:"tables,codehilite"}} | ||
:returns: A rendered markdown | ||
""" | ||
return mark_safe(markdown_module.markdown( | ||
force_text(value), extensions=MARKDOWN_EXTENSIONS, safe_mode=False)) | ||
extensions = (arg and arg.split(',')) or MARKDOWN_EXTENSIONS | ||
return _markdown(value, extensions=extensions, safe=False) | ||
|
||
|
||
@register.filter(is_safe=True) | ||
def markdown_safe(value): | ||
""" Safe Rendering markdown. | ||
def markdown_safe(value, arg=None): | ||
""" Render markdown over a given value, optionally using varios extensions. | ||
Default extensions could be defined which MARKDOWN_EXTENSIONS option. | ||
Enables safe mode, which strips raw HTML and only returns HTML generated | ||
by markdown. | ||
:returns: A rendered string. | ||
:returns: A rendered markdown. | ||
""" | ||
return mark_safe(markdown_module.markdown( | ||
force_text(value), extensions=MARKDOWN_EXTENSIONS, safe_mode=True)) | ||
extensions = (arg and arg.split(',')) or MARKDOWN_EXTENSIONS | ||
return _markdown(value, extensions=extensions, safe=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
""" Markdown utils. """ | ||
import markdown as markdown_module | ||
from django.utils.encoding import force_text | ||
from django.utils.safestring import mark_safe | ||
|
||
from .settings import MARKDOWN_EXTENSIONS | ||
|
||
|
||
def markdown(value, extensions=MARKDOWN_EXTENSIONS, safe=False): | ||
""" Render markdown over a given value, optionally using varios extensions. | ||
Default extensions could be defined which MARKDOWN_EXTENSIONS option. | ||
:returns: A rendered markdown | ||
""" | ||
return mark_safe(markdown_module.markdown( | ||
force_text(value), extensions=extensions, safe_mode=safe)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters