Skip to content

Instantly share code, notes, and snippets.

@jacobian
Created January 7, 2011 18:28
Show Gist options
  • Save jacobian/769872 to your computer and use it in GitHub Desktop.
Save jacobian/769872 to your computer and use it in GitHub Desktop.
from django import template
from django.template import defaulttags
from django.utils.safestring import mark_for_escaping
register = template.Library()
class EscapedNode(template.Node):
def __init__(self, node):
self.node = node
def render(self, context):
return mark_for_escaping(self.node.render(context))
@register.tag
def firstof(parser, token):
node = defaulttags.firstof(parser, token)
return EscapedNode(node)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment