The `html-to-draftjs` library provides a utility function for converting raw HTML strings into a DraftJS `ContentState` object, which is suitable for direct use within a DraftJS editor. Currently stable at version `1.5.0`, this package is primarily designed to facilitate initial content loading or pasting functionalities in applications utilizing DraftJS, especially those built with `react-draft-wysiwyg`. While there's no explicit release cadence, the presence of recent version updates and a warning about a specific faulty version (1.2.0) indicates ongoing maintenance. Its key differentiator is its focused purpose for DraftJS, offering specific handling for HTML structures and an optional `customChunkRenderer` for extending its capabilities to handle custom HTML nodes or provide specific block types beyond standard conversions, particularly useful for atomic blocks.
npm install html-to-draftjsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to convert an HTML string to DraftJS ContentState, including using the optional customChunkRenderer for specific HTML tags like `<hr/>`.
Upgrade to `html-to-draftjs@^1.3.0` or later using `npm install html-to-draftjs@latest`.
Verify that `type` values like 'HORIZONTAL_RULE' are recognized by your DraftJS configuration or component that renders the editor content.
Pre-process HTML for cleanliness or use the `customChunkRenderer` for specific, non-standard HTML patterns you need to support accurately.
For ESM, use `import htmlToDraft from 'html-to-draftjs';`. For CJS, use `const htmlToDraft = require('html-to-draftjs').default;`.Run `npm install html-to-draftjs` or `yarn add html-to-draftjs` in your project directory.
Ensure the `type` string returned by your `customChunkRenderer` matches a block type known to your DraftJS setup. Also, check that `mutability` and `data` (even if empty) are included in the returned object.