Skip to content

Preserve target formatting when pasting Markdown - #3443

Merged
Julia Roldi (juliaroldi) merged 8 commits into
masterfrom
u/juliaroldi/markdown-paste-font
Aug 21, 2026
Merged

Preserve target formatting when pasting Markdown#3443
Julia Roldi (juliaroldi) merged 8 commits into
masterfrom
u/juliaroldi/markdown-paste-font

Conversation

@juliaroldi

Copy link
Copy Markdown
Contributor

Summary

Update MarkdownPastePlugin to merge converted Markdown with preferTarget, preserving the destination font family, size, and color while still applying Markdown formatting such as heading boldness. Add a regression test covering Markdown pasted into preformatted content.

How to test

  1. Run yarn test:fast --testPathPattern=MarkdownPastePluginTest.
  2. Paste a Markdown heading into content with a custom font family, font size, and text color. Confirm the pasted heading retains those destination styles and applies the expected bold heading format.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@juliaroldi
Julia Roldi (juliaroldi) marked this pull request as ready for review August 20, 2026 16:18
@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-08-21 16:55 UTC

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates Markdown paste conversion to preserve destination formatting while retaining heading styles, with regression coverage for styled content.

Changes:

  • Uses preferTarget during auto-conversion.
  • Adds tests for preserving font family, size, color, and heading boldness.
  • The asMarkdown path still requires target-preferred merging. Moderate, 2 votes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Summary
packages/roosterjs-content-model-markdown/test/plugins/MarkdownPastePluginTest.ts Adds regression coverage for styled Markdown headings.
packages/roosterjs-content-model-markdown/lib/plugins/MarkdownPastePlugin.ts Preserves target formatting during auto-conversion; the explicit asMarkdown path still replaces custom font sizes with heading sizing.
Suppressed comments (1)

packages/roosterjs-content-model-markdown/lib/plugins/MarkdownPastePlugin.ts:98

  • preferTarget overrides every segment-format key, not just font family/size/color. A target marker can carry explicit italic: false (the DOM italic handler records normal styles this way) or a non-default fontWeight, so Markdown emphasis/heading boldness is then overwritten and disappears. Use keepSourceEmphasisFormat, or merge only the destination's non-semantic font properties while retaining source emphasis.
                        mergeFormat: 'preferTarget',

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

}),
undefined /*context*/,
{
mergeFormat: 'preferTarget',
@juliaroldi
Julia Roldi (juliaroldi) merged commit ca88324 into master Aug 21, 2026
8 checks passed
@juliaroldi
Julia Roldi (juliaroldi) deleted the u/juliaroldi/markdown-paste-font branch August 21, 2026 16:54
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.

3 participants