streaming-markdown

raw JSON →
0.2.15 verified Sat May 09 auth: no javascript

Streaming Markdown parser for incremental rendering of markdown as it's written, targeting AI chat-style outputs. Current version 0.2.15. Actively developed with experimental features. Ships TypeScript types. Key differentiator: optimistic parsing – immediately renders partial tokens (e.g., inline code, bold) without waiting for closing markers, supporting selectable text during streaming. The library exposes a custom Renderer interface for DOM control, with built-in default renderer and logger renderer. Minimal bundle size (~3 kB gzipped). Requires Node >=20 for server-side use.

error SyntaxError: The requested module 'streaming-markdown' does not provide an export named 'default'
cause Trying to default import from an ESM-only module that only exports named exports.
fix
Use named imports: import { parser } from 'streaming-markdown'
error Error: Cannot find module 'streaming-markdown'
cause Package not installed or running in an unsupported environment (e.g., Node <20).
fix
Install with npm install streaming-markdown and ensure Node >=20.
error TypeError: smd.default_renderer is not a function
cause Importing wrong symbol or using a version prior to v0.0.15 where the function existed.
fix
Verify the correct import: import { default_renderer } from 'streaming-markdown'
gotcha Parser is experimental; markdown features may be incomplete or behave unexpectedly.
fix Check the GitHub README for supported features before relying on it in production.
breaking In v0.0.15, the attribute for code blocks changed from 'lang' to 'class'. Custom renderers relying on 'lang' will break.
fix Update custom renderers to use 'class' attribute for language.
gotcha Node >=20 required. Older versions will cause runtime errors.
fix Upgrade Node.js to version 20 or later.
gotcha The package is ESM-only; CommonJS require() will fail.
fix Use import statements or switch to ESM in your project.
npm install streaming-markdown
yarn add streaming-markdown
pnpm add streaming-markdown

Demonstrates creating a parser with default_renderer, writing markdown chunks, and ending the stream.

import * as smd from 'streaming-markdown';

const element = document.getElementById('output');
const renderer = smd.default_renderer(element);
const parser = smd.parser(renderer);

smd.parser_write(parser, "# Hello ");
smd.parser_write(parser, "World\n\n");
smd.parser_write(parser, "This is **bold** and *italic* text.");
smd.parser_end(parser);