slab / delta

Simple and expressive JSON format for describing rich-text content and their changes
https://quilljs.com/docs/delta
BSD 3-Clause "New" or "Revised" License
914 stars 130 forks source link

How to convert html to delta format using delta module? #6

Closed sheeshmohsin closed 7 years ago

sheeshmohsin commented 7 years ago

I have seen examples of conversion of delta to html format, but no where its explained to convert html to delta format. Is there anyway to do that?

jhchen commented 7 years ago

You can use the construction APIs to create a Delta in general, but parsing, sanitizing and interpreting HTML is outside the scope of this project. You will have to use another third party library for that in conjunction with the construction APIs.

Toub commented 6 years ago

What about using Clipboard.convert ?

https://github.com/quilljs/quill/blob/master/modules/clipboard.js

aramk commented 4 years ago

This seems to work:

quill.setContents(quill.clipboard.convert(html));
sdhull commented 4 years ago

I know this is an old issue but it strikes me as an odd oversight that Quill doesn't support this in any sort of documented way and the only way to do it is essentially a hack.

What is the recommended approach from Quill designers if I want to make some rich content editable more than once but also want to make the content renderable as simple HTML (as in the editor but just for display)?

AFAICT the easiest way to support this use-case is to store the content twice: once as Delta and once as HTML. Otherwise you're left rolling your own parser to convert HTML to Delta (if you store it as HTML) or Delta to HTML (for rendering outside an editor context).

Surely I'm missing something here?

aramk commented 4 years ago

I store it as HTML and delta as well so I can render without parsing each time. I think there should be a setHtmlContents() convenience method as well though. Is this not supported because Quill is a superset of HTML and doing so may alter results, or vice versa?