I'm having trouble understanding how I would populate the Quill editor with some basic HTML text using plain js.
I'm passing text with basic formatting (just bold, italic, underline and header tags) so there aren't any advanced RTF features to worry about.
So for example: My javascript might be something like
var postContent = "<h2>My short post</h2><p>This is a <strong>really, really</strong> short post.</p>";
quill.setText(postContent, "api");
I thought I'd be able to use quill.setText(postContent, "api") but that seems to display the HTML tags instead of rendering the formatted text.
Do I actually need to parse the code into a blot? Seems like there must be a way to get Quill to render that basic HTML, as it seems to work if I paste simple formatted text directly into Quill.
One thing I've tried is simply doing:
quill.root.innerHTML = postContent;
Which seems to work visibly, but I'm worried that I'm now doing something a little hacky and I might not actually be using Quill as intended. Shouldn't there be a way to accomplish this via the Quill API?
Any insight? Thanks.
There is unsafe deprecated function dangerouslyPasteHTML: https://quilljs.com/docs/modules/clipboard/#dangerouslypastehtml
It's better to use setContents or updateContents with Delata of ops with attributes: https://quilljs.com/docs/api/#updatecontents
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With