From 0f42e5a4c8191185c05e07a908d682bf6566d11d Mon Sep 17 00:00:00 2001 From: Eric Lapouyade Date: Tue, 12 Nov 2024 14:27:06 +0100 Subject: [PATCH] v0.19.0 --- CHANGES.rst | 6 +++++- docxtpl/__init__.py | 2 +- docxtpl/template.py | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 5cc87de..823059f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,11 @@ +0.19.0 (2024-11-12) +------------------- +- Support rendering variables in footnotes (Thanks to Bart Broere) + 0.18.0 (2024-07-21) ------------------- - IMPORTANT : Remove Python 2.x support -- Add hyperlink option in InlineImage (thanks to Jean Marcos da Rosa) +- Add hyperlink option in InlineImage (Thanks to Jean Marcos da Rosa) - Update index.rst (Thanks to jkpet) - Add poetry env - Black all files diff --git a/docxtpl/__init__.py b/docxtpl/__init__.py index c5d79cf..e0f7f50 100644 --- a/docxtpl/__init__.py +++ b/docxtpl/__init__.py @@ -4,7 +4,7 @@ @author: Eric Lapouyade """ -__version__ = "0.18.0" +__version__ = "0.19.0" # flake8: noqa from .inline_image import InlineImage diff --git a/docxtpl/template.py b/docxtpl/template.py index 2a442fa..d9ab3ff 100644 --- a/docxtpl/template.py +++ b/docxtpl/template.py @@ -210,7 +210,8 @@ def v_merge(m1): return re.sub( r"(].*?)(.*?)(?:{%\s*vm\s*%})(.*?)()", v_merge, - m.group(), # Everything between ```` and ```` with ``{% vm %}`` inside. + m.group(), + # Everything between ```` and ```` with ``{% vm %}`` inside. flags=re.DOTALL, ) @@ -310,7 +311,7 @@ def render_xml_part(self, src_xml, part, context, jinja_env=None): line_number = max(exc.lineno - 4, 0) exc.docx_context = map( lambda x: re.sub(r"<[^>]+>", "", x), - src_xml.splitlines()[line_number:(line_number + 7)], + src_xml.splitlines()[line_number : (line_number + 7)], ) raise exc @@ -352,15 +353,22 @@ def render_properties( setattr(self.docx.core_properties, prop, rendered) def render_footnotes( - self, context: Dict[str, Any], jinja_env: Optional[Environment] = None + self, context: Dict[str, Any], jinja_env: Optional[Environment] = None ) -> None: if jinja_env is None: jinja_env = Environment() for section in self.docx.sections: for part in section.part.package.parts: - if part.content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml': - xml = self.patch_xml(part.blob.decode('utf-8') if isinstance(part.blob, bytes) else part.blob) + if part.content_type == ( + "application/vnd.openxmlformats-officedocument" + ".wordprocessingml.footnotes+xml" + ): + xml = self.patch_xml( + part.blob.decode("utf-8") + if isinstance(part.blob, bytes) + else part.blob + ) xml = self.render_xml_part(xml, part, context, jinja_env) part._blob = xml