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.

Template export adds a html body tag in mjml code

See original GitHub issue

Hi, im a newbie coder and im using Grapesjs in a react component. i am having troubles to export mjml and html code. When i click on export template button it add an extra <body> tag before and after mjml code. It seems to be the canvas wrapper. how can i prevent this issue?

my console log display this error: index.js:1 Uncaught Error: Malformed MJML. Check that your structure is correct and enclosed in <mjml> tags.

thats my code:

`import React, {useState, useEffect} from ‘react’; import * as grapesjs from ‘grapesjs’;

import grapesJSMJML from ‘grapesjs-mjml’

import {useParams} from ‘react-router-dom’ import { API_HOST } from ‘./api_utils’;

const Editor = () => { const [editor, setEditor] = useState(null); const pageId = useParams(); console.log(‘params editor :>>’, pageId )

useEffect(() => {
  const editor =grapesjs.init({
    id:"#editor",
    noticeOnUnload: 0,
    container:"#editor",
    avoidInlineStyle : false,
    fromElement: true,
    storageManager:{
      type: "remote",
      stepsBeforeSave: 1,
      contentTypeJson:true,
      storeComponents:true,
      storeStyles:true,
      storeHtml:true,
      storeCss: true,
      headers: {
        "Content-Type": "application/json",
      },
      id: "mycustom-",
      urlStore: `${API_HOST}/${pageId.pageId}/content`,
      urlLoad: `${API_HOST}/${pageId.pageId}/content`,
    },
    plugins: [grapesJSMJML],
    pluginsOpts:{
      grapesJSMJML:{
        resetDevices: false,
        overwriteExport: true,
        resetStyleManager:true,
        resetBlocks:true,
       
        
      },
    }
  });
 
  editor.DomComponents.clear()
  editor.addComponents('<mjml><mj-body><mj-section></mj-section></mj-body></mjml>')
  setEditor(editor);
}, []);

return ( <div id="editor"> </div> ) } export default Editor `

and that is the export template modal: image

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
mlazovlacommented, May 12, 2022

No, I have to remove body tag entirely.

It is like this:

<body>
  <mjml>
    <mj-head id="ilnn">
       <mj-raw>
       ...
  </mjml>
</body>

And it would be like this.

<mjml>
  <mj-head id="ilnn">
    <mj-raw>
     ...
</mjml>

The solution is to override wrapper component toHTML() method.

editor.getWrapper().toHTML = function(opts) {
  return this.getInnerHTML(opts);
};
0reactions
artfcommented, Oct 1, 2022

This should be fixed in the latest release.

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 >
Intro to MJML: Responsive HTML Email Coding Made Easy
Scalero lays out the tips and tricks on how to code MJML emails, including a sample email code to help get started.
Read more >
My Wonderful HTML Email Workflow - Josh W Comeau
If you've ever had the misfortune of being tasked with building a template for HTML emails, you know it's tricky business!
Read more >
Get Started with MJML: How to Code Responsive Emails
Discover a simple way to develop responsive emails. Find out how to get started with the MJML framework and code mobile-friendly campaigns.
Read more >
How to create email templates using MJML - Step-by-step guide
We will code an email template design using MJML in this blog post. ... of <head></head> tags in the HTML, same way the...
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