Migrating from micromark
This page covers the key differences between micromark and @lanexio/parser-grammar-markdown and shows how to rewrite common micromark patterns.
API mapping
Section titled “API mapping”| micromark | Lanexio Parser | Notes |
|---|---|---|
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 } option | GFM is enabled by default. |
micromarkExtension | Not applicable | Lanexio Parser does not support runtime grammar extensions in v1.0. |
Step-by-step migration
Section titled “Step-by-step migration”-
Install
@lanexio/parser-grammar-markdownand remove micromark.Terminal window pnpm add @lanexio/parser-grammar-markdownpnpm remove micromark micromark-extension-gfm mdast-util-from-markdown -
Replace
micromark(str)withparseMarkdown(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 HTMLimport { parseMarkdown } from '@lanexio/parser-grammar-markdown';const encoder = new TextEncoder();const tree = parseMarkdown(encoder.encode('# Hello\n\nA paragraph.')); -
Replace tree traversal.
// Lanexio Parser: use cursor for traversalimport { 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;}} -
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 defaultparseMarkdown(bytes); // GFM onparseMarkdown(bytes, { gfm: false }); // CommonMark only
Key differences
Section titled “Key differences”Output type
Section titled “Output type”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.
No runtime extensions
Section titled “No runtime extensions”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.
Input type
Section titled “Input type”micromark accepts strings. Lanexio Parser accepts Uint8Array. Use new TextEncoder().encode(str) to convert.
GFM default
Section titled “GFM default”micromark requires explicit GFM plugin registration. Lanexio Parser enables GFM by default. Pass { gfm: false } for strict CommonMark.
Heap usage
Section titled “Heap usage”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.