diff --git a/docxtpl/__init__.py b/docxtpl/__init__.py
index aa1b1ee..29f63dc 100644
--- a/docxtpl/__init__.py
+++ b/docxtpl/__init__.py
@@ -27,6 +27,7 @@ import six
import binascii
import os
import zipfile
+from functools import partial
NEWLINE_XML = ''
NEWPARAGRAPH_XML = ''
@@ -234,8 +235,31 @@ class DocxTemplate(object):
.replace('}_}', '}}')
.replace('{_%', '{%')
.replace('%_}', '%}'))
+ dst_xml = self.resolve_listing(dst_xml)
return dst_xml
+ def resolve_listing(self, xml):
+ xml = xml.replace('\n', NEWLINE_XML)
+ xml = xml.replace('\t', TAB_XML)
+ xml = xml.replace('\f', PAGE_BREAK)
+
+ def resolve_run(paragraph_properties, m):
+ run_properties = re.search(r'.*', m[0])
+ run_properties = run_properties[0] if run_properties else ''
+ return m[0].replace('\a', '%s%s' % (paragraph_properties, run_properties))
+
+ def resolve_paragraph(m):
+ paragraph_properties = re.search(r'.*', m[0])
+ paragraph_properties = paragraph_properties[0] if paragraph_properties else ''
+
+ p_resolve_run = partial(resolve_run, paragraph_properties)
+
+ return re.sub(r']*)?>.*?', p_resolve_run, m[0])
+
+ xml = re.sub(r']*)?>.*?', resolve_paragraph, xml)
+
+ return xml
+
def build_xml(self, context, jinja_env=None):
xml = self.get_xml()
xml = self.patch_xml(xml)