Case ce-0136-code-block-paste-formats · Scenario scenario-code-block-editing

Pasting formatted content into code block loses code structure

OS: Windows 11 Device: Desktop or Laptop Any Browser: Firefox 120.0 Keyboard: US Status: draft
code pre paste formatting firefox

Phenomenon

When pasting formatted content (with HTML formatting) into a code block in Firefox, the formatting is preserved but the code block structure may be lost. The code block may be converted to regular paragraphs.

Reproduction example

  1. Create a code block: <pre><code>function test() {</code></pre>
  2. Paste formatted HTML content into it
  3. Observe the DOM structure

Observed behavior

  • Code block structure is lost
  • <pre><code> may be converted to <p> elements
  • Formatting is preserved but code context is lost
  • Code block is broken

Expected behavior

  • Code block structure should be maintained
  • Formatting should be stripped (code should be plain text)
  • Code block should remain as <pre><code>
  • Structure should be preserved

Browser Comparison

  • Chrome/Edge: May preserve or break structure
  • Firefox: More likely to break structure (this case)
  • Safari: Most likely to break structure

Notes and possible direction for workarounds

  • Intercept paste in code blocks
  • Strip all formatting from pasted content
  • Preserve code block structure
  • Convert HTML to plain text
Before
function test() {
Code block structure
❌ After Paste (Bug)

Bold Code

Code block structure lost, &lt;pre&gt;&lt;code&gt; converted to &lt;p&gt;
vs
✅ Expected
Bold Code
Expected: Code block structure maintained, formatting removed (plain text)

Browser compatibility matrix

This matrix shows which browser and OS combinations have documented cases for this scenario. The current case is highlighted. Click on a cell to view other cases.

Current case
Confirmed
Draft
No case documented

All variants (detailed table)

Complete list of all cases for this scenario with full environment details.

Case OS Device Browser Keyboard Status
ce-0108-code-block-whitespace-chrome Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0136-code-block-paste-formats Windows 11 Desktop or Laptop Any Firefox 120.0 US draft
ce-0147-code-block-line-breaks-lost Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0157-code-block-formatting-allowed Windows 11 Desktop or Laptop Any Chrome 120.0 US draft

Playground for this case

Use the reported environment as a reference and record what happens in your environment while interacting with the editable area.

Reported environment
OS: Windows 11
Device: Desktop or Laptop Any
Browser: Firefox 120.0
Keyboard: US
Your environment
Sample HTML:
Event log
Use this log together with the case description when filing or updating an issue.
0 events
Interact with the editable area to see events here.

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.