Manage autoscaping on InlineImage, Richtext and Subdoc
This commit is contained in:
parent
ee9cfd1d3e
commit
aa9889fc26
@ -1,3 +1,7 @@
|
||||
0.4.9 (2018-05-08)
|
||||
------------------
|
||||
- Manage autoscaping on InlineImage, Richtext and Subdoc
|
||||
|
||||
0.4.8 (2018-04-20)
|
||||
------------------
|
||||
- Purge MANIFEST.in file
|
||||
|
||||
@ -5,7 +5,7 @@ Created : 2015-03-12
|
||||
@author: Eric Lapouyade
|
||||
'''
|
||||
|
||||
__version__ = '0.4.8'
|
||||
__version__ = '0.4.9'
|
||||
|
||||
from lxml import etree
|
||||
from docx import Document
|
||||
@ -368,6 +368,9 @@ class Subdoc(object):
|
||||
def __str__(self):
|
||||
return self._get_xml()
|
||||
|
||||
def __html__(self):
|
||||
return self._get_xml()
|
||||
|
||||
|
||||
class RichText(object):
|
||||
""" class to generate Rich Text when using templates variables
|
||||
@ -430,6 +433,9 @@ class RichText(object):
|
||||
def __str__(self):
|
||||
return self.xml
|
||||
|
||||
def __html__(self):
|
||||
return self.xml
|
||||
|
||||
R = RichText
|
||||
|
||||
class Listing(object):
|
||||
@ -446,6 +452,9 @@ class Listing(object):
|
||||
def __str__(self):
|
||||
return self.xml
|
||||
|
||||
def __html__(self):
|
||||
return self.xml
|
||||
|
||||
|
||||
class InlineImage(object):
|
||||
"""Class to generate an inline image
|
||||
@ -476,5 +485,7 @@ class InlineImage(object):
|
||||
def __str__(self):
|
||||
return self._insert_image()
|
||||
|
||||
def __html__(self):
|
||||
return self._insert_image()
|
||||
|
||||
|
||||
|
||||
@ -8,6 +8,8 @@ Created : 2017-01-14
|
||||
from docxtpl import DocxTemplate, InlineImage
|
||||
# for height and width you have to use millimeters (Mm), inches or points(Pt) class :
|
||||
from docx.shared import Mm, Inches, Pt
|
||||
import jinja2
|
||||
from jinja2.utils import Markup
|
||||
|
||||
tpl=DocxTemplate('test_files/inline_image_tpl.docx')
|
||||
|
||||
@ -31,6 +33,7 @@ context = {
|
||||
'desc': 'Tornado is a Python web framework and asynchronous networking library.'},
|
||||
]
|
||||
}
|
||||
|
||||
tpl.render(context)
|
||||
# testing that it works also when autoescape has been forced to True
|
||||
jinja_env = jinja2.Environment(autoescape=True)
|
||||
tpl.render(context, jinja_env)
|
||||
tpl.save('test_files/inline_image.docx')
|
||||
|
||||
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.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user