Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read in existing data into Quill JS

I am having real trouble understanding how to work with quill...

Saving the data is not a problem as that pretty straight forward :)

I am a little stuck on two points

  1. How to edit the saved data in quill
  2. How to parse the saved data to create a static page

can anyone offer any advice how to load the delta

{"ops":[{"insert":"this is a test bit of text\n"}]}

back into the quill editor and how to parse the output to create a page?

Thanks in advance for any replies!

like image 656
Tony Avatar asked Sep 27 '16 19:09

Tony


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.

What is Delta in Quill?

Deltas are a simple, yet expressive format that can be used to describe Quill's contents and changes. The format is a strict subset of JSON, is human readable, and easily parsible by machines.

How do you use react Quill?

Learn how to use react-quill by viewing and forking example apps that make use of react-quill on CodeSandbox. Custom Toolbar with React Quill (Fully working)Quill test with a custom toolbar built with an HTML template. The toolbar includes custom font families, custom font sizes and a custom button.


1 Answers

Use setContents to insert a delta:

quill.setContents({
    "ops":[
        {"insert":"this is a test bit of text\n"}
    ]
});

http://codepen.io/anon/pen/VKWZLd

You can access the raw HTML with:

var html = document.querySelector(".ql-editor").innerHTML

If you are working with raw HTML, you need to sanitize it before you use it.

like image 199
Ben Browitt Avatar answered Oct 13 '22 14:10

Ben Browitt