Add an API method for setting HTML content
There is no API method for setting HTML content via code. You can retrieve HTML content with getSemanticHTML() but there is not way of setting this via the API. You can set plain text with setText() but that renders all HTML tags as plain text.
As a workaround you can do the following:
quill.root.innerHTML = myHtmlContent;
But this is unpleasant and could be easily implemented in the API with a setSemanticHTML(string) method. Named as such for consistency with the get method. However you may want to add range parameters etc. which would involve a more complex implementation.
Version 2.0.0
Hi you can use quill.setContents() together with quill.clipboard.convert(). Here's an example: Playground
Many thanks @luin, that works for me, but it's not very intuitive or obvious. I think at least there should be something in the documentation to indicate how to do this, or simply implement your code in a method as I suggested.
Hi you can use
quill.setContents()together withquill.clipboard.convert(). Here's an example: Playground
Thanks for the playground, but if I insert some whitespace to the HTML code and it will lost after convert. Is it a bug?
Such as:
quill.setContents(quill.clipboard.convert({
html: '<h2> Header</h2>'
}))