import convert from 'draftjs-to-html' ; import { RichText } from 'store/slices/story' ; const customEntityTransform = ( entity , text ) => { if ( entity . type !== 'IMAGE' || ! entity . data . src . startsWith ( 'media://' ) ) { return undefined ; } return `<img src="${ entity . data . src . replace ( 'media://' , './media/' ) }" alt="${ entity . data . alt }" style="height: ${ entity . data . height };width: ${ entity . data . width }"/>` ; } ; export default function convertToHtml ( richText ) { if ( richText && richText . contentState ) { return convert ( JSON . parse ( richText . contentState ) , undefined , undefined , customEntityTransform ) ; } }