BUG: image src won't change in exported HTML
Question
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
chrome 100
Reproducible demo link
https://grapesjs.com/demo.html
Describe the bug
How to reproduce the bug? 0. I am using external
- Drag an image block to canvas
- Select an image from the custom modal
- View the code
- Check the model/target object attributes
What is the expected behavior?
The src attribute of the exported code should contain the actual url <img src="actual-url" />
What is the current behavior? I am using an external module for custom asset manager.
The model/target src attribute should contain the actual url
<img width="682" alt="Screen Shot 2022-04-08 at 2 26 08 PM" src="https://user-images.githubusercontent.com/48402616/162377084-c1eff1fe-3084-468e-8f27-ea287dda62f6.png">
but the exported html has the placeholder base64 as src attribute
<img width="616" alt="Screen Shot 2022-04-08 at 2 35 55 PM" src="https://user-images.githubusercontent.com/48402616/162378381-861f5a70-0857-4fe2-a0f6-cec1d13182ab.png">
If is necessary to execute some code in order to reproduce the bug, paste it here below:
The config:
assetManager: {
custom: {
open: (props) => {
this.showAddMedia = true;
},
close: (props) => {
this.showAddMedia = false;
}
},
},
Adding the src attribute
setMedia(doc) {
const selected = this.editor.getSelected();
selected.addAttributes({ src: doc.url });
console.log(selected)
console.log(selected.toHTML())
this.editor.AssetManager.close()
},
closeMediaModal() {
this.editor.AssetManager.close()
}
Code of Conduct
- I agree to follow this project's Code of Conduct
Answers (2)
either use selected.set('src', doc.url) or enable unsafe html attributes
Refer to #4148
Yeah, I'd say you should simply switch to selected.set('src', doc.url) as already suggested.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #5268
BUG: autoplay for youtube or vimeo doesn't work
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v115 Reproducible demo link https:/...
Issue #6348
BUG: It's possible to drag and drop literally anything inside grapesjs canvas
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://grap...
Issue #5607
BUG: Cannot expand previously empty layers
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v120.0.6099.199 Reproducible demo l...
Issue #5378
BUG: Uncaught TypeError: Cannot read properties of undefined (reading 'Canvas') while dragging a component in Layer Manager Panel
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome v116.0.5845.97 Reproducible demo li...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.