Registry / serialization / mjml-parser-xml

mjml-parser-xml

JSON →
library5.0.1jsnpmunverified

mjml-parser-xml is a fundamental, internal package within the MJML ecosystem, currently at stable version 5.0.1. Its primary function is to parse MJML (Mailjet Markup Language) XML strings into an Abstract Syntax Tree (AST) or a similar structured JavaScript object representation. While this package is not typically accessed directly by end-users, who generally interact with the higher-level `mjml` package and its `mjml2html` function, it is a critical component that underpins the entire MJML conversion process. The parser translates MJML's declarative, semantic XML-like syntax into an intermediate format that the MJML engine can then process and render into robust, responsive HTML. The MJML project maintains an active and consistent development cadence, with frequent updates across its monorepo, including alpha and beta releases for major versions, ensuring ongoing compatibility with evolving email client standards and web practices.

npm install mjml-parser-xml
INSTALL
IMPORT
SIG · MJML-PARSER-XML
M
mjml-parser-xml
serializationjavascriptv5.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MJMLParser
import MJMLParser from 'mjml-parser-xml';
import { MJMLParser } from 'mjml-parser-xml';
MJMLParser is the default export of this package and should be imported without curly braces.
MJMLParser
const MJMLParser = require('mjml-parser-xml');
const { MJMLParser } = require('mjml-parser-xml');
For CommonJS environments, the default export is directly assigned. MJML v5 targets Node.js 20+, so ESM is preferred.

This quickstart demonstrates how to import the `MJMLParser` and use it to convert a raw MJML string into its corresponding Abstract Syntax Tree (AST) object, illustrating basic parsing functionality and options.

import MJMLParser from 'mjml-parser-xml'; const mjmlString = ` <mjml> <mj-body> <mj-section> <mj-column> <mj-text font-size="20px" color="#F45E43">Hello MJML World!</mj-text> </mj-column> </mj-section> </mj-body> </mjml> `; try { // Parse the MJML string into an AST (Abstract Syntax Tree) object const ast = MJMLParser(mjmlString, { // Optional configurations keepComments: false, // Do not keep comments in the parsed output filePath: './templates', // Base path for mj-include directives }); console.log('Successfully parsed MJML to AST:'); console.log(JSON.stringify(ast, null, 2)); // Example of accessing a node (simplified, actual AST structure is more complex) if (ast && ast.children && ast.children.length > 0) { const firstBodyChild = ast.children[0]; console.log('\nFirst child of mj-body:', firstBodyChild.tagName); } } catch (error) { console.error('Error parsing MJML:', error); }
Debug
Known issues
breakingThe handling of `<mj-include>` and `ignoreIncludes` has become stricter in MJML v5. This may lead to parsing errors if include paths are not correctly configured or if unauthorized file access is attempted.
fix
Review all `mj-include` paths and ensure they are relative to the `filePath` option passed to the parser or are explicitly allowed. Use `mjml.config.js` for global configuration if applicable.
affects: >=5.0.0
breakingMJML v5 has replaced legacy HTML/CSS minifiers (`html-minifier`, `js-beautify`) with `htmlnano` and `cssnano`. While `mjml-parser-xml` itself focuses on XML parsing, changes in the overall minification pipeline (driven by `mjml-core`) mean that the *final rendered HTML* will be more aggressively minified. This can affect workflows that rely on exact HTML formatting, diffing raw HTML, or parsing by regular expressions.
fix
Adjust any tools or tests that depend on precise whitespace or formatting of the generated HTML. Minification options can be configured via `.mjmlconfig.js`.
affects: >=5.0.0
breakingThe outer HTML structure has been restructured in MJML v5, with the `<body>` tag now driven by `mj-body` rather than a global skeleton. This affects the root HTML structure produced after parsing and rendering.
fix
Update any code or stylesheets that rely on the previous default `<body>` tag structure or its attributes. The `mj-body` component now controls its own `<body>` generation.
affects: >=5.0.0
gotchaThe underlying XML parser (`htmlparser2`) can misinterpret the `<` character within `mj-raw` tags as an opening HTML tag, causing the parser to break and leave subsequent MJML unparsed. This is particularly problematic in templating contexts (e.g., `var value <= 10;`).
fix
Avoid using `<` directly in `mj-raw` tags where it might be ambiguous. Consider using `&lt;` for the less-than entity or reordering comparisons (e.g., `10 >= value;`) if possible.
affects: >=4.x
deprecatedMJML v5 has removed the automatic migration helper for very old MJML syntax (v3.x/early v4.x). Users upgrading from these older versions must now manually update their MJML code to conform to modern syntax, as automatic fixes will no longer be applied.
fix
Manually review and update older MJML templates to conform to MJML v4 or v5 syntax before upgrading. Consult the MJML v4 migration guide for guidance.
affects: >=5.0.0
breakingMJML 5 officially drops support for older Node.js versions, specifically Node 16 and 18, and now targets Node 20, 22, and 24 in its CI. Running `mjml-parser-xml` in unsupported Node.js environments may lead to unexpected behavior or errors.
fix
Ensure your development and deployment environments are running Node.js version 20 or higher.
affects: >=5.0.0
Errors
Common errors & fixes
Error: Missing component for tag <unknown-tag>
The MJML input contains a tag that is not recognized as a valid MJML component.
fix
Check for typos in MJML tag names. Ensure all custom components are correctly registered and available to the parser if using a custom setup.
Error: Cannot resolve mj-include path for file: 'path/to/my-partial.mjml'
MJML v5's stricter `mj-include` handling prevents resolution of the specified file path.
fix
Verify that the `filePath` option passed to `MJMLParser` is correct and that the included file path is relative and accessible within the allowed directories. Ensure no '..' escapes outside the `filePath` are used.
ReferenceError: MJMLParser is not defined
This usually indicates a CommonJS module is trying to `require` an ESM-only package, or vice-versa, or the default export is not correctly imported.
fix
For ESM, use `import MJMLParser from 'mjml-parser-xml';`. For CommonJS, use `const MJMLParser = require('mjml-parser-xml');` and ensure your Node.js environment supports the module type being used.
Upgrade
Version history
5.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
mjml-parser-xml — npm install mjml-parser-xml · libregistry