draft-js-utils
draft-js-utils copied to clipboard
Img tags with "width" defined is missing the attribute when imported
I have an image tag:
<img src="https://someimage" width="100" />
the tag is converted to html correctly as above with draft-js-export-html, but when converting to draft again with draft-js-import-html, it displays just like this:
<img src="https://someimage" />
Is the width attribute not supported?
I have the same problem... You claim "converted to html correctly?" but I don't actually have that experience. Can you show me how you convert the image tag to html? Thanks!
@AieraFlyyyy I am not that sure but this is what I did to add the image to the editor state:
const entityKey = Entity.create('image', 'IMMUTABLE', { src });
const newState = AtomicBlockUtils.insertAtomicBlock(this.getEditorState(), entityKey, ' ');
And this to convert the state to HTML:
import { stateToHTML } from 'draft-js-export-html';
stateToHTML(newState.getCurrentContent())
Don't know if it is to any help...
Thanks, that's a lot help! You just give me the right direction, I think And I fixed my trouble with your method:
let a= convertFromRaw( toJS( test.ArticleContent ) ) //ContentState let c= EditorState.createWithContent(a) //EditorState let entityKey = Entity.create('image',"IMMUTABLE", { src:"" } ) let newState = AtomicBlockUtils.insertAtomicBlock( c , entityKey , "" ); let d = stateToHTML( newState.getCurrentContent( ), Option )
thanks very much !
Any update on this? I have the same issue, exporting works perfectly fine, but when I import, the width attribute seems to be ignored
Any update?