jpuri / draftjs-to-html

Library for converting Draftjs editor content state to HTML
MIT License
321 stars 143 forks source link

CustomEntityTransform does not work properly #122

Open victors1682 opened 1 year ago

victors1682 commented 1 year ago

I've been attempting to apply a custom transformation, but I'm facing difficulties in getting it to work. We previously applied the transformation to the same element using 'draft-js' and 'draft-js-export-html'.

Testing

const draftToHtml = require("draftjs-to-html")

const data = {
    blocks: [
      {
        key: '123',
        text: 'My Heading',
        type: 'header-one',
        depth: 0,
        inlineStyleRanges: [],
        entityRanges: [],
        data: {}
      }
    ],
    entityMap: {}
  }

  const customEntityTransform = (data) => {
    return "<h1> Transformed: "+data+"</h1>"
  }

  const result = draftToHtml(data, undefined, false, customEntityTransform)

  console.log(result)