Phenomenon
When editing text within a code block in Chrome, line breaks may be lost or converted to <br> tags instead of being preserved as newlines. This breaks code formatting and structure.
Reproduction example
- Create a code block with multiple lines
- Edit the code (add, delete, modify lines)
- Observe line break preservation
Observed behavior
- Line breaks are lost
- Or line breaks are converted to
<br>tags - Code structure is broken
- Formatting is lost
Expected behavior
- Line breaks should be preserved
- Code structure should be maintained
- Formatting should remain intact
- Behavior should match code editors
Browser Comparison
- Chrome/Edge: Line breaks may be lost (this case)
- Firefox: Similar line break issues
- Safari: Line break preservation inconsistent
Notes and possible direction for workarounds
- Ensure
white-space: preCSS is applied - Intercept Enter key to insert newlines properly
- Preserve line breaks during editing
- Monitor and restore line breaks if lost