draft-js-utils icon indicating copy to clipboard operation
draft-js-utils copied to clipboard

Img tags with "width" defined is missing the attribute when imported

Open alfredvaa opened this issue 6 years ago • 5 comments

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?

alfredvaa avatar Mar 14 '18 12:03 alfredvaa

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 avatar Mar 29 '18 08:03 AieraFlyyyy

@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...

alfredvaa avatar Mar 29 '18 19:03 alfredvaa

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 !

AieraFlyyyy avatar Mar 30 '18 01:03 AieraFlyyyy

Any update on this? I have the same issue, exporting works perfectly fine, but when I import, the width attribute seems to be ignored

KrustyC avatar Nov 15 '18 16:11 KrustyC

Any update?

thiagogsr avatar Jan 29 '19 14:01 thiagogsr