Skip to content

realloon/markflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

markflow

An incremental Markdown parser for streaming output.

Streaming rendering

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

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

Syntax highlighting

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 })

One-shot parsing

import { markdownToHtml } from 'markflow'

const html = markdownToHtml('# Hello\n\n**Fast** and safe.')

Options

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.

About

An incremental Markdown parser for streaming output.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Contributors