Summernote createRange with HTML
Asked Answered
W

1

6

Some text in my summernote editor contains HTML. I want to get the user selected text, exactly as it is in the editor.

All the answers I've seen so far tell me to use this

$('#summernote').summernote('createRange').toString()

But it strips all the existing HTML from the selection. This:

$('#summernote').summernote('code')

Returns all the text, with HTML, but not regarding the user selected text.

Is there a way to get the user selected text with all HTML and formatting in summernote?

Wistful answered 11/1, 2018 at 9:37 Comment(0)
M
1

Here is my solution - output in html variable.

var range = $('#summernote').summernote('createRange');
var nodes = range.nodes();
var div = document.createElement('div');
for (i=0; i<nodes.length; ++i) {
    div.appendChild(nodes[i].cloneNode(true));
}
var html = div.innerHTML;
Maddock answered 17/3, 2019 at 20:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.