Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any library convert html to block of editorjs, or convert block to html #1232

Closed
qqqays opened this issue Jul 14, 2020 · 12 comments
Closed

Comments

@qqqays
Copy link
Contributor

qqqays commented Jul 14, 2020

i want to convert html to block (json structure of editorjs )

@gabrielmoterani
Copy link

gabrielmoterani commented Jul 24, 2020

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.

@qqqays
Copy link
Contributor Author

qqqays commented Jul 27, 2020

@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。

@gabrielmoterani
Copy link

@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 :)

@qqqays
Copy link
Contributor Author

qqqays commented Aug 4, 2020

@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.

@gabrielmoterani
Copy link

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?

@qqqays
Copy link
Contributor Author

qqqays commented Dec 9, 2020

@gabrielmoterani I put the project to https://github.com/qqqays/server4parseEditorJs. You can try it ; )

@qqqays qqqays closed this as completed Dec 10, 2020
@qqqays qqqays changed the title Is there any python library convert html to block of editorjs, or convert block to html Is there any library convert html to block of editorjs, or convert block to html Mar 14, 2021
@proflinksgh
Copy link

How did you do it? Please show me

@Alchez
Copy link

Alchez commented Jul 15, 2022

@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);
    }
  },
  ...
});

@sushant-78
Copy link

@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?

@Alchez
Copy link

Alchez commented Aug 4, 2022

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.

@sushant-tce
Copy link

@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

@ranjancse26
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants