fix: handle dom tables properly when copy pasting #2206
Merged
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.
Summary
This PR addresses an issue where copying and pasting DOM tables (e.g., from web pages) into Milkdown resulted in plain text or paragraphs instead of Markdown tables. #2159
The root cause was that the
parseDOMrule fortable_header_rowin@milkdown/preset-gfmwas too strict, requiring adata-is-headerattribute. Standard HTML tables typically use<tr>elements containing<th>children for headers, without specific data attributes.Changes:
parseDOMrule fortable_header_row. This rule identifies a<tr>as a header row if it contains any<th>elements.How did you test this change?
I verified the fix by creating a local temporary reproduction test and running the full end-to-end regression suite.
I created a temporary test case to parse a standard HTML table string:
table_header_rowandtable_row.Ran the full e2e test suite to ensure no existing functionality was broken.
Command:
pnpm --filter=@milkdown/e2e testResult: All 97 tests passed.