suneditor icon indicating copy to clipboard operation
suneditor copied to clipboard

add option to get content as JSON

Open arasrezaei opened this issue 2 years ago • 2 comments

hi, thanks for this great editor! if we can get a JSON export from editor, we can use it on other platforms that do not support html, like React Native for example. something like: editor.getJson() or similar.

arasrezaei avatar Mar 31 '23 00:03 arasrezaei

Can you show an example of the output?

JiHong88 avatar Mar 31 '23 07:03 JiHong88

Can you show an example of the output?

Sure, A really basic example: [ { "tag":"p", "attributes":[ { "style":[ { //CameCase style like React style "fontSize":10, "color":" red" } ] } ], "children":[ { "type":"text", "value":"Hello world!" }, ...rest ] } ] I think it's pretty easy and straightforward to implement. It's my be something like a virtual DOM. We can define methods like this: editor.getContents() ==> output HTML string default editor.getContents({output: "JSON"}) ==> JSON output

and for settings data: editor.setContents(data) ===> data could be JSON | String The overall process could be like this: editor -> HTML string -> JSON JSON -> HTML string -> editor

This is an example and could be tuned.

arasrezaei avatar Mar 31 '23 07:03 arasrezaei