add {% vm %} to make the table cell virtically merged within a {% for %}
This commit is contained in:
parent
12f759cb8e
commit
2a7630a80b
@ -84,7 +84,17 @@ class DocxTemplate(object):
|
||||
# This is mandatory to have jinja2 generating correct xml code
|
||||
pat = r'<w:%(y)s[ >](?:(?!<w:%(y)s[ >]).)*({%%|{{)%(y)s ([^}%%]*(?:%%}|}})).*?</w:%(y)s>' % {'y':y}
|
||||
src_xml = re.sub(pat, r'\1 \2',src_xml,flags=re.DOTALL)
|
||||
|
||||
|
||||
# add vMerge
|
||||
# use {% vm %} to make this table cell and its copies be vertically merged within a {% for %}
|
||||
pat_vm = r'(<\/w:tcPr>.*)(<\/w:tcPr>)(.*?){%vm%}.*?<w:t>(.*?)(<\/w:t>)'
|
||||
def vMerge(m):
|
||||
return m.group(1) + '<w:vMerge {% if loop.first %}w:val="restart"{% endif %}/>' + m.group(2) + m.group(3) + "{% if loop.first %}"+ m.group(4) +"{% endif %}" + m.group(5)
|
||||
pat_num_vm = re.compile(r'{%vm%}')
|
||||
num = len(pat_num_vm.findall(src_xml))
|
||||
for i in range(0,num):
|
||||
src_xml = re.sub(pat_vm,vMerge,src_xml)
|
||||
|
||||
def clean_tags(m):
|
||||
return m.group(0).replace(r"‘","'").replace('<','<').replace('>','>')
|
||||
src_xml = re.sub(r'(?<=\{[\{%])(.*?)(?=[\}%]})',clean_tags,src_xml)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user