Skip to content

Instantly share code, notes, and snippets.

@tkaemming
Created May 14, 2010 20:07
Show Gist options
  • Save tkaemming/401597 to your computer and use it in GitHub Desktop.
Save tkaemming/401597 to your computer and use it in GitHub Desktop.
import re
from django import template
register = template.Library()
@register.filter
def gist(value):
gist_regex = re.compile(r'http://gist\.github\.com/(?P<hash>[\d]+)/?')
return gist_regex.sub(lambda match: u'<script src="http://gist.github.com/%s.js"></script>' % match.group('hash'), value)
gist.is_safe = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment