You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Following up #52, I'm wondering while Jinja does not also keep leading empty lines after a line statement.
Expected Behavior
== No empty lines
0
1
2
== Leading empty line
0
1
2
== Trailing empty line
0
1
2
== Leading and trailing empty lines
0
1
2
Actual Behavior
== No empty lines
0
1
2
== Leading empty line
0
1
2
== Trailing empty line
0
1
2
== Leading and trailing empty lines
0
1
2
Template Code
env=Environment(line_statement_prefix='%%')
print('== No empty lines')
print(env.from_string("""%% for item in seq{{item}}%% endfor""").render(seq=list(range(3))), end='')
print('== Leading empty line')
print(env.from_string("""%% for item in seq{{item}}%% endfor""").render(seq=list(range(3))), end='')
print('== Trailing empty line')
print(env.from_string("""%% for item in seq{{item}}%% endfor""").render(seq=list(range(3))), end='')
print('== Leading and trailing empty lines')
print(env.from_string("""%% for item in seq{{item}}%% endfor""").render(seq=list(range(3))), end='')
Your Environment
Python version: 2.7.17
Jinja version: 2.11.2
Proposed Fix
The fix for #52 only handled the trailing empty lines. Here is a fix to also handle the leading empty lines:
diff --git a/src/jinja2/lexer.py b/src/jinja2/lexer.py
index 552356a..f8fb7f5 100644 src/jinja2/lexer.py
--- a/src/jinja2/lexer.py+++ b/src/jinja2/lexer.py@@ -593,7 +593,7 @@ class Lexer(object):
],
# line statements
TOKEN_LINESTATEMENT_BEGIN: [
- (c(r"\s*(\n|$)"), TOKEN_LINESTATEMENT_END, "#pop")+ (c(r"[ \t\v]*(\n|$)"), TOKEN_LINESTATEMENT_END, "#pop")
]
+ tag_rules,
# line comments
The text was updated successfully, but these errors were encountered:
Following up #52, I'm wondering while Jinja does not also keep leading empty lines after a line statement.
Expected Behavior
Actual Behavior
Template Code
Your Environment
Proposed Fix
The fix for #52 only handled the trailing empty lines. Here is a fix to also handle the leading empty lines:
The text was updated successfully, but these errors were encountered: