John
John

Reputation: 11399

How to preserve new lines in CKEditor 5?

I am using Angular 2+ with CKEditor 5.

When I use the string: "foo\r\nbar", the text inside the editor is not applying the new lines. Using a CSS rule: white-space: pre-line; on the text in other elements on the page works, but not in CKEditor. How can I preserve the new lines in CKEditor 5?

Here is my component:

import * as ClassicEditor from '@ckeditor/ckeditor5-build-classic';
@Component({
      selector: 'test',
      templateUrl: './test.component.html',
      styleUrls: ['./test.component.scss']
})
export class TestComponent {
      public editor = ClassicEditor;
      testString = "foo\r\nbar";
      constructor(){}
}

Here is my html:

<ckeditor [editor]="editor" [(ngModel)]="testString"></ckeditor>

Upvotes: 0

Views: 2506

Answers (1)

MTilsted
MTilsted

Reputation: 5545

You need to replace "\r\n" with "<br />" in the string using javascript, before you give it to ckeditor.

Upvotes: 1

Related Questions