Intentional is converted to a regular space on upcast when adjacent to a space, at the end of a text node, or after <br>
Provide detailed reproduction steps (if any)
- Create an editor with the default Paragraph and Essentials plugins.
- Run:
editor.setData( '<p>a b</p>' );
console.log( JSON.stringify( getModelData( editor.model, { withoutSelection: true } ) ) );
editor.setData( '<p>Lorem <br> <br>ipsum</p>' );
console.log( JSON.stringify( getModelData( editor.model, { withoutSelection: true } ) ) );- Inspect the model text, for example with
[ ...text ].map( c => c.charCodeAt( 0 ).toString( 16 ) ).
Other inputs that are affected:
┌───────────────────────────┬──────────────────────────────┐
│ Input HTML │ Text in model │
├───────────────────────────┼──────────────────────────────┤
│ <p>1 2</p> │ 1 + two \u0020 + 2 │
├───────────────────────────┼──────────────────────────────┤
│ <p>Lorem </p> │ Lorem + \u0020 │
├───────────────────────────┼──────────────────────────────┤
│ <p>x<br> y</p> │ \u0020\u0020y after the <br> │
└───────────────────────────┴──────────────────────────────┘✔️ Expected result
An in the source HTML that the author wrote deliberately ends up as \u00A0 in tsee it and treat it differently from a regular space.
❌ Actual result
The model contains no \u00A0 for these inputs. DomConverter#_processDomInlineNodes (ckmconverter.ts) assumes that any in these positions was produced by _processDataFromViewText for rendering and converts it back:
- a \u00A0 pair (space + nbsp) becomes two spaces,
- a trailing \u00A0 becomes a space when it ends the text node, follows a nbsp or spacline element or a text node starting with a space,
- a leading \u00A0 becomes a space when it follows
or an inline element, or starts the block.
The same happens for editor.data.processor.toView() and for pasted HTML. On the way out the space is rendered as nbsp again, but the number and position of nbsp characters can change. When source editing is toggled repeatedly, nbsp characters can be added or removed (see also #14680).
❓ Impact
A plugin that visualizes non-breaking spaces (TYPO3's Whitespace plugin marks every \\upan.ck-nbsp) cannot highlight these characters. They never reach the model, so editors see only some of the nbsp in their content. Source: TYPO3 #101726 (https://forge.typo3.org/issues/101726).
❓ Possible solution
Either of these would help:
- A DomConverter / HtmlDataProcessor option, or an event, to keep \u00A0 as-is on upcast (for example
preserveNbsp: true, or a hook to override the normalization). - Documenting the normalization rules and how integrators can opt out.
Related issues: #10745, #11042 (nbsp replaced by a regular space, closed as not planneund trip multiplying nbsp), #16098 (whitespace not preserved in toView).
Other details
- Browser: any (the behaviour is in the engine's DOM→view conversion)
- CKEditor version: 48.5.2
- Installed plugins: Essentials, Paragraph
Source: ckeditor/ckeditor5