From f852bedba566f2af9a5cf7dd5be97609f9825a98 Mon Sep 17 00:00:00 2001 From: Erik Moqvist Date: Sat, 14 Dec 2019 15:25:31 +0100 Subject: [PATCH] Leave newlines in replace block function. --- tests/test_textparser.py | 4 ++-- textparser.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_textparser.py b/tests/test_textparser.py index 05fd9c4..d32dae4 100644 --- a/tests/test_textparser.py +++ b/tests/test_textparser.py @@ -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: diff --git a/textparser.py b/textparser.py index 6a76714..f5ca7fb 100644 --- a/textparser.py +++ b/textparser.py @@ -6,7 +6,7 @@ __author__ = 'Erik Moqvist' -__version__ = '0.22.0' +__version__ = '0.23.0' class _Mismatch(object): @@ -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:])