@nlux/markdown
TypeScript icon, indicating that this package has built-in type declarations

1.0.14 • Public • Published

Markdown Stream Parser by nlux 🌲✨💬

Free And Open Source Docs nlux.ai

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 ecosystem.

Usage

import {
    MarkdownStreamParser,
    MarkdownStreamParserOptions,
    createMarkdownStreamParser,
} from "@nlux/markdown";

const options: MarkdownStreamParserOptions = {
    // skipAnimation: <true / false >,  // default: false
    // syntaxHighlighter: < Highlighter from @nlux/highlighter >
    // onComplete: () => console.log("Parsing complete"),
};

const domElement = document.querySelector(".markdown-container");
const mdStreamParser: MarkdownStreamParser = createMarkdownStreamParser(
    domElement!,
    options,
);

// On each chunk of markdown
mdStreamParser.next("## Hello World");

// When the markdown stream is complete
mdStreamParser.complete();

Interfaces

export type MarkdownStreamParser = {
    next(value: string): void;
    complete(): void;
};

export type MarkdownStreamParserOptions = {
    openLinksInNewWindow?: boolean;
    syntaxHighlighter?: HighlighterExtension;
    skipAnimation?: boolean;
    onComplete?(completeCallback: Function): void;
};

Package Sidebar

Install

npm i @nlux/markdown

Homepage

nlux.dev

Weekly Downloads

183

Version

1.0.14

License

MPL-2.0

Unpacked Size

72.1 kB

Total Files

7

Last publish

Collaborators

  • shichri