A lightweight, efficient markdown-to-HTML converter that supports incremental parsing. Instead of processing the entire markdown document at once, this package allows you to stream chunks of markdown text and converts them to HTML on-the-fly.
npm install streaming-md-to-htmlA lightweight, efficient markdown-to-HTML converter that supports incremental parsing. Instead of processing the entire markdown document at once, this package allows you to stream chunks of markdown text and converts them to HTML on-the-fly.
> This package is very early and a work in progress. Currently it provides low-level primitives for rendering markdown that is streamed in. It is not fully spec-compliant yet.
- 🚀 Incremental parsing - process markdown chunks as they arrive
- 🌐 Environment agnostic - works in Node.js, browsers, and other JavaScript environments
- 🎯 Efficient - only processes new content without re-parsing previous content
- 📝 Supports common markdown syntax:
- Headings (H1-H6)
- Paragraphs
- Code blocks with language support
- Bold text
- Italic text
- Safe HTML character handling
``bash`
npm install streaming-md-to-html
`typescript
import { MdToHtml } from 'streaming-md-to-html';
// Initialize the converter
const converter = new MdToHtml();
// Add markdown content incrementally
const result1 = converter.append('# Hello\n');
const result2 = converter.append('This is a bold statement.\n');
const result3 = converter.append('`javascript\nconsole.log("Hello!");\n`');
// Each append() call returns information about updated lines
// You can use this to efficiently update your UI
console.log(result1.lastLineUpdated); // Info about the heading
console.log(result2.lastLineUpdated); // Info about the paragraph
console.log(result3.newLines); // Info about the new code block
// Get the complete HTML at any point
const html = converter.getHtml(converter.lines);
``
The converter maintains an internal tree structure of markdown nodes. As new content is streamed in:
1. Each chunk is processed character by character
2. Special markdown syntax is detected and converted to the appropriate HTML structure
3. The converter returns information about which lines were updated or added
4. You can access the HTML output at any time without reprocessing the entire document
This makes it ideal for:
- Real-time markdown previews
- Streaming large markdown documents
- Live editing applications
- Any scenario where incremental updates are beneficial
- Framewrk agnostic
MIT