Open paduvi opened 7 years ago
Current fix temporarily by stripping all figure
tag. I know there would be many unknown tags, not only figure
. I think we need a more complete approach than this:
const htmlToContentState = (html = "") => {
const {contentBlocks, entityMap} = htmlToDraft(preprocessHtml(html));
return ContentState.createFromBlockArray(contentBlocks, entityMap);
}
const preprocessHtml = (html = "") => {
const $ = cheerio.load(html, {
normalizeWhitespace: true,
decodeEntities: false
});
$.root().find('*').contents().filter((i, el) => el.type === 'comment').remove();
$("figure").contents().each((i, el) => {
$(el).insertBefore($(el).parent());
});
$("script, noscript, figure").remove();
return $('body').html() || "";
}
@paduvi : plz not that this lib is made to handle only the html generated by https://github.com/jpuri/react-draft-wysiwyg. It can not handle all html tags.
I'm having trouble with
Error: Unknown DraftEntity key.
with following code:This is my html sample: