Line statements eat newlines #52

Closed
gavento opened this Issue Aug 3, 2011 · 4 comments

Projects

None yet

3 participants

@gavento
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
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
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
aspiers commented May 2, 2013

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

@mitsuhiko mitsuhiko pushed a commit that closed this issue May 19, 2013
Adam Spiers Prevent line statements eating newlines (fixes #52) 08f38a8
@mitsuhiko mitsuhiko closed this in 08f38a8 May 19, 2013
@lajarre
lajarre commented Apr 14, 2016

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

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

I want to be alone

renders as =>

hello
hello
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