This commit is contained in:
Eric Lapouyade 2020-10-27 10:07:42 +01:00
parent 4af6f2282f
commit 53d582c407
2 changed files with 12 additions and 8 deletions

View File

@ -1,3 +1,7 @@
0.11.1 (2020-10-27)
-------------------
- fix #320
0.11.0 (2020-10-19) 0.11.0 (2020-10-19)
------------------- -------------------
- \\n, \\a, \\t and \\f are now accepted in simple context string. Thanks to chabErch@github - \\n, \\a, \\t and \\f are now accepted in simple context string. Thanks to chabErch@github

View File

@ -4,7 +4,7 @@ Created : 2015-03-12
@author: Eric Lapouyade @author: Eric Lapouyade
""" """
__version__ = '0.11.0' __version__ = '0.11.1'
import functools import functools
import io import io
@ -234,7 +234,7 @@ class DocxTemplate(object):
def resolve_listing(self, xml): def resolve_listing(self, xml):
def resolve_text(run_properties, paragraph_properties, m): def resolve_text(run_properties, paragraph_properties, m):
xml = m[0].replace('\t', '</w:t></w:r>' xml = m.group(0).replace('\t', '</w:t></w:r>'
'<w:r>%s<w:tab/></w:r>' '<w:r>%s<w:tab/></w:r>'
'<w:r>%s<w:t xml:space="preserve">' % (run_properties, run_properties)) '<w:r>%s<w:t xml:space="preserve">' % (run_properties, run_properties))
xml = xml.replace('\a', '</w:t></w:r></w:p>' xml = xml.replace('\a', '</w:t></w:r></w:p>'
@ -246,18 +246,18 @@ class DocxTemplate(object):
return xml return xml
def resolve_run(paragraph_properties, m): def resolve_run(paragraph_properties, m):
run_properties = re.search(r'<w:rPr>.*</w:rPr>', m[0]) run_properties = re.search(r'<w:rPr>.*</w:rPr>', m.group(0))
run_properties = run_properties[0] if run_properties else '' run_properties = run_properties.group(0) if run_properties else ''
return re.sub(r'<w:t(?:[^>]*)?>.*?</w:t>', return re.sub(r'<w:t(?:[^>]*)?>.*?</w:t>',
lambda x: resolve_text(run_properties, paragraph_properties, x), m[0], lambda x: resolve_text(run_properties, paragraph_properties, x), m.group(0),
flags=re.DOTALL) flags=re.DOTALL)
def resolve_paragraph(m): def resolve_paragraph(m):
paragraph_properties = re.search(r'<w:pPr>.*</w:pPr>', m[0]) paragraph_properties = re.search(r'<w:pPr>.*</w:pPr>', m.group(0))
paragraph_properties = paragraph_properties[0] if paragraph_properties else '' paragraph_properties = paragraph_properties.group(0) if paragraph_properties else ''
return re.sub(r'<w:r(?:[^>]*)?>.*?</w:r>', return re.sub(r'<w:r(?:[^>]*)?>.*?</w:r>',
lambda x: resolve_run(paragraph_properties, x), lambda x: resolve_run(paragraph_properties, x),
m[0], flags=re.DOTALL) m.group(0), flags=re.DOTALL)
xml = re.sub(r'<w:p(?:[^>]*)?>.*?</w:p>', resolve_paragraph, xml, flags=re.DOTALL) xml = re.sub(r'<w:p(?:[^>]*)?>.*?</w:p>', resolve_paragraph, xml, flags=re.DOTALL)