revert 0.10.4
This commit is contained in:
parent
f9b95afe7a
commit
7282856484
@ -1,3 +1,7 @@
|
||||
0.10.5 (2020-10-15)
|
||||
-------------------
|
||||
- Revert 0.10.4 as the XML code get corrupted
|
||||
|
||||
0.10.4 (2020-10-15)
|
||||
-------------------
|
||||
- \\n \\t and \\f are now accepted in simple context string (#307, #312)
|
||||
|
||||
@ -7,7 +7,7 @@ Created : 2015-03-12
|
||||
import functools
|
||||
import io
|
||||
|
||||
__version__ = '0.10.4'
|
||||
__version__ = '0.10.5'
|
||||
|
||||
from lxml import etree
|
||||
from docx import Document
|
||||
@ -27,7 +27,6 @@ import six
|
||||
import binascii
|
||||
import os
|
||||
import zipfile
|
||||
from functools import partial
|
||||
|
||||
NEWLINE_XML = '</w:t><w:br/><w:t xml:space="preserve">'
|
||||
NEWPARAGRAPH_XML = '</w:t></w:r></w:p><w:p><w:r><w:t xml:space="preserve">'
|
||||
@ -235,33 +234,8 @@ class DocxTemplate(object):
|
||||
.replace('}_}', '}}')
|
||||
.replace('{_%', '{%')
|
||||
.replace('%_}', '%}'))
|
||||
dst_xml = self.resolve_listing(dst_xml)
|
||||
return dst_xml
|
||||
|
||||
def resolve_listing(self, xml):
|
||||
xml = xml.replace('\n', NEWLINE_XML)
|
||||
xml = xml.replace('\f', PAGE_BREAK)
|
||||
|
||||
def resolve_run(paragraph_properties, m):
|
||||
run_properties = re.search(r'<w:rPr>.*</w:rPr>', m[0])
|
||||
run_properties = run_properties[0] if run_properties else ''
|
||||
xml = m[0].replace('\t', '</w:t></w:r>'
|
||||
'<w:r>%s<w:tab/></w:r>'
|
||||
'<w:r>%s<w:t xml:space="preserve">' % (run_properties, run_properties))
|
||||
return xml.replace('\a', '</w:t></w:r></w:p><w:p>%s<w:r>%s<w:t>' % (paragraph_properties, run_properties))
|
||||
|
||||
def resolve_paragraph(m):
|
||||
paragraph_properties = re.search(r'<w:pPr>.*</w:pPr>', m[0])
|
||||
paragraph_properties = paragraph_properties[0] if paragraph_properties else ''
|
||||
|
||||
p_resolve_run = partial(resolve_run, paragraph_properties)
|
||||
|
||||
return re.sub(r'<w:r(?: [^>]*)?>.*?</w:r>', p_resolve_run, m[0])
|
||||
|
||||
xml = re.sub(r'<w:p(?: [^>]*)?>.*?</w:p>', resolve_paragraph, xml)
|
||||
|
||||
return xml
|
||||
|
||||
def build_xml(self, context, jinja_env=None):
|
||||
xml = self.get_xml()
|
||||
xml = self.patch_xml(xml)
|
||||
|
||||
@ -6,7 +6,7 @@ context = {
|
||||
'myvar': R(
|
||||
'"less than" must be escaped : <, this can be done with RichText() or R()'
|
||||
),
|
||||
'myescvar': 'Without using Richtext, you can simply escape text with a "|e" jinja filter in the template : < ',
|
||||
'myescvar': 'It can be escaped with a "|e" jinja filter in the template too : < ',
|
||||
'nlnp': R(
|
||||
'Here is a multiple\nlines\nstring\aand some\aother\aparagraphs\aNOTE: the current character styling is removed'
|
||||
),
|
||||
@ -14,11 +14,6 @@ context = {
|
||||
'the listing\nwith\nsome\nlines\nand special chars : <>&\f ... and a page break'
|
||||
),
|
||||
'page_break': R('\f'),
|
||||
'new_listing': """With the latest version of docxtpl,
|
||||
there is no need to use Listing objects anymore.
|
||||
Just use \\n for newline,\n\\t\t for tabulation and \\f for ...\f...page break
|
||||
One can also use special chars : <>& but you have then to add "|e" jinja filter in the template
|
||||
""",
|
||||
}
|
||||
|
||||
tpl.render(context)
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user