question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid Id attribute on mjml image tag

See original GitHub issue

When utilizing the asset manager to upload a new image, the asset manager attaches an id attribute to the mjml image tag. This id attribute causes an mjml validation error preventing the use of mjml strict validation in down stream applications.

Steps to reproduce:

  • Navigate to https://grapesjs.com/demo-mjml.html

  • Double click on the sciolino-paris-bw.jpg image opeing the asset manager Screen Shot 2020-04-24 at 10 17 38 AM

  • choose an image of your choice replacing the Parisian photo Screen Shot 2020-04-24 at 10 21 57 AM

  • View code via the </> icon and be alerted to a warning

Screen Shot 2020-04-24 at 10 23 31 AM

  • infringing line of code
<mj-column>
        <mj-image width="200px" src="//placehold.it/350x250/78c5d6/fff/image1.jpg" id="is2ee"/>
 </mj-column>

Open questions: I have yet to dig into the asset manager code to identify a fix. is the id a critical part of the asset manager functionality?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
ThomasPofcommented, Feb 18, 2021

Dirty fix : add regex to all editor.getHtml() function like that

editor.getHtml().replaceAll(new RegExp(/ id="([^"]+)"/g),'')

it will remove all ids. Not clean, but works!

0reactions
vinhnxvcommented, Sep 11, 2021

Dirty fix : add regex to all editor.getHtml() function like that

editor.getHtml().replaceAll(new RegExp(/ id="([^"]+)"/g),'')

it will remove all ids. Not clean, but works!

Thank you so much! I have reprocessed it:

editor.on('component:update:src', component => {
                    if (component.is('mj-image')) {
                        let code = editor.getHtml();
                        let componentId = component.getId()
                        let replace = ` id="${componentId}"`;
                        let re = new RegExp(replace, 'g');
                        code = code.replaceAll(re, '')
                        editor.setComponents(code);
                    }

                    return component;
                });

I try to use component.removeAttributes('id') or

const attr = component.getAttributes();
delete attr.id;
component.setAttributes(attr);

but still can not remove component ID.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mjml-guides – Documentation for MJML - The Responsive ...
This tag allows you to add custom attributes on any html tag of the generated html, using css selectors. It's not needed for...
Read more >
HTML image not showing in Gmail - Stack Overflow
I noticed that Google was stripping the src attribute from my img tags. I tried every answer on this page - with no...
Read more >
Template Management - Mailjet Help Center
Use MJML Code – MJML is Mailjet's markup language designed to reduce the pain of coding responsive emails. Import existing MJML templates ...
Read more >
As a side note, I'm amazed that it's 2021 and there's no good ...
If you just want text and images, you don't need CSS. Just the <img> tag - and even there you'll run into differences...
Read more >
mjml-image - npm
attribute unit default value align position center alt string n/a border string none
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found