Skip to content

Instantly share code, notes, and snippets.

@bertwesarg
Created November 24, 2011 09:49
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 bertwesarg/1390994 to your computer and use it in GitHub Desktop.
Save bertwesarg/1390994 to your computer and use it in GitHub Desktop.
Patch to re-add final newline
diff --git i/jinja2/lexer.py w/jinja2/lexer.py
index 69865d0..6a540e2 100644 jinja2/lexer.py
--- i/jinja2/lexer.py
+++ w/jinja2/lexer.py
@@ -549,7 +549,12 @@ class Lexer(object):
"""This method tokenizes the text and returns the tokens in a
generator. Use this method if you just want to tokenize a template.
"""
+ add_final_nl = False
+ if source[-2:] is '\r\n' or source[-1] in ['\r', '\n']:
+ add_final_nl = True
source = '\n'.join(unicode(source).splitlines())
+ if add_final_nl:
+ source += '\n'
pos = 0
lineno = 1
stack = ['root']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment