diff --git a/CHANGES.rst b/CHANGES.rst index 99f796d..d10f89c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,6 +15,8 @@ Unreleased properties like ``w:textAlignment``, and ``{%-``/``-%}`` next to a table no longer drop its tags. - Templates saved by LibreOffice no longer get a second ``docProps/core.xml``, which made LibreOffice refuse the generated file. +- A subdoc that ends with a table gets an empty paragraph after it, so ``{{p subdoc }}`` at the + end of the document or of a table cell no longer makes Word reject the file. 0.21.0 (2026-11-15) ------------------- diff --git a/docform/docx/subdoc.py b/docform/docx/subdoc.py index 5ff351f..deccadc 100644 --- a/docform/docx/subdoc.py +++ b/docform/docx/subdoc.py @@ -171,6 +171,10 @@ def _get_xml(self): wrapper = etree.Element(destination_body.tag, nsmap=destination_body.nsmap) for element in body: wrapper.append(deepcopy(element)) + # Word needs a paragraph after a table at the end of a cell or of the + # document, and {{p subdoc }} can put the subdoc's last table there. + if wrapper[-1].tag == "{%s}tbl" % nsmap["w"]: + etree.SubElement(wrapper, "{%s}p" % nsmap["w"]) xml = etree.tostring(wrapper, encoding="unicode", pretty_print=False) return xml.partition(">")[2].rpartition("