Micro MDX Parser

1.1.24 · active · verified Wed Apr 22

micro-mdx-parser is a lightweight JavaScript parser engineered to efficiently convert Markdown or HTML content into a structured JSON representation. This package is specifically designed for scenarios requiring client-side parsing and component rendering within CMS-like applications, where a full MDX toolchain might be considered excessive. It is built as a fork of the `himalaya` parser, incorporating specific 'MDX-like' adjustments to better align with modern component-based content rendering needs. Currently stable at version 1.1.24, its release cadence is typically infrequent, characteristic of a mature, specialized utility library. Key differentiators include its minimal footprint, versatile compatibility across both browser and server environments, and its focus on generating a parseable JSON AST for programmatic content manipulation, rather than direct HTML output.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import the `parse` function and use it to convert both Markdown and HTML strings into a JSON Abstract Syntax Tree (AST).

import { parse } from 'micro-mdx-parser';

const markdownContent = `# Hello MDX-like!

This is a paragraph with **bold** text and an _italic_ word.

<p>HTML can also be parsed.</p>

<MyComponent prop="value" />
`;

const htmlContent = `<div><h1>Welcome</h1><p>This is <strong>some</strong> HTML.</p></div>`;

const parsedMarkdown = parse(markdownContent);
const parsedHtml = parse(htmlContent);

console.log('Parsed Markdown AST:');
console.log(JSON.stringify(parsedMarkdown, null, 2));

console.log('\nParsed HTML AST:');
console.log(JSON.stringify(parsedHtml, null, 2));

// Example of accessing elements
if (parsedMarkdown.length > 0 && parsedMarkdown[0].type === 'element' && parsedMarkdown[0].tagName === 'h1') {
  console.log('\nFirst element in Markdown is an H1:', parsedMarkdown[0].children[0].content);
}

view raw JSON →