1.5.0 • Published 6 years ago

html-to-draftjs v1.5.0

Weekly downloads
160,399
License
MIT
Repository
github
Last release
6 years ago

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.

nawadata-web-testing@cepres/uikitagent-interfacejl-react-formspcx-react-controlsscm-uioneview-gui@kichiyaki/react-draft-wysiwygjpms-ui-kitcaec-admin-webtxstate-reactquickbuilderpc_esignatureuicognitiveleap-corecognitiveleap-core-usarms_v2.8_webui@infinitebrahmanuniverse/nolb-html-tsupport-worksuiterect-components-007@everything-registry/sub-chunk-1868react-components-007ui-food2cdogma-gantt-uidraft-editor-merchxtcfw-showcase-edittenders-portalteachable-marketingweb-ui-depsvuexy-react-admin-dashboardwordpress-rest-adminwso2_apim_publisherws-react-draft-wysiwygres-build-cb-pkgfinalres-build-cb-pkgfinal-freshchatres-build-cb-pkgfinal-olarkresumebuild-pkg3resumebuild-pkg4resumebuild-pkg5resumebuild-pkg6resumebuild-pkg7resumebuild-pkg8storybook-v2-testtest-wsyiwygtest_hamar_01test_ui_kittestmodule-carlosyangth-react-formbuilderji-wysiwyg-editorjl-react-forms-fixlawgile-shared-react-componentslay-editorl-min-componentsidentity-admin-uiims-ui-kitinmobu-uigoodera-infinity-gemsgoodera-infinity-gems-testhd-centralizedhm-richtext-editorhake-drafthama0testh01_testioc-liturgical-reaction81lib-react-draft-wysiwyglele22mani-custom-react-formsmaterial-ui-form-fieldsluxe-web-frameworkkody-react-draft-wysiwyg@wiggot/c3-ui@therms/atalaya@thinkeloquent/rd2020-designer-app-bookmarklet@ubidy_devs/ubidy-ui-kit-unstable@ubidy_devs/ubidy_ui_kit@themeetinghouse/tmh-render-router@uynguyen505/react-draft-wysiwyg@xcodebuild/react-draft-wysiwyg@stcrash/react-draft-wysiwyg@tellescope/react-componentsaldehydeagolo-clipboard-output-configata-wysiwyg-editoranttplb1reactantd-admin@cloudbusiness/mailbuilder@cjfed/cjfec@golpasal/editor@hankliu/hankliu-ui@griddo/ax@guozg/react-comments-section@actonate/mirkwood-rx@ajoelp/react-html-wysiwyg@hassenkarnit/react-draft-wysiwygreact-cssd900showcase-editsourcenet_schoolstagelightsp-react-draft-wysiwyg
1.5.0

6 years ago

1.4.0

7 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 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

9 years ago

0.1.0-beta6

9 years ago

0.1.0-beta5

9 years ago

0.1.0-beta4

9 years ago

0.1.0-beta3

9 years ago

0.1.0-beta2

9 years ago

0.0.1-beta

9 years ago

0.0.1

9 years ago