An incremental Markdown parser for streaming output.
import { MarkdownStream } from '@realloon/markflow'
const stream = new MarkdownStream()
const output = document.querySelector('#output')
for await (const delta of modelOutput) {
stream.write(delta.content)
output.innerHTML = stream.html
}
stream.end()
output.innerHTML = stream.htmlBy default, raw HTML generated by the model is escaped. If you enable allowHtml, you must ensure that the content is trusted.
Call reset() or create a new instance before starting a new message.
markflow can be combined with Aura to stream syntax-highlighted code:
import { Aura, csharp } from '@realloon/aura'
import { MarkdownStream } from '@realloon/markflow'
const aura = new Aura().register([csharp])
const stream = new MarkdownStream({ highlighter: aura })import { markdownToHtml } from 'markflow'
const html = markdownToHtml('# Hello\n\n**Fast** and safe.')interface MarkdownOptions {
breaks?: boolean // Render soft line breaks as <br>; defaults to false
gfm?: boolean // Tables, task lists, strikethrough, and bare URLs; defaults to true
allowHtml?: boolean // Pass through inline HTML; defaults to false
highlighter?: Highlighter // Optional streaming syntax highlighter
}Currently supported features include ATX and Setext headings, paragraphs, soft and hard line breaks, fenced and indented code blocks, blockquotes, nested ordered and unordered lists, task lists, tables, thematic breaks, emphasis, strikethrough, code, links, images, autolinks, and backslash escapes. Reference link definitions, footnotes, and raw HTML blocks are not currently supported.