From 333a04618015865a9319570547cce181686a43b7 Mon Sep 17 00:00:00 2001 From: Tolo Palmer Date: Fri, 7 Jun 2019 11:04:34 +0100 Subject: [PATCH] Handle spaces correctly when run are split by Jinja code --- docxtpl/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docxtpl/__init__.py b/docxtpl/__init__.py index 9f70ff8..d711801 100644 --- a/docxtpl/__init__.py +++ b/docxtpl/__init__.py @@ -99,8 +99,12 @@ class DocxTemplate(object): cellbg,src_xml,flags=re.DOTALL) # avoid {{r and {%r tags to strip MS xml tags too far + # ensure space preservation when splitting + src_xml = re.sub(r'((?:(?!).)*)({{r\s.*?}}|{%r\s.*?%})', + r'\1\2', + src_xml,flags=re.DOTALL) src_xml = re.sub(r'({{r\s.*?}}|{%r\s.*?%})', - r'\1', + r'\1', src_xml,flags=re.DOTALL) for y in ['tr', 'tc', 'p', 'r']: