Skip to content

Register <label> in defaultProcessorMap to prevent spurious div injection on paste - #3416

Open
JiuqingSong with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-pasting-labels-bug
Open

Register <label> in defaultProcessorMap to prevent spurious div injection on paste#3416
JiuqingSong with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-pasting-labels-bug

Conversation

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Pasting HTML containing <label> elements caused an extra <div> to be injected inside each label, resulting in double-line rendering. The root cause: label was absent from defaultProcessorMap, so it fell through to generalProcessor ('*'), which wraps unknown elements in a ContentModelGeneralBlock — serialized back as a <div>.

Changes

  • defaultProcessors.ts — Register label: knownElementProcessor in defaultProcessorMap. This treats <label> like other inline-capable elements (span, b, em, etc.), processing its children as segments rather than wrapping them in a new block.

  • knownElementProcessorTest.ts — Add a test case verifying that a <label> with text content produces a paragraph with a text segment and no extra block wrappers.

Before the fix, pasting a <label>Test</label> would produce:

<label><div>Test</div></label>

After the fix, the label content is preserved as-is without any injected wrapper.

Add `label: knownElementProcessor` to the `defaultProcessorMap` so that
`<label>` HTML elements are treated as known elements (like `span`)
instead of falling through to the `generalProcessor`. This prevents an
extra `<div>` wrapper from being inserted inside `<label>` elements
when pasting HTML content, fixing issue #2447.
Copilot AI changed the title [WIP] Fix bug where pasting labels adds unexpected div elements Register <label> in defaultProcessorMap to prevent spurious div injection on paste Jul 27, 2026
Copilot AI requested a review from JiuqingSong July 27, 2026 18:36
@JiuqingSong
JiuqingSong marked this pull request as ready for review July 27, 2026 18:40
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://microsoft.github.io/roosterjs/pr-preview/pr-3416/

Built to branch gh-pages at 2026-07-29 18:31 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@JiuqingSong

Copy link
Copy Markdown
Collaborator

@copilot The PR has test case failure. Fix it.

Copilot AI commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot The PR has test case failure. Fix it.

Fixed in commit Fix test: label is inline, expect one implicit paragraph not two blocks. The test was wrong: <label> has display: inline by default, so knownElementProcessor treats it as an inline element — its text content is appended to the current (implicit) paragraph rather than creating a new block paragraph followed by an empty trailing one. The expected value in the test now matches that actual inline behavior.

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.

Pasting labels sometimes adds a Div element that is not present in the source of the copy

2 participants