{%- xxx -%} merging feature
This commit is contained in:
parent
ccac13390a
commit
97be69b950
@ -109,6 +109,11 @@ class DocxTemplate(object):
|
||||
r'</w:t></w:r><w:r><w:t xml:space="preserve">\1</w:t></w:r><w:r><w:t xml:space="preserve">',
|
||||
src_xml,flags=re.DOTALL)
|
||||
|
||||
# {%- will merge with previous paragraph text
|
||||
src_xml = re.sub(r'</w:t>(?:(?!</w:t>).)*?{%-','{%',src_xml,flags=re.DOTALL)
|
||||
# -%} will merge with next paragraph text
|
||||
src_xml = re.sub(r'-%}(?:(?!<w:t[ >]).)*?<w:t[^>]*?>','%}',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
|
||||
|
||||
17
tests/merge_paragraph.py
Normal file
17
tests/merge_paragraph.py
Normal file
@ -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')
|
||||
BIN
tests/templates/merge_paragraph_tpl.docx
Normal file
BIN
tests/templates/merge_paragraph_tpl.docx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user