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']: