Skip to content

Commit

Permalink
v0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Lapouyade committed Nov 12, 2024
1 parent bc92389 commit 0f42e5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion docxtpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@author: Eric Lapouyade
"""
__version__ = "0.18.0"
__version__ = "0.19.0"

# flake8: noqa
from .inline_image import InlineImage
Expand Down
18 changes: 13 additions & 5 deletions docxtpl/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def v_merge(m1):
return re.sub(
r"(</w:tcPr[ >].*?<w:t(?:.*?)>)(.*?)(?:{%\s*vm\s*%})(.*?)(</w:t>)",
v_merge,
m.group(), # Everything between ``</w:tc>`` and ``</w:tc>`` with ``{% vm %}`` inside.
m.group(),
# Everything between ``</w:tc>`` and ``</w:tc>`` with ``{% vm %}`` inside.
flags=re.DOTALL,
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0f42e5a

Please sign in to comment.