Quill: Return html of selected text

Created on 21 Nov 2017  路  4Comments  路  Source: quilljs/quill

Hello, I have a question how to return selected text from editor in HTML format? getSelection method can be used for text only. I've been struggling with this for few days now. Any help would be highly appreciated.

Most helpful comment

Check this CodePen

I was sure I posted comment with the link same day you add your last comment. Sorry.

All 4 comments

Quill doesn't work with HTML, it works with own Delta format. But you can get HTML from selection easily with plain js and browser API (you can paste this snippet to your browser console to test it):

var selection = window.getSelection();
if (selection.rangeCount > 0) {
  var range = selection.getRangeAt(0);
  var documentFragment = range.cloneContents();
}
console.log(documentFragment || 'nothing selected');

@DmitrySkripkin thank you for your time. Your code doesn't seems to be doing what I was hoping for. It works for content outside of Quill but not for its content:
You can see an example I trying it on here: https://codepen.io/anon/pen/EbRVxV
result for me is below. I would expect first fragment to be surrounded in html too.
image

Check this CodePen

I was sure I posted comment with the link same day you add your last comment. Sorry.

DmitrySkripkin, thanks. The above example seems to work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kheraud picture kheraud  路  3Comments

GildedHonour picture GildedHonour  路  3Comments

scottfr picture scottfr  路  3Comments

aletorrado picture aletorrado  路  3Comments

splacentino picture splacentino  路  3Comments