Skip to content

Instantly share code, notes, and snippets.

@skhaz
Created July 21, 2011 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skhaz/1096448 to your computer and use it in GitHub Desktop.
Save skhaz/1096448 to your computer and use it in GitHub Desktop.
"""
https://github.com/coffin/coffin/blob/master/coffin/template/defaulttags.py
"""
class SpacelessExtension(Extension):
"""Removes whitespace between HTML tags, including tab and
newline characters.
Works exactly like Django's own tag.
"""
tags = set(['spaceless'])
def parse(self, parser):
lineno = parser.stream.next().lineno
body = parser.parse_statements(['name:endspaceless'], drop_needle=True)
return nodes.CallBlock(
self.call_method('_strip_spaces', [], [], None, None),
[], [], body,
).set_lineno(lineno)
def _strip_spaces(self, caller=None):
from django.utils.html import strip_spaces_between_tags
return strip_spaces_between_tags(caller().strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment