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.
Common errors
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'
Warnings
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.
Install
npm install streaming-markdown yarn add streaming-markdown pnpm add streaming-markdown Imports
- parser wrong
import parser from 'streaming-markdown'correctimport { parser } from 'streaming-markdown' - default_renderer wrong
const { default_renderer } = require('streaming-markdown')correctimport { default_renderer } from 'streaming-markdown' - parser_write wrong
import { write } from 'streaming-markdown'correctimport { parser_write } from 'streaming-markdown'
Quickstart
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);