halley

samemark

The same mdast as remark-parse, up to 10x faster, with streaming for chat UIs

Area
Libraries
Language
JavaScript
License
MIT
Latest
v0.1.0
Plate
No. 14 of 14
Fig. 14samemark
Move your pointer over it

What came back

  1. 6.2x to 10.3x

    faster end to end, markdown to HTML, with identical output on every file.source

  2. 60x

    less main-thread time streaming a 30,000-character chat answer into the page.source

  3. 28x to 47x

    faster parsing alone, with the same syntax tree.source

samemark returns the same mdast tree as remark-parse with GFM, positions included, and replaces it in a unified pipeline with one import. Your remark plugins keep working, and the whole markdown to HTML run gets several times faster. A second entry, samemark/stream, parses chat answers incrementally so streaming UIs stop re-parsing the whole message on every token.

How it works

  1. 01

    A hand-written fast path parses markdown straight into the mdast node shapes micromark produces, with no micromark at parse time.

  2. 02

    Any setup it does not reproduce exactly (other micromark extensions, custom frontmatter fences) is detected and handed to mdast-util-from-markdown, so you always get micromark's answer.

  3. 03

    The stream parser re-parses only the unfinished tail of the message and reuses every finished block, so a push costs the new text, not the whole answer.

What it does

  • Same mdast as mdast-util-from-markdown with GFM, positions included, checked node by node against micromark
  • remarkParseFast is a drop-in for remark-parse in unified, Astro and react-markdown
  • remark-gfm, remark-frontmatter and remark-math are handled natively; other extensions are passed to the real parser, so the output stays correct
  • samemark/stream parses chat output incrementally and matches a full parse after every chunk, so finished blocks keep their object identity for React.memo
  • Plain JavaScript, no native binary, runs in Node 18+, browsers, Deno, Bun and edge runtimes