Skip to content

Commit c1b4ae6

Browse files
committed
consider empty lines as part of the indented block
1 parent e20a708 commit c1b4ae6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

web/template.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,22 @@ def read_indented_block(self, text, indent):
392392
('a\nb\n', 'c')
393393
>>> read_indented_block(' a\n b\n c\nd', ' ')
394394
('a\n b\nc\n', 'd')
395+
>>> read_indented_block(' a\n\n b\nc', ' ')
396+
('a\n\n b\n', 'c')
395397
"""
396398
if indent == '':
397399
return '', text
398400

399401
block = ""
400-
while True:
401-
if text.startswith(indent):
402-
line, text = splitline(text)
402+
while text:
403+
line, text2 = splitline(text)
404+
if line.strip() == "":
405+
block += '\n'
406+
elif line.startswith(indent):
403407
block += line[len(indent):]
404408
else:
405409
break
410+
text = text2
406411
return block, text
407412

408413
def read_statement(self, text):
@@ -526,7 +531,7 @@ def emit(self, indent):
526531

527532
def __repr__(self):
528533
return 't' + repr(self.value)
529-
534+
530535
class ExpressionNode:
531536
def __init__(self, value, escape=True):
532537
self.value = value.strip()

0 commit comments

Comments
 (0)