3

I want to show HTML string to editorJS. Any idea for that?

from <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>

to something like this:

    "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"
}```

1 Answers1

0

You can use the same editorsjs that you are using to create this JSON object block. EditorJs library has a function - renderFromHtml() that converts your HTML block back into JSON object 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))
})
rahul mehra
  • 418
  • 2
  • 13