Repository navigation
Preserve content when pasting multiple HTML tables - #128
Open
cyberianin wants to merge 1 commit into
Open
cyberianin wants to merge 1 commit into
cyberianin wants to merge 1 commit into
Conversation
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.
Problem
When clipboard HTML contains two tables,
generateText()takes the source before the first<table, converts only the first parsed table, and resumes after the last</table>. This silently removes the content between the tables and the second table. The same function serves paste and drop.Fix
For HTML containing multiple, nested, or ambiguously bounded tables, use
text/plainonly when a deliberately narrow check confirms that simple paragraphs and independent tables match its Markdown blocks in order. Otherwise, preserve the original HTML source in the editor instead of attempting a potentially lossy partial conversion. Keep the existing single-table conversion path, with a guard for tag casing that its source slicing cannot handle. Let later handlers observedefaultPreventedso one handled event produces one insertion. The final skip-formatting cleanup listener still runs on the same element.Minimal reproduction
Clipboard
text/html:Clipboard
text/plain:Before this change, the result loses
Betweenand the second table. After this change, the complete Markdown is inserted once. If the plain representation is absent, incomplete, or ambiguous, the original HTML string is inserted once instead.Verification
86be75f8(middle content absent) and passes with this patch.npm test: 60 passed, 0 failed.npm run lint: passed.npm run build: passed.Scope and limitations
The fallback preserves the source HTML string in the editor; it does not prove equivalent rendering in GitHub Flavored Markdown. The report's HTML was reconstructed from its Markdown, not captured from the original clipboard. Complex headings, lists, rich cells, skipped or nested tables are deliberately left as HTML rather than partially converted. The plain-text check is conservative and is not a general HTML-to-Markdown converter.
This differs from #20, which replaced every parsed table in a DOM container and returned the container's serialized
innerHTML, including turning skipped tables into text. That change was reverted by #22 after regressions on GitHub.com. This patch does not serialize the whole clipboard DOM or convert every table; it preserves the original HTML when a complete plain-text Markdown representation cannot be established.