Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Line statements eat newlines #52

gavento opened this Issue Aug 3, 2011 · 4 comments


None yet
3 participants

gavento commented Aug 3, 2011

Line statements eat not only the spaces until the beginning of the line as documented at http://jinja.pocoo.org/docs/templates/#whitespace-control , but also all the previous newlines.

As of 2.7-dev, the following code generates no empty lines:

%% for i in range(3)
{{i}}, next line should be empty

%% endfor

This is an issue in languages where newlines matter (generated LaTeX).

gavento commented Aug 3, 2011

Can be fixed in lexer.py:200 by changing the regex from r'^\s*' to r'^[ \t\v]*'. This makes the whitespace list limited, but that should not be an issue without re.UNICODE or re.LOCALE

aspiers commented May 1, 2013

Hmm. There still needs to be a way of including blank lines in the code which do not get rendered in the output, but are only there for legibility. I propose that lines containing line_statement_prefix (or line_comment_prefix) and nothing else be the mechanism for this. Currently they are not handled in a helpful way (filed as #204 and #205).

aspiers commented May 2, 2013

Just discovered that {##} is a tolerable workaround.

@mitsuhiko mitsuhiko closed this in 08f38a8 May 19, 2013

mitsuhiko added a commit that referenced this issue May 19, 2013

Merge pull request #203 from aspiers/master
Prevent line statements eating newlines (fixes #52)

lajarre commented Apr 14, 2016

Newlines after a end control bloc (endif, endfor) are still eaten up:

%% for i in range(2)
%% endfor

I want to be alone

renders as =>

I want to be alone

Is this expected behavior? This doesn't make sense to me regarding the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment