Roland
Roland

Reputation: 303

ckeditor removes new line characters from source

Using CKEditor 4.9.2 on a textarea, which already has content, separated by new lines (\r\n). When the CKEditor instance loaded, these new lines were removed like this:

New lines removed

<textarea name="message" >
row 1 text text text 
row 2 text text text text text text 
row 3 text text 
row 4 text 
row 5
</textarea>

I can't convert them to <br> tags, have to work with \r\n characters.

How can I keep the \r\n characters?

Upvotes: 1

Views: 2524

Answers (1)

Kajetan W.Li
Kajetan W.Li

Reputation: 161

You can't preserve new line character in CKEditor, it is not regular textarea. It is displaying your content by using html elements on page and it cant work like you want. Easy solution I can suggest would bo to replace all new lines with <br>.

editor.on( 'setData', function(event) { event.data.dataValue = event.data.dataValue.replace( 'your regexp', '<br>' ); } );

And then after getting editor data, just replace each <br> with new line character.

Upvotes: 2

Related Questions