[Prototype] Convert plain text/thin-wrapper paste to formatted HTML via markdown#3361
Closed
JiuqingSong wants to merge 1 commit into
Closed
[Prototype] Convert plain text/thin-wrapper paste to formatted HTML via markdown#3361JiuqingSong wants to merge 1 commit into
JiuqingSong wants to merge 1 commit into
Conversation
Convert plain text/thin-wrapper paste to formatted HTML via markdown When pasted content is plain text, or HTML that is only a thin wrapper of plain text (e.g. each line wrapped in a DIV or P with no other formatting), interpret it as markdown and replace the paste fragment with the converted formatted HTML, so we paste formatted content by default instead of raw markdown text. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> @
|
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.
@
Summary
Adds a feature to PastePlugin that detects plain-text / markdown-style paste content and converts it to formatted HTML by default.
When content is pasted with the
defaultsource (not Word/Excel/PowerPoint/OneNote/etc.) and as anormalpaste, the plugin now:clipboardData.text).rawHtmlnull/undefined/empty), or the HTML is a thin wrapper of the plain text — every element is a structural tag (DIV,P,BR,SPAN), no element carries attributes (nostyle,class, etc.), and the HTML text matches the plain text. Any real formatting element (<b>,<a>,<table>, styled spans…) disqualifies it.convertMarkdownToContentModel, turns the resulting Content Model into a DOM tree viacontentModelToDom, and replaces the contents ofBeforePasteEvent.fragmentin place — so the rest of the paste pipeline sees the formatted HTML instead of raw markdown.This makes pasting markdown text produce formatted HTML (headings, lists, links, etc.) by default instead of literal markdown.
Scope / safety
pasteType === normal, so "paste as plain text" (asPlainText) keeps raw text, andmergeFormat/asImageare untouched.Files changed
lib/paste/Markdown/convertPastedTextToMarkdown.ts(new) —shouldConvertPastedTextToMarkdown(detection) andconvertPastedTextToMarkdown(conversion + fragment replacement).lib/paste/PastePlugin.ts— added adefaultcase to the paste-source switch that runs detection/conversion.package.json— addedroosterjs-content-model-markdowndependency.test/paste/Markdown/convertPastedTextToMarkdownTest.tsplus integration tests inContentModelPastePluginTest.ts.Verification
yarn test:fast(filtered) — 29 passingyarn eslint— cleanyarn b— build succeeds (confirms the new cross-package dependency resolves)🤖 Generated with Claude Code
@