1.5.0 • Published 5 years ago
html-to-draftjs v1.5.0
HTML To DraftJS
A library for converting plain HTML to DraftJS Editor content. Build for use with react-draft-wysiwyg.
Installation
npm install html-to-draftjs --save
Usage
import { EditorState, ContentState } from 'draft-js';
import htmlToDraft from 'html-to-draftjs';
const blocksFromHtml = htmlToDraft(this.props.content);
const { contentBlocks, entityMap } = blocksFromHtml;
const contentState = ContentState.createFromBlockArray(contentBlocks, entityMap);
const editorState = EditorState.createWithContent(contentState);
(optional) customChunkRenderer
Use to define additional html nodes. Only supports atomic blocks.
- nodeName: string - the name of the node, in lowercase
- node: HTMLElement - the parsed node itself
This renderer function is executed before any other html to draft conversion. Return nothing (or something falsy) to continue with the normal translation.
Example:
htmlToDraft('<hr/>', (nodeName, node) => {
if (nodeName === 'hr') {
return {
type: 'HORIZONTAL_RULE',
mutability: 'MUTABLE',
data: {}
};
}
})
Take Care: Plz not use version 1.2.0
it has build issues.
1.5.0
5 years ago
1.4.0
7 years ago
1.3.1
7 years ago
1.3.0
7 years ago
1.2.0
7 years ago
1.1.2
7 years ago
1.1.1
7 years ago
1.1.0
7 years ago
1.0.1
8 years ago
1.0.0
8 years ago
0.1.0-beta.16
8 years ago
0.1.0-beta15
8 years ago
0.1.0-beta14
8 years ago
0.1.0-beta13
8 years ago
0.1.0-beta11
8 years ago
0.1.0-beta10
8 years ago
0.1.0-beta9
8 years ago
0.1.0-beta8
8 years ago
0.1.0-beta7
8 years ago
0.1.0-beta6
8 years ago
0.1.0-beta5
8 years ago
0.1.0-beta4
8 years ago
0.1.0-beta3
8 years ago
0.1.0-beta2
8 years ago
0.0.1-beta
8 years ago
0.0.1
8 years ago