quill icon indicating copy to clipboard operation
quill copied to clipboard

Add an API method for setting HTML content

Open ianef opened this issue 2 years ago • 6 comments

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

ianef avatar Apr 24 '24 16:04 ianef

Hi you can use quill.setContents() together with quill.clipboard.convert(). Here's an example: Playground

luin avatar Apr 28 '24 03:04 luin

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.

ianef avatar May 02 '24 12:05 ianef

Hi you can use quill.setContents() together with quill.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>'
}))

M4nk1n avatar Jun 20 '24 07:06 M4nk1n