diff --git a/docxtpl/__init__.py b/docxtpl/__init__.py index 2ab1e9e..96a8997 100644 --- a/docxtpl/__init__.py +++ b/docxtpl/__init__.py @@ -109,6 +109,11 @@ class DocxTemplate(object): r'\1', src_xml,flags=re.DOTALL) + # {%- will merge with previous paragraph text + src_xml = re.sub(r'(?:(?!).)*?{%-','{%',src_xml,flags=re.DOTALL) + # -%} will merge with next paragraph text + src_xml = re.sub(r'-%}(?:(?!]).)*?]*?>','%}',src_xml,flags=re.DOTALL) + for y in ['tr', 'tc', 'p', 'r']: # replace into xml code the row/paragraph/run containing # {%y xxx %} or {{y xxx}} template tag diff --git a/tests/merge_paragraph.py b/tests/merge_paragraph.py new file mode 100644 index 0000000..90e84e3 --- /dev/null +++ b/tests/merge_paragraph.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +''' +Created : 2015-03-12 + +@author: Eric Lapouyade +''' + +from docxtpl import DocxTemplate + +tpl=DocxTemplate('templates/merge_paragraph_tpl.docx') + +context = { + 'living_in_town' : True, +} + +tpl.render(context) +tpl.save('output/merge_paragraph.docx') diff --git a/tests/templates/merge_paragraph_tpl.docx b/tests/templates/merge_paragraph_tpl.docx new file mode 100644 index 0000000..71faa5a Binary files /dev/null and b/tests/templates/merge_paragraph_tpl.docx differ