Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
mjml-core
Advanced tools
The mjml-core package is a framework for creating responsive email templates using a markup language called MJML (Mailjet Markup Language). It simplifies the process of designing and coding responsive emails by providing a set of high-level components that abstract away the complexities of HTML and CSS.
Basic MJML to HTML Conversion
This feature allows you to convert MJML markup into responsive HTML. The code sample demonstrates how to use the `mjml2html` function to convert a simple MJML template into HTML.
const mjml2html = require('mjml');
const mjml = `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>Hello World</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>`;
const { html, errors } = mjml2html(mjml);
console.log(html);
Custom Components
This feature allows you to create custom MJML components. The code sample demonstrates how to create and register a custom button component.
const { registerComponent, BodyComponent } = require('mjml-core');
class CustomButton extends BodyComponent {
render() {
return this.renderMJML(`
<mj-button background-color="${this.getAttribute('background-color')}" href="${this.getAttribute('href')}">
${this.getContent()}
</mj-button>
`);
}
}
registerComponent(CustomButton);
Validation
This feature provides validation for MJML templates. The code sample demonstrates how to use the `mjml2html` function with strict validation to catch any errors in the MJML markup.
const mjml2html = require('mjml');
const mjml = `
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-text>Hello World</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>`;
const { html, errors } = mjml2html(mjml, { validationLevel: 'strict' });
if (errors.length > 0) {
console.error('Validation errors:', errors);
} else {
console.log(html);
}
Handlebars is a popular templating engine that allows you to build dynamic HTML templates. Unlike MJML, which is specifically designed for responsive email templates, Handlebars is more general-purpose and can be used for a variety of web development tasks.
Pug (formerly known as Jade) is a high-performance template engine heavily influenced by Haml and implemented with JavaScript for Node.js and browsers. While Pug is not specifically designed for email templates, it offers a powerful syntax for generating HTML.
Nunjucks is a rich and powerful templating language for JavaScript. It is heavily inspired by Jinja2, the templating engine for Python. Nunjucks is not specifically tailored for email templates but offers a lot of flexibility for general HTML generation.
npm install --save mjml-core
This is the core mjml library, composed by a set of functions for both parsing, and rendering mjml
import mjml2html from 'mjml'
console.log(mjml2html(`code`))
FAQs
mjml-core
The npm package mjml-core receives a total of 553,137 weekly downloads. As such, mjml-core popularity was classified as popular.
We found that mjml-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.