我想向 editorJS 显示 HTML 字符串。有什么想法吗?
来自
<h1>The video src attribute</h1><video width="320" height="240" controls src="movie.ogg">Yourbrowser does not support the video tag.</video><p><b>Note:</b> The .ogg fileformat is not supported in old IE and Safari.</p>
像这样:
"time" : 1616822242088,
"blocks" : [
{
"type" : "image",
"data" : {
"file" : {
"url" : "https://codex.so/public/app/img/external/codex2x.png"
},
"caption" : "",
"withBorder" : false,
"stretched" : false,
"withBackground" : false
}
}
],
"version" : "2.19.3"
}```
最佳答案
您可以使用与创建此 JSON 对象 block 相同的 editorsjs。
EditorJs 库有一个函数 - renderFromHtml()
可以将您的 HTML block 转换回 JSON 对象 block 。
editor = new EditorJS({
autofocus: true,
tools: <editorjs_tools>,
data: HTML
});
editor.blocks.renderFromHTML(req.body.html);
window.editor.save().then(data => {
console.log(data); // json block data as expected
res.end(JSON.stringify(data))
})
关于html - 是否可以将 HTML 转换为 EditorJS json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66828244/