Opened 9 years ago

Closed 9 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:


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 = text );
if ( !inPre && !inTextarea )
  text = text.replace( /[\t\r\n ]{2,}|[\t\r\n]/g, ' ' );

Change History (1)

comment:1 Changed 9 years ago by Piotrek Koszuliński

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy