Skip to content

Instantly share code, notes, and snippets.

@Jwpe
Last active August 8, 2016 03:40
Show Gist options
  • Save Jwpe/fad38fd47679ff57f0d4 to your computer and use it in GitHub Desktop.
Save Jwpe/fad38fd47679ff57f0d4 to your computer and use it in GitHub Desktop.
Markdown template filter in Django 1.5+
from django import template
import markdown
register = template.Library()
@register.filter
def markdownify(text):
# safe_mode governs how the function handles raw HTML
return markdown.markdown(text, safe_mode='escape')
{% load markdown_filter %}
<html>
...
<div class="md-content">
{{ my_markdown_content|markdownify|safe }}
</div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment