Fix table cell trailing paragraph - #918
Open
typetetris wants to merge 2 commits into
Open
Conversation
And also not only containing another table.
Otherwise word is unhappy with the file and offers the user to repair it.
bokuweb
reviewed
Sep 5, 2026
| // INFO: We need to add empty paragraph when parent cell includes only cell. | ||
| .apply_if(self.children.is_empty(), |b| b.add_child(&Paragraph::new()))? | ||
| // INFO: To make word happy, the content of a table cell has to end in a paragraph. | ||
| .apply_if( |
Owner
There was a problem hiding this comment.
This also appends an empty paragraph when the last child is a StructuredDataTag or TableOfContents, not only when it is a nested table. Both can already contain a trailing paragraph, so the extra sibling paragraph may change cell height/spacing and round-trip output for otherwise valid cells.
Could we either limit this to TableCellContent::Table, which covers the reported Paragraph + Table repair case, or determine whether SDT/TOC effectively ends in a paragraph? Tests for cells ending in SDT and TOC would help ensure this broader change is intentional.
Contributor
Author
There was a problem hiding this comment.
Yes. I'll have to read a bit into SDT/TOCs until I understand it more. Will adapt the MR afterwards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change?
Always end a table cell contents in a paragraph.
What can I check for bug fixes?
Run test
table_cell_trailing_paragraphat 5407823 and observe that word will offer to repair the file ./docx-core/tests/output/table_cell_trailing_paragraph.docx.Run test
table_cell_trailing_paragraphat c039969 and observe that word will open the file ./docx-core/tests/output/table_cell_trailing_paragraph.docx without complaint.