Skip to content

Migrating from micromark

This page covers the key differences between micromark and @lanexio/parser-grammar-markdown and shows how to rewrite common micromark patterns.

micromarkLanexio ParserNotes
micromark(value: string, options?)parseMarkdown(bytes: Uint8Array, options?)Lanexio Parser accepts bytes. Use new TextEncoder().encode(str). Returns a LexTree, not an HTML string.
fromMarkdown(value, options?)parseMarkdown(bytes, options?)Returns a LexTree (flat AST), not an mdast.
mdast (object tree)LexTree (flat ArrayBuffer)No mdast. Use LexCursor for traversal.
gfm() extension{ gfm: true } optionGFM is enabled by default.
micromarkExtensionNot applicableLanexio Parser does not support runtime grammar extensions in v1.0.
  1. Install @lanexio/parser-grammar-markdown and remove micromark.

    Terminal window
    pnpm add @lanexio/parser-grammar-markdown
    pnpm remove micromark micromark-extension-gfm mdast-util-from-markdown
  2. Replace micromark(str) with parseMarkdown(encoder.encode(str)).

    // Before (micromark)
    import { micromark } from 'micromark';
    const html = micromark('# Hello\n\nA paragraph.'); // returns HTML string
    // After (Lanexio Parser) — returns a LexTree, not HTML
    import { parseMarkdown } from '@lanexio/parser-grammar-markdown';
    const encoder = new TextEncoder();
    const tree = parseMarkdown(encoder.encode('# Hello\n\nA paragraph.'));
  3. Replace tree traversal.

    // Lanexio Parser: use cursor for traversal
    import { MdKind } from '@lanexio/parser-grammar-markdown';
    const cursor = tree.cursor();
    visit: while (true) {
    if (cursor.current.kind === MdKind.AtxHeading) {
    console.log('heading at', cursor.current.range);
    }
    if (cursor.gotoFirstChild()) continue;
    while (!cursor.gotoNextSibling()) {
    if (!cursor.gotoParent()) break visit;
    }
    }
  4. Handle GFM options.

    // micromark required explicit plugin registration for GFM
    // import { gfm } from 'micromark-extension-gfm';
    // micromark(src, { extensions: [gfm()] });
    // Lanexio Parser: GFM is on by default
    parseMarkdown(bytes); // GFM on
    parseMarkdown(bytes, { gfm: false }); // CommonMark only

micromark’s default export (micromark(str)) returns an HTML string directly. Lanexio Parser’s parseMarkdown returns a LexTree (a flat AST). This is intentional: Lanexio Parser separates parsing from rendering. You traverse the tree and render to your target format.

There is no built-in Markdown-to-HTML serializer in Lanexio Parser v1.0. If you need HTML output from Markdown, parse to a LexTree and write a renderer, or use parser-cli for one-off conversions.

micromark supports runtime grammar extensions (micromark-extension-*). Lanexio Parser does not support runtime grammar extensions in v1.0. Grammar behavior is fixed at build time.

micromark accepts strings. Lanexio Parser accepts Uint8Array. Use new TextEncoder().encode(str) to convert.

micromark requires explicit GFM plugin registration. Lanexio Parser enables GFM by default. Pass { gfm: false } for strict CommonMark.

micromark builds an mdast object tree (one object per node). Lanexio Parser builds a flat ArrayBuffer — one allocation per parse, regardless of document size. Individual nodes are views into that buffer, so there is no per-node GC pressure.