Repository navigation
Paste handling: unwrap layout-only tables - #83131
Open
theaminulai wants to merge 2 commits into
Open
theaminulai wants to merge 2 commits into
theaminulai wants to merge 2 commits into
Conversation
HTML emails commonly use nested single-cell (or single-column) <table> elements purely for cross-client layout, not to convey tabular data. Pasting that content into the editor turned every one of those wrapper tables into a Table block, since the paste pipeline had no way to tell a layout table apart from a real one. Adds a tableNormaliser filter to the paste pipeline that unwraps a table when every one of its rows has exactly one cell, promoting the cells' content (each normalised into its own blocks) in its place. A table where any row has more than one cell is left untouched, since that's a real row/column relationship. The filter runs bottom-up like the rest of the paste pipeline, so nested layout tables are unwrapped one level at a time. A genuine data table nested several layout tables deep (also a common email pattern) is promoted all the way up while being left untouched itself, and still becomes a Table block.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
This branch has not been deployed
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?
Unwraps
<table>elements that are only being used for layout (every row has exactly one cell) when pasting content, so their content pastes as normal blocks instead of a Table block.Why?
Closes #4171. HTML emails commonly use nested single-cell (or single-column)
<table>elements purely for cross-client layout, since that's still the most reliable way to control layout across email clients — not to convey tabular data. Pasting that content into the editor turned every one of those wrapper tables into a Table block, exactly as described (and re-confirmed as of Gutenberg 21.1.0) in the issue, since the paste pipeline had no way to tell a layout table apart from a real one. This matches the issue's own suggested heuristic: "detect if the table only has one cell."How?
tableNormaliserfilter inpackages/blocks/src/api/raw-handling/table-normaliser.ts, added to the paste pipeline inpaste-handler.tsnext to the existingdivNormaliser(a similar "unwrap a layout-only wrapper" concern).normaliseBlocks) before being joined, so adjacent plain-text rows become separate paragraphs instead of merging into one.Testing Instructions
<table><tr><td><p>Hello</p></td></tr></table>into the editor — confirm it becomes a Paragraph block, not a Table block.npm run test:unit:vitest -- packages/blocks/src/api/raw-handling— 134/134 passing.