Merge pull request #236 from mneitsabes/master

Add the ability to add a RichText object to another RichText object
This commit is contained in:
Eric Lapouyade 2019-11-09 20:41:21 +01:00 committed by GitHub
commit 4fe1cc507d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -625,6 +625,10 @@ class RichText(object):
font=None,
url_id=None):
# If a RichText is added
if isinstance(text, RichText):
self.xml += text.xml
return
# If not a string : cast to string (ex: int, dict etc...)
if not isinstance(text, (six.text_type, six.binary_type)):

View File

@ -9,7 +9,7 @@ from docxtpl import DocxTemplate, RichText
tpl=DocxTemplate('templates/richtext_tpl.docx')
rt = RichText('an exemple of ')
rt = RichText()
rt.add('a rich text', style='myrichtextstyle')
rt.add(' with ')
rt.add('some italic', italic=True)
@ -38,8 +38,11 @@ rt.add('superscript', superscript=True)
rt.add(' and some')
rt.add('subscript', subscript=True)
rt_embedded = RichText('an example of ')
rt_embedded.add(rt)
context = {
'example' : rt,
'example' : rt_embedded,
}
tpl.render(context)