Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Perisisting / Displaying Draft.js content #62

Closed
dburrows opened this issue Feb 24, 2016 · 5 comments
Closed

Perisisting / Displaying Draft.js content #62

dburrows opened this issue Feb 24, 2016 · 5 comments

Comments

@dburrows
Copy link

Great project, exactly what I'm looking for, after playing around I understand how to get a raw js representation of the content from the editorState

convertToRaw(editorState.getCurrentContent())

Is this Raw state what your are persisting to a DB?

Coupled with that - how are you handling display of the content? Are there any utilities to convert this to a viewable format e.g. HTML? It's fine if the answer is 'you need to write your own parsers for the raw format' but would be good to have some pointers to how best to parse Draft.js raw into other formats?

I guess you must be doing something kind of conversion at FB, but maybe that's a wrong assumption, any guidance would be much appreciated.

@hellendag
Copy link

We store Notes as a structure similar to the raw output provided by convertToRaw, and content like comments as annotated plaintext. We can then convert to static output on www via XHP, or on apps through native means.

You can also use the Editor component for static rendering, via the readOnly prop.

I didn't want to release any conversion utilities we weren't using in production on Facebook, so that's why I haven't included any in the repo. I also didn't want to be prescriptive about the HTML or markdown flavors people might want to use. So yes, you'll need to write your own -- my assumption has been that someone would build these utilities soon after launch. :)

@dburrows
Copy link
Author

Great, thanks for the info ;)

@florentferry
Copy link

A little experimental and just for an simple project need, but feel free to instigate or fork if you need to store HTML in database.

DraftHTMLRenderer

@dburrows
Copy link
Author

Thanks @florentferry , I've also knocked up up a demo of HTML in/HTML out editing here based on the Rich example:

https://github.com/dburrows/draft-js-BasicHtmlEditor

In: Uses DraftPasteProcesser to parse HTML into a 'BlockArray'
Out: Uses a basic parser that converts the Draft raw format into html.

@rgbkrk
Copy link
Contributor

rgbkrk commented Feb 26, 2016

If anyone comes along with an export to commonmark example, I'd be happy to see that. 😄

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

No branches or pull requests

4 participants