Opened 10 years ago
Closed 10 years ago
#12591 closed New Feature (invalid)
Preserve whitespace in HTML nodes
Reported by: | Boris Lykah | Owned by: | |
---|---|---|---|
Priority: | Normal | Milestone: | |
Component: | Core : Parser | Version: | |
Keywords: | Cc: |
Description
If we call setData with HTML like
<p> abc def </p>
It will be transformed into the following structure after fromHtml call
<p>abc def </p>
It would be good to have an option to preserve whitespaces on a certain condition. CKEditor DTD or filter settings seem to be good candidates for keeping this option.
The whitespace trimming logics is situated in parser.onText in htmlparser/fragment.js:
if ( ( !currentNode._.hasInlineStarted || pendingBRs.length ) && !inPre && !inTextarea ) { text = CKEDITOR.tools.ltrim( text ); ... if ( !inPre && !inTextarea ) text = text.replace( /[\t\r\n ]{2,}|[\t\r\n]/g, ' ' );
There's no option for that and won't be, because CKEditor's parser must work this way. It's built for HTML editing and keeps only these spaces that matter. Otherwise, all algorithms working on DOM would have a tough job understanding what some spaces around selection, ranges, inline or block elements mean. The code would be awful to write and maintain.