Skip to content

Instantly share code, notes, and snippets.

@nkryptic
Created February 21, 2013 04:47
Show Gist options
  • Save nkryptic/5002167 to your computer and use it in GitHub Desktop.
Save nkryptic/5002167 to your computer and use it in GitHub Desktop.
from django.template.base import Node, Library
register = Library()
class UnindentNode(Node):
def __init__(self, nodelist):
self.nodelist = nodelist
def render(self, context):
lines = self.nodelist.render(context).split('\n')
return '\n'.join(line.strip() for line in lines)
@register.tag
def unindent(parser, token):
nodelist = parser.parse(('endunindent',))
parser.delete_first_token()
return UnindentNode(nodelist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment