Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve the contents of a Quill text editor

I am using the quill text editor in a javascript app and I need to retrieve the contents of the text editor as a string with the HTML included but the docs are a little sparse on this subject.

like image 938
Top-Bot Avatar asked Mar 01 '17 20:03

Top-Bot


People also ask

How do I get content from Quill editor?

Many options exist to get HTML content from Quill editor. You can try to convert Delta with a JavaScript library: Quill Delta to HTML Converter. Solutions on Stack Overflow.

How do I get the Quill editor in HTML?

I just use - $("#form"). find('#quill-editor . ql-editor'). html();


2 Answers

Depends what you want to get, here's an example showing a few ways:

http://codepen.io/k3no/pen/amwpqk

var delta = editor.getContents(); var text = editor.getText(); var justHtml = editor.root.innerHTML; preciousContent.innerHTML = JSON.stringify(delta); justTextContent.innerHTML = text; justHtmlContent.innerHTML = justHtml; 
like image 53
Keno Avatar answered Sep 18 '22 19:09

Keno


Quite simply by accessing the editor's innerHTML:

var quill = new Quill('#editor', {     theme: 'snow' }); // .... var editor_content = quill.container.innerHTML // or quill.container.firstChild.innerHTML could also work 

Hope this helps!

like image 29
nibnut Avatar answered Sep 19 '22 19:09

nibnut