-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
JSON to back to html, How? #676
Comments
we need a |
Rendering an Editor.js JSON is a trivial and specific task, that depends on plugins and technologies you use. For example {
"time" : 1550476186479,
"blocks" : [
{
"type" : "paragraph",
"data" : {
"text" : "The example of text that was written in <b>one of popular</b> text editors."
}
},
{
"type" : "header",
"data" : {
"text" : "With the header of course",
"level" : 2
}
},
{
"type" : "paragraph",
"data" : {
"text" : "So what do we have?"
}
}
],
"version" : "2.8.1"
} with the simplest <p>
The example of text that was written in <b>one of popular</b> text editors.
</p>
<h2>
With the header of course
</h2>
<p>
So what do we have?
</p> We does not know a set of users plugins, so we can not provide a universal rendering tool. But the other side is a freedom of design — you can create any markup and logic you need. Some simple examples:Nodejs + Twig https://github.com/codex-team/codex.docs/blob/master/src/views/pages/page.twig#L36 PHP https://github.com/codex-team/codex/blob/master/www/application/classes/Controller/Articles/Index.php#L189 |
We thought about The problem of using this method for rendering an articles is that some of complex plugins provide an UI that different between data filling and rendering. For example, |
Excuse me, I'm super ignorant, but I installed the PHP plugin you mentioned, cause I understood it was supposed to return raw HTML out of the JSON object. But it returns another JSON that is like the . I'm not understanding how can i just print the editor content in HTML format without having that JSON Thanks! |
Sorry I haven't looked at the code but the readme said it would output the block objects but apparently not. Guess this it not the case and the true purpose was lost in translation |
No worries. |
I love this tool but also need raw HTML output. The work we do is a bit too dynamic for switch statements. Can't switch between all the html types... I mean you can, but it's cumbersome and finicky. Looking forward to the update. |
|
maybe use contenteditable=false solve problem
and simple css to hide toolbars
or |
We also had this problem. Since we use Laravel we made a plugin that works with little configuration and is extendable. |
There is a reason why many editors don't output these sort of JSONs and choose raw HTML instead. Because, to translate that JSON back to HTML, you're going to have to write a parser and that's just basically re-inventing the wheel when you could've started with HTML in the first place. For the moment, anyone seeking an alternative, look into this old, simple, well maintained project: It's the same idea, but makes no assumptions about the format (JSON/HTML). |
Hello, @wotta We're having the same issue. |
Hello @petarmitanoski, Hope this reaches you in time since I just woke up. Please see the following repository. |
@wotta The package you suggested up there is just for PHP, supposedly, is there any made editor that can be used to convert the Object JSON blocks to raw HTML? Cos I'm working on a project which has been started with EditorJS and wouldn't want to resolve to another WYSIWYG editor? Really need a reply soonest. Thanks |
@despeauxz Not really sure if I fully understand your question. The package I linked is to convert the data that we save from EditorJS to the database. So we save the data from EditorJS to our backend which is saved in the database. We don't use a custom editor. I hope this is an answer to your question. |
@wotta, Got your explanation. I'm currently not working on a PHP project, It's a Javascript/React Project. Could you suggest any package that transforms the data from the JSON block before hitting the database? |
@despeauxz Sorry I don't know a package that does that. You could make your own package if you cannot find anything. ( or even anything that fits your needs ) You know the data structure which makes it pretty easy to convert it to HTML. |
Just a rough example here how one could go about converting the JSON to HTML. |
Thanks Williams, I already got my head around it. Thanks a lot❤
…On Mon, Jul 22, 2019 at 7:08 PM William Reiske ***@***.***> wrote:
Just a rough example here how one could go about converting the JSON to
HTML.
https://jsfiddle.net/wreiske/5Le9kwcv/
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#676?email_source=notifications&email_token=AEATVS3E7DWG7KXW3CXBWB3QAXZTHA5CNFSM4HDKSBDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2QWGXA#issuecomment-513893212>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEATVS5HNQCMRQRBDW7NRK3QAXZTHANCNFSM4HDKSBDA>
.
|
This might save someone, just want to drop this |
Thanks to all 👍 |
@panpash I would make it a npm package :) |
@wotta now it's compatible with internet explorer but I have a question, |
To be honest, I am not sure. |
If you don't care about the class names, you already have the html present for you: |
@tkaravou , I don't load editorjs scripts and don't init editorjs on read-only view. |
Still no progress here? |
Here's my solution for converting the blocks to html foreach ($blocks as $block) {
// paragraph
if ($block['type'] == 'paragraph') {
$return .= '<p>'.$block['data']['text']."</p>\n";
}
// header
else if ($block['type'] == 'header') {
$return .= '<h'.$block['data']['level'].'>'.$block['data']['text'].'</h'.$block['data']['level'].">\n";
}
// list
else if ($block['type'] == 'list') {
$listtag = ($block['data']['style'] == 'ordered') ? 'ol' : 'ul';
$return .= '<'.$listtag.">\n";
foreach ($block['data']['items'] as $itemtext) {
$return .= "\t<li>".$itemtext."</li>\n";
}
$return .= '</'.$listtag.">\n";
}
} |
This is my solution for vue.js |
I created this simple utility for parsing clean data to html, after going through these issues. I would love if anyone else wanted to use it. Use it in the browser or node, or simply extend it to suit your needs. |
@pavittarx Amazing simple and great package! I'm using it in my react project! Thank you very much, definitely saved me few hours! |
thanks @dquak , I'm glad to see it have been helpful to you. <3 I hope you have starred the repo already. Also, if you do feel there is something missing, please do let me know. |
Hello @pavittarx thanks for your package ;) Can you please tell me how to use it right ? |
@osman0000 Are you sure your data is in JSON structure? |
Thanks for your reply @dquak ! |
You can go deep to the package code, it’s a very simple one and self
understanding..
From your error it seem like your blocks doesn’t have the right schema
created by the editor JS of
{blocks: [{ type:’header’, data:{} }]}
…On Sat, 16 May 2020 at 17:48 osman0000 ***@***.***> wrote:
Thanks for your reply @dquak <https://github.com/dquak> !
I tried this : let html =
edjsParser.parse(JSON.parse($httpRequest.responseText));
And I now I get this error : TypeError: transforms[block.type] is not a
function
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#676 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC43P5LDNMTA7GI6PKL5UR3RR2RVXANCNFSM4HDKSBDA>
.
|
here is the datas that I saved : |
@osman0000 If you see the docs, the supported block.types as of now are So you would simply have to do this: // define parser function for paragraph block
const paragraph = (data) => {
return `<p> ${data.text} </p>`;
}
// pass it to the parser intializer function.
const edjsParser = edjsHTML({ paragraph }); See: https://github.com/pavittarx/editorjs-html#extend-for-custom-blocks I will add more descriptive errors and paragraph support. Let me know if you still face any problems, Thanks. <3 |
Hey @pavittarx thanks for your reply ! I'll try that ;) |
I tried that :
But I get this error : |
@osman0000 I have made this working example for you to have a look: https://repl.it/@pavittarx/editorjs-browser Apologies: It should be, since only data property is being passed. let paragraph = (data)=>{
return `<p> ${data.text}</p>`
} |
Hello @pavittarx. Thanks for your reply, the way that I saved my data was wrong so I got some error but now everytging is ok ;) Everything works very fine ! Thanks a lot ! |
This one is great for React https://github.com/BomdiZane/EditorJS-React-Renderer |
this is example for vue |
Based on this here's a trait https://gist.github.com/JunaidQadirB/4df3c7daa5cb2ab40639df65e55ced80 |
I've created a package for this purpose. editorjs-parser
It also is configurable. |
For server-side rendering you should use backend technology that cleans, validates and stores Editor's data, and then it could be rendered with any templating engine. Check out implemented packages in our awesome list awesome-list. Read only mode was included in v2.19 |
I've created a simple package for Laravel framework work with JSON validation using editorjs-php Support
Thank you codex-team |
Hi there, please give me a way to save blocks to database. |
Hello , I want to change the json file dynamically, that is, the user fills in the information on the site and downloads the new json file. Can you help me? |
So cool that it outputs clean data...
Then how do I convert this clean data to html, so I can, as you say, use it it in a web page?
Thanks!
The text was updated successfully, but these errors were encountered: