Search code examples
javascriptckeditor5

How to get HTML code of selected text in ckeditor 5?


How to get HTML of the selected text in ckeditor 5?

In ckeditor 4 there is getHTML() method. What is the analog in the 5th version?


Solution

  • Using DataController#stringify and getSelectedContent as Alexandros Kyriakos suggested, it can also be done like this:

    let sHtmlSelection = this.editor.data.stringify(this.editor.model.getSelectedContent(this.editor.model.document.selection));