html-to-draftjs
A library for converting plain HTML to DraftJS Editor content. Build for use with **[react-draft-wysiwyg](https://github.com/jpuri/react-draft-wysiwyg)**.
Last updated a year ago by jyotipuri .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install html-to-draftjs 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.0.1-beta                                ...           beta (3 years ago)
  • 1.4.0                                ...           latest (a year ago)

25 Versions

  • 1.4.0                                ...           a year ago
  • 1.3.1                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
  • 0.1.0-beta.16                                ...           2 years ago
  • 0.1.0-beta15                                ...           2 years ago
  • 0.1.0-beta14                                ...           2 years ago
  • 0.1.0-beta13                                ...           2 years ago
  • 0.1.0-beta11                                ...           2 years ago
  • 0.1.0-beta10                                ...           2 years ago
  • 0.1.0-beta9                                ...           2 years ago
  • 0.1.0-beta8                                ...           2 years ago
  • 0.1.0-beta7                                ...           2 years ago
  • 0.1.0-beta6                                ...           2 years ago
  • 0.1.0-beta5                                ...           2 years ago
  • 0.1.0-beta4                                ...           2 years ago
  • 0.1.0-beta3                                ...           2 years ago
  • 0.1.0-beta2                                ...           3 years ago
  • 0.0.1-beta                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 8
This Week 953
This Month 3,097
Last Day 181
Last Week 1,077
Last Month 4,127
Dependencies (0)
None
Dev Dependencies (12)
Dependents (95)

Copyright 2014 - 2016 © taobao.org |