html - 是否可以将 HTML 转换为 EditorJS json?

标签 html reactjs editorjs

我想向 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/

相关文章:

reactjs - 在 React js 中安装 Razorpay

javascript - 如何防止在 Firefox 中点击 HTML5 视频控件时出现事件冒泡

html - 为什么div不在两个div之间

javascript - 如何使用 React 测试库测试 HOC

node.js - 从docker容器的服务访问兄弟服务

javascript - 如何从 editor-js 手动渲染数据

javascript - EditorJs 警告 "«blocks.stretchBlock()» is deprecated and will be removed in the next major release. Please use the «BlockAPI» instead."

editorjs - 如何将 block 数据加载到 EditorJS 中?

javascript - 更改 jquery mobile 页面 init 上的元素

html - 如何对齐自举网格