Markdown Stream Parser by NLUX 🌲✨💬
A lightweight JS/TS library that can be used to parse markdown streams as they are being read or generated.
It can be useful for LLM-powered applications that need to parse markdown streams in real-time.
This package is part of the NLUX UI toolkit for AI ecosystem.
Usage
Parsing Markdown Stream
import {
MarkdownStreamParser,
MarkdownStreamParserOptions,
createMarkdownStreamParser,
} from "@nlux/markdown";
const options: MarkdownStreamParserOptions = {
};
const domElement = document.querySelector(".markdown-container");
const mdStreamParser: MarkdownStreamParser = createMarkdownStreamParser(
domElement!,
options,
);
mdStreamParser.next("## Hello World");
mdStreamParser.complete();
Parsing Markdown Snapshot
import { parseMdSnapshot } from "@nlux/markdown";
const parsedMarkdown = parseMdSnapshot(snapshot, options);
Interfaces
export type MarkdownStreamParser = {
next(value: string): void;
complete(): void;
};
export type MarkdownStreamParserOptions = {
markdownLinkTarget?: 'blank' | 'self';
syntaxHighlighter?: HighlighterExtension;
skipStreamingAnimation?: boolean;
streamingAnimationSpeed?: number;
waitTimeBeforeStreamCompletion?: number | 'never';
showCodeBlockCopyButton?: boolean;
onComplete?: () => void;
};
export type SnapshotParser = (
snapshot: string,
options?: {
syntaxHighlighter?: HighlighterExtension,
htmlSanitizer?: SanitizerExtension;
markdownLinkTarget?: 'blank' | 'self',
showCodeBlockCopyButton?: boolean;
skipStreamingAnimation?: boolean;
},
) => string;