Is there any library convert html to block of editorjs, or convert block to html
i want to convert html to block (json structure of editorjs )
Maybe I am wrong, but I think if you start editorjs with html as initial payload it will convert for blocks for you. Block to html you can find samples of code online.
@gabrielmoterani Thank you for your reply. I have gotten some html pages with python spider from public website. Now I want to parse them to blocks of editorjs in backend, and then save these blocks to database. I have found a way to convert blocks to html。
@qqqays Yeah, I need to convert HTML for EditorJs blocks too... What I am doing is using a nodejs lib to convert HTML to json and then iterating each item of this json, converting to blocks. But I dont think this is such a good ideia. HTML is very nested... I think Editorjs has something inside that do this conversion, since you can paste html in Editor and he will convert to Editorjs Blocks.
It would be better if EditorJs provide us that api.
If anyone knows a better way to do that, please share with us :)
@gabrielmoterani Hello, bro! How is the work of parsing html into editor.js blocks? I did this with jsdom that ran in nodejs,I created a entity of editorjs in jsdom, then share this entity in jsdom and nodejs env. The entity as a factory converting html to blocks, then return the blocks.
Well I am still struggling to make a good solution for my application. @qqqays can u share more details of your implementation? Can u share the code that converts jsdom to blocks?
I tried to use a lib that named Hymalaya that converts html to JSON, but HTML object became so nested, thats impossible to iterate over it.
Does anyone nows how Editorjs convert pasted content to blocks?
@gabrielmoterani I put the project to https://github.com/qqqays/server4parseEditorJs. You can try it ; )
How did you do it? Please show me
@proflinksgh I was able to take a clue from @qqqays's library and I used the following code block to convert an HTML string to EditorJS blocks:
const editor = new EditorJS({
...
onReady: async () => {
if (dataIsHtml) {
await editor.blocks.renderFromHTML(data);
}
},
...
});
@Alchez Hello, I came across your reply as I am facing the same issue, did you change anything else except adding above code to the editorjs instance? Where can you get the outputted html string from?Also, if possible can I have a look at the code file?
Hey @sushant-78, unfortunately the code is private on Github so I can't share it.
We were receiving an HTML string from our backend server that we wanted to output as EditorJS blocks, that was our source. By just adding that onReady function, we were able to convert the string to blocks.
Hope that helps.
@Alchez Thanks, for quick reply, didn't need to try it out, worked out a solution,needed to migrate data, so wrote patch script for it
@qqqays You are the savior. The solution works well with [email protected] but not the latest. Yet, you are the legend
<script src="https://cdn.jsdelivr.net/npm/@editorjs/[email protected]/dist/editor.min.js"></script>
hi team, is there any defined solution r=to render html to editorjs. i have tried above suggestion but i failed.
But it give [object HTMLPreElement] for pre tag, how to solve it? Thanks.