Case ce-0157-code-block-formatting-allowed · Scenario scenario-code-block-editing

Formatting can be applied inside code blocks

OS: Windows 11 Device: Desktop or Laptop Any Browser: Chrome 120.0 Keyboard: US Status: draft
code pre formatting chrome

Phenomenon

When editing text within a code block in Chrome, formatting operations (bold, italic, etc.) can still be applied. This breaks the code formatting and creates invalid code structure.

Reproduction example

  1. Create a code block: <pre><code>function test() {</code></pre>
  2. Select text inside the code block
  3. Apply bold formatting (Ctrl+B)

Observed behavior

  • Formatting is applied: <pre><code>function <b>test</b>() {</code></pre>
  • Code structure is broken
  • Formatting should not be in code
  • Invalid code structure

Expected behavior

  • Formatting should be prevented in code blocks
  • Code should remain plain text
  • Structure should be preserved
  • Formatting operations should be blocked

Browser Comparison

  • All browsers: Formatting can be applied (default behavior)
  • Custom implementation needed to prevent formatting

Notes and possible direction for workarounds

  • Intercept formatting operations in code blocks
  • Prevent default behavior for formatting
  • Block format commands (bold, italic, etc.)
  • Preserve code as plain text
Before
function test() {
Code block structure
After Bold (Bug)
function test() {
Formatting applied inside code block, code structure damaged
vs
✅ Expected
function test() {
Expected: Formatting blocked inside code block, plain text maintained

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: Chrome 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.