Add `keep_trailing_newline` to configure final endline stripping
This option defaults to False for compatibility with the existing
behaviour. I've added the option because I expect I won't remember to
keep an extra trailing newline in my templates, and some non-HTML
templates *need* that last newline.
See also:
https://groups.google.com/d/msg/pocoo-libs/6DylMqq1voI/GXTbZJ1Tr-sJ
diff --git a/jinja2/ext.py b/jinja2/ext.py
index 206756f..650ddd2 100644
--- a/jinja2/ext.py
+++ b/jinja2/ext.py
@@ -589,7 +589,9 @@
options.get('line_statement_prefix') or LINE_STATEMENT_PREFIX,
options.get('line_comment_prefix') or LINE_COMMENT_PREFIX,
getbool(options, 'trim_blocks', TRIM_BLOCKS),
- NEWLINE_SEQUENCE, frozenset(extensions),
+ NEWLINE_SEQUENCE,
+ getbool(options, 'keep_trailing_newline', KEEP_TRAILING_NEWLINE),
+ frozenset(extensions),
cache_size=0,
auto_reload=False
)