Comments (14)
To retrieve the raw data call this:
var rawData = Draft.convertToRaw(editorState.getCurrentContent())
To create an EditorState from the raw data:
var contentState = Draft.ContentState.createFromBlockArray(Draft.convertFromRaw(rawData))
var editorState = Draft.EditorState.createWithContent(contentState)
from draft-js.
Not sure why but the only way I was able to restore state was by skipping the middle step in the above comment like so:
var rawData = Draft.convertToRaw(editorState.getCurrentContent())
var editorState = Draft.EditorState.createWithContent(Draft.convertFromRaw(rawData))
Just in case anyone else comes here and has issues when trying to use Draft.ContentState.createFromBlockArray
!
from draft-js.
Since we don't use markup or markdown to store rich content at Facebook, I haven't built any such utilities for this repo. (Since I wouldn't want to build and release something we aren't using in prod on FB.)
Feel free to create such a utility, though -- I'm sure there will be others who need it too.
If you just need to render your content statically within React, you can use the readOnly
prop on Editor
.
from draft-js.
Here is a gist that converts DraftJS raw block data to HTML:
https://gist.github.com/davisml/2b5184f64c59eb3745fd
Supports H1, H2, blockquote, ul, ol, strong, em and underline styles mapped to the rich text example. Uses a modified version of AttributedString.js (https://github.com/cohitre/attributedString.js) to format the style ranges.
from draft-js.
To retrieve the raw data call this:
var rawData = Draft.convertToRaw(editorState.getCurrentContent())
To create an EditorState from the raw data:
var contentState = Draft.convertFromRaw(rawData) // convertFromRow already returns contentState, no need to 'createFromBlockArray()'
var editorState = Draft.EditorState.createWithContent(contentState)
from draft-js.
@hellendag @cogell I'm going to start working on conversion utilities for both Markdown and HTML this evening. I'll submit a PR when they're done, in case they are useful for the project.
from draft-js.
Fabulous. Thanks so much!
from draft-js.
:)
from draft-js.
Is there a way to get rawContent
mapped to HTML with our already defined decorators
, styleMap
, blockStyleFn
, etc
from draft-js.
Thanks for your quick reply. Will do!
from draft-js.
@cogell , +1 for retrieve HTML content util
@hellendag , wondering how you handle rich content at FB :)
from draft-js.
@BRWR Thanks, I haven't had time to start anything on that utility. Happy to review and be of assistance since I'll need this moving forward on my project as well.
from draft-js.
Hello, I have also tried draft-Js-export stateToHtml function, but the function is not working in IE is there any other way to get HTML from DraftJS editor?
from draft-js.
Manohar D
from draft-js.
Related Issues (20)
- read-only font size not working
- Ctrl+A selection doesn't work in Firefox when there are action items
- Bug in demo text editor on website HOT 4
- created by DraftEditorTextNode
- state in decorator are memorised
- Add custom classes
- Ordered and unordered lists don't work
- Is/should convertToRaw be based on some kind of open standard? HOT 1
- How to insert texts via google chrome extension to an input created by DraftJS HOT 1
- Pressing return jumps to start of line in Android API 33 HOT 1
- How to change blockType by pressing keyboard
- why draftInlineStyleType only can be default type? HOT 1
- How to get the cursor position? HOT 4
- URGENT :: How to update words arrays in handleStrategy of decorator?
- how to stop the style i add in replaceText?
- pre select inline style, then input in composition mode, the selected inlinestyle not work
- when input some IME punctuation, the editor crashs
- wrong return value of getInlineStyleForCollapsedSelection and getInlineStyleForNonCollapsedSelection
- http://localhost:8000/
- InvalidStateError: 'extend' requires a Range to be added to the Selection HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from draft-js.