Markdown template filter for Django.
Maintained. Last release 6 months ago, commits in 2 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install django-markdownifyDjango Markdownify - A Django Markdown filter
Django Markdownify is a template filter to convert Markdown to HTML in Django. Markdown is converted to HTML and sanitized.
Read the full documentation on Read the docs or check out the package on pypi.
[!WARNING]
The old settings are removed in release 0.9.4! Please update to the new settings as soon as possible.
Usage
Load the tag inside your template:
{% load markdownify %}
Then you can change markdown to html as follows:
{{ 'text'|markdownify }}
or
{{ somevariable|markdownify }}
Example
{% load markdownify %}
{{'Some *test* [link](#)'|markdownify }}
Is transformed to:
<p>
Some <em>test</em> <a href="#">link</a>
</p>
The filter is a wrapper around Markdown and Bleach and as such supports their settings. It is possible to define multiple settings for multiple usecases.
For example:
# settings.py
MARKDOWNIFY = {
"default": {
"WHITELIST_TAGS": ["a", "p", "h1", ]
},
"alternative": {
"WHITELIST_TAGS": ["a", "p", ],
"MARKDOWN_EXTENSIONS": ["markdown.extensions.fenced_code", ]
}
}
And in your templates:
<!-- page1.html -->
{{ mytext|markdownify }} <!-- Uses your default settings -->
<!-- page2.html -->
{{ mytext|markdownify:"alternative" }} <!-- Uses your alternative settings -->