Skip to content

Commit

Permalink
Leave newlines in replace block function.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Dec 14, 2019
1 parent 1d6c98e commit f852bed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/test_textparser.py
Expand Up @@ -1040,8 +1040,8 @@ def test_replace_blocks(self):
datas = [
('{}', '{}'),
('{{}}', '{ }'),
('{{} xxx {}}', '{ }'),
('1{a}2{b}3', '1{ }2{ }3')
('{{\n} xxx {}}', '{ \n }'),
('1{a\n}2{b}3', '1{ \n}2{ }3')
]

for old, expected in datas:
Expand Down
8 changes: 6 additions & 2 deletions textparser.py
Expand Up @@ -6,7 +6,7 @@


__author__ = 'Erik Moqvist'
__version__ = '0.22.0'
__version__ = '0.23.0'


class _Mismatch(object):
Expand Down Expand Up @@ -911,7 +911,11 @@ def replace_blocks(string, start='{', end='}'):
depth -= 1

if depth == 0:
chunks.append(' ' * (pos - begin))
for chunk in string[begin:pos].split('\n'):
chunks.append(' ' * len(chunk))
chunks.append('\n')

chunks.pop()
begin = pos

chunks.append(string[begin:])
Expand Down

0 comments on commit f852bed

Please sign in to comment.