Skip to content

Fix table cell trailing paragraph - #918

Open
typetetris wants to merge 2 commits into
bokuweb:mainfrom
typetetris:fix-table-cell-trailing-paragraph
Open

Fix table cell trailing paragraph#918
typetetris wants to merge 2 commits into
bokuweb:mainfrom
typetetris:fix-table-cell-trailing-paragraph

Conversation

@typetetris

Copy link
Copy Markdown
Contributor

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_paragraph at 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_paragraph at c039969 and observe that word will open the file ./docx-core/tests/output/table_cell_trailing_paragraph.docx without complaint.

And also not only containing another table.
Otherwise word is unhappy with the file and offers the user
to repair it.
// 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(

@bokuweb bokuweb Sep 5, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'll have to read a bit into SDT/TOCs until I understand it more. Will adapt the MR afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants