Add jinja2 tags test file

This commit is contained in:
Eric Lapouyade 2018-05-15 18:21:20 +02:00
parent aa9889fc26
commit f2e76d0e61
23 changed files with 14 additions and 2 deletions

View File

@ -1,3 +1,7 @@
0.4.10 (2018-05-08)
------------------
- Wheel distribution
0.4.9 (2018-05-08)
------------------
- Manage autoscaping on InlineImage, Richtext and Subdoc

View File

@ -5,7 +5,7 @@ Created : 2015-03-12
@author: Eric Lapouyade
'''
__version__ = '0.4.9'
__version__ = '0.4.10'
from lxml import etree
from docx import Document
@ -19,6 +19,8 @@ import six
import binascii
import os
import zipfile
from six.moves import html_parser
unescape = html_parser.HTMLParser().unescape
NEWLINE = '</w:t><w:br/><w:t xml:space="preserve">'
NEWPARAGRAPH = '</w:t></w:r></w:p><w:p><w:r><w:t xml:space="preserve">'
@ -55,6 +57,7 @@ class DocxTemplate(object):
def patch_xml(self,src_xml):
# strip all xml tags inside {% %} and {{ }} that MS word can insert into xml source
# also unescape html entities
src_xml = re.sub(r'(?<={)(<[^>]*>)+(?=[\{%])|(?<=[%\}])(<[^>]*>)+(?=\})','',src_xml,flags=re.DOTALL)
def striptags(m):
return re.sub('</w:t>.*?(<w:t>|<w:t [^>]*>)','',m.group(0),flags=re.DOTALL)

View File

@ -6,7 +6,7 @@ tests = sorted(glob.glob('[A-Za-z]*.py'))
excludes = ['runtests.py']
for test in tests:
if test not in excludes:
if test not in excludes and test.startswith('unescape'):
six.print_('%s ...' % test)
subprocess.call(['python','./%s' % test])

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,5 @@
from docxtpl import *
tpl = DocxTemplate('test_files/unescape_jinja2_tags_tpl.docx')
tpl.render({})
tpl.save('test_files/unescape_jinja2_tags.docx')