简体   繁体   English

加载时在 Quill 编辑器中插入来自 HTML 的格式化内容

[英]Insert formatted content from HTML in Quill editor on load

I want to use Quill for writing articles on my website, however I may need to edit those articles at some point.我想使用 Quill 在我的网站上撰写文章,但是我可能需要在某些时候编辑这些文章。

To retrieve my formatted content from Quill and put it into the database, I call quill.root.innerHTML , and everything goes well.为了从 Quill 检索我的格式化内容并将其放入数据库,我调用quill.root.innerHTML ,一切顺利。

However , I'm struggling to find how I could get this HTML content , and then have it displayed in my Quill editor, formatted exactly as it was when I submitted it, when the page loads .但是,我正在努力寻找如何获得此 HTML 内容,然后将其显示在我的 Quill 编辑器中,其格式与我提交时的格式完全相同,当页面加载时

Any help would be welcome, thanks in advance!欢迎任何帮助,在此先感谢!

Quill's contents are described by the JSON Delta format, and the API provides methods to getContents and setContents using this format: Quill 的内容由 JSON Delta格式描述,API 提供了使用这种格式的getContentssetContents方法:

// Retrieve JSON using the Quill API
const delta = quill.getContents()
const ops = delta.ops;
// Store the JSON representation instead of the raw HTML
storeInDB(ops);

Then you can retrieve the JSON and it should all "just work":然后你可以检索 JSON 它应该都“正常工作”:

const ops = fetchFromDB();
quill.setContents(ops);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM