Add jinja2 tags test file
This commit is contained in:
parent
aa9889fc26
commit
f2e76d0e61
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
tests/test_files/unescape_jinja2_tags.docx
Normal file
BIN
tests/test_files/unescape_jinja2_tags.docx
Normal file
Binary file not shown.
BIN
tests/test_files/unescape_jinja2_tags_tpl.docx
Normal file
BIN
tests/test_files/unescape_jinja2_tags_tpl.docx
Normal file
Binary file not shown.
Binary file not shown.
5
tests/unescape_jinja2_tags.py
Normal file
5
tests/unescape_jinja2_tags.py
Normal 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')
|
||||
Loading…
x
Reference in New Issue
Block a user