convertFromHTML tag <img /> problem
See original GitHub issueHi! In convertFromHTML for links i can do this:
htmlToEntity: (nodeName, node) => {
if (nodeName === 'a') {
return Entity.create(
'LINK',
'MUTABLE',
{url: node.href}
)
}
}
For images ( tag) I trying:
htmlToEntity: (nodeName, node) => {
if (nodeName === 'img') {
return Entity.create(
'IMAGE',
'MUTABLE',
{src: node.src}
)
}
}
But it doesn’t work. In draft-js editor img not showed.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7
Top Results From Across the Web
Draft JS recognize img from HTML - Stack Overflow
I'm trying to convert HTML to editorState using the native convertFromHtml . But it's not recognizing the img tag.
Read more >How to use the draft-convert.convertFromHTML function in ...
To help you get started, we've selected a few draft-convert.convertFromHTML examples, based on popular ways it is used in public projects.
Read more >Problem: Export PDF With Image - Power Platform Community
Hello guys, I have problem with convert html to pdf with image . Τhe problem is that the image cannot be modified in...
Read more >How to solve Draft.js convertFromHTML converting image ...
js convertFromHTML converting image <img> tags into 'unstyled' contentBlock type instead of 'atomic' content block type? Edit. openJavaScript ...
Read more >[Solved]-Draft JS recognize img from HTML-Reactjs
the Mikhail Khazov solution is partially correct, I had to add the img tag into the figure tag, that should solve the problem....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Images get a bit more complicated because they’re not strict decorations of text. An additional atomic block type is used to have a custom block renderer, then the entity can be used to store metadata within that block. In our internal image plugin our conversion options look something like this:
This way your HTML output looking like this:
If you need to deal with any incoming
<img>
tags that don’t have wrapping<figures>
you can add the block type by changing htmlToBlock to add the atomic block type around any tags without it:Let me know if this works @Zhurbin!
i know its too late but i’m just trying to help those who have this issue in the future. just have this issue today for showing
<img>
tag and im using ‘entityToHTML’ and its fix the problem for me.