Created
November 7, 2013 15:48
-
-
Save curtmerrill/7356817 to your computer and use it in GitHub Desktop.
Markdown template tag for Django
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
# Creates a template tag so you can use Markdown in textfields | |
# | |
# REQUIRES: | |
# - markdown 2 -- pip install markdown2 | |
# | |
# USAGE: | |
# - Create a folder in your app called "templatetags" | |
# - Save this file and an __init__.py in the folder | |
# - In your template, add "{% load markdown_tag %}" at top | |
# - {{ field|md }} will output escaped markup | |
# - {{ field|md|safe }} outputs "safe" markup | |
from django import template | |
from django.template.defaultfilters import stringfilter | |
import markdown2 | |
register = template.Library() | |
@register.filter(name="md") | |
@stringfilter | |
def markdown(value): | |
return markdown2.markdown(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment