Issue #4249Opened April 8, 2022by iamqinglong0 reactions

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

  1. Drag an image block to canvas
  2. Select an image from the custom modal
  3. View the code
  4. 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)

m-jojo-sApril 8, 20220 reactions

either use selected.set('src', doc.url) or enable unsafe html attributes

Refer to #4148

artfApril 8, 20220 reactions

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.