@20minutes/draft-convert
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

@20minutes/draft-convert

Node CI npm version npm downloads

Forked version:

  • with deps up to date
  • CI on GitHub Actions
  • new validateHTML function parameter for convertToHTML

For the official readme, check the official project.

validateHTML (option of convertToHTML)

validateHTML take the final HTML of the current block as parameter and must return a boolean saying if every thing is ok.

We do have some custom entity/block generation and sometimes, the produced HTML might be wrong. So we validate it using ReactDomServer, like:

import ReactDOMServer from 'react-dom/server'
import { Parser as HtmlToReactParser } from 'html-to-react'

// ...

const html = convertToHTML({
  // ...
  validateHTML: (html) => {
    try {
      const htmlToReactParser = HtmlToReactParser()

      ReactDOMServer.renderToString(htmlToReactParser.parse(html))

      return true
    } catch (e) {
      return false
  }
})(editorState.getCurrentContent());

/@20minutes/draft-convert/

    Package Sidebar

    Install

    npm i @20minutes/draft-convert

    Weekly Downloads

    71

    Version

    3.0.1

    License

    Apache-2.0

    Unpacked Size

    242 kB

    Total Files

    53

    Last publish

    Collaborators

    • webtech20minutes
    • j0k3r