fix template filter with quote

This commit is contained in:
elapouya 2015-05-11 12:50:35 +02:00
parent 423b3005ef
commit 0f1569188d
3 changed files with 10 additions and 2 deletions

View File

@ -1,3 +1,7 @@
0.1.5 (2015-05-11)
------------------
- fix template filter with quote
0.1.4 (2015-03-27) 0.1.4 (2015-03-27)
------------------ ------------------
- add RichText support - add RichText support

View File

@ -5,7 +5,7 @@ Created : 2015-03-12
@author: Eric Lapouyade @author: Eric Lapouyade
''' '''
__version__ = '0.1.4' __version__ = '0.1.5'
from lxml import etree from lxml import etree
from docx import Document from docx import Document
@ -53,10 +53,14 @@ class DocxTemplate(object):
# This is mandatory to have jinja2 generating correct xml code # 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} 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) src_xml = re.sub(pat, r'\1 \2',src_xml,flags=re.DOTALL)
src_xml = src_xml.replace(r"&#8216;","'")
return src_xml return src_xml
def render_xml(self,src_xml,context): def render_xml(self,src_xml,context):
with open('/tmp/titi','w') as fh:
fh.write(src_xml)
template = Template(src_xml) template = Template(src_xml)
dst_xml = template.render(context) dst_xml = template.render(context)
dst_xml = dst_xml.replace('{_{','{{').replace('}_}','}}').replace('{_%','{%').replace('%_}','%}') dst_xml = dst_xml.replace('{_{','{{').replace('}_}','}}').replace('{_%','{%').replace('%_}','%}')

View File

@ -24,7 +24,7 @@ News
""" % read('README', 'CHANGES') """ % read('README', 'CHANGES')
setup(name='docxtpl', setup(name='docxtpl',
version='0.1.4', version='0.1.5',
description='Python docx template engine', description='Python docx template engine',
long_description=long_description, long_description=long_description,
classifiers=[ classifiers=[