Skip to content
项目

关于

Ultrafast, lightweight streaming Markdown for React and AI replies

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
+1
15天
+4
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

flowdown

Ultrafast, lightweight streaming Markdown for React and AI replies
Its own parser · 0 dependencies · 40 KB gzipped · 16× faster on a long stream

CI npm Rust crate MIT licence Buy us a coffee

flowdown.localix.ai · Get started · Syntax · API · Comparison · Rust

One reply streamed twice, side by side on black, on a page and in a terminal: a heading with colored, italic, struck-through and code text, figures, a warning, numbered steps with code, tabs, a table, pros and cons, a file tree, math, details and sources, then three cards worked by the pointer on the page and by keys in the terminal. A slider moves from 12 to 24 pods and a switch turns the figures into hours a year; three boxes are ticked, a progress bar fills and a badge reads ready; a quick check is answered wrong, then right

One reply, streamed and then worked twice: by <Markdown> on a page, with the pointer, and by @localix-ai/flowdown/tui in a terminal, with keys.

flowdown draws a model's reply as it arrives: GitHub Markdown, plus the forms a model can write and a reader can scan, such as steps, tabs, headline figures, pros and cons, callouts, folded sections, sources, file trees, titled code, diagrams and math. Nothing flickers, and no raw syntax shows while the text is still coming in. It works in React, on a page with no framework, on a server and in a terminal, and a Rust crate reads the same dialect.

npm npm install @localix-ai/flowdown
pnpm pnpm add @localix-ai/flowdown
bun bun add @localix-ai/flowdown
yarn yarn add @localix-ai/flowdown
Cargo cargo add flowdown --git https://github.com/localixai/flowdown --tag rust-v0.3.0
import { Markdown } from '@localix-ai/flowdown'
import '@localix-ai/flowdown/styles.css'

export function Reply({ text, done }: { text: string; done: boolean }) {
  return <Markdown streaming={!done}>{text}</Markdown>
}

<Markdown> needs React 18 or 19. A model writes the forms once its system prompt teaches them: add answerFormatPrompt() from @localix-ai/flowdown/prompt (prompting).

Why

  • Fast. A 100k-character reply streams in 0.15 s. The next fastest renderer takes 2.4 s, and Streamdown takes 6.5 s.
  • Linear. A reply four times longer costs 2.5 times more, not sixteen, and no update takes more than 5 ms.
  • Repairs a reply mid-stream. Unfinished **bold, half-typed links and open code fences never show their raw syntax.
  • Complete. Its parser passes every example of CommonMark and of GitHub's extensions (conformance).
  • Light. One package with no dependencies, 40 KB gzipped, styled without Tailwind.
  • Safe. Raw HTML from a reply is sanitized, and links are held to safe protocols.

flowdown beside five other React Markdown renderers: time to stream six kinds of reply, download size, packages installed, and the cost of a four times longer reply

Every figure, how it was measured, and the cases where another renderer suits better are in the comparison.

A reply on a dark page explaining cross-entropy: a sum with limits, a softmax fraction, a brace under p minus y labelled prediction minus truth, arrows labelled softmax and minus log, and a Jacobian written as cases

Formulas as MathML, with a math font of its own and no dependency (math).

Generative Markdown

A reply can do more than tell: colour the words that matter, put a calculator in a card, recount a figure as the reader drags a slider, send a questionnaire back filled in. Generative Markdown is that reply written as text, tags with Markdown inside them and values in braces, drawn on a page or in a terminal, with nothing in it run as code. The two cards at the top of this page are such a reply, worked on a page and in a terminal. Its text is tags like these:

<state minutes={15} />
<card>
<slider bind="minutes" min=1 max=30 label="Running time" unit="min" />
<metric label="Cost a month" value={`€${(minutes * 0.6).toFixed(2)}`} />
</card>

@localix-ai/flowdown/widgets reads it and writes the prompt that teaches it, by the sections a page chooses; /widgets/react and /widgets/tui draw it, and hand what the reader does to the page as typed events through a policy of the page's own (Generative Markdown).

Beyond React

One package covers every target, each behind its own import path. Only the first one imports React.

Import Draws
@localix-ai/flowdown React elements
@localix-ai/flowdown/static HTML text, for a server or an email
@localix-ai/flowdown/dom a page with no framework, kept up to date in place
@localix-ai/flowdown/element <flow-down>, for Vue, Svelte, Solid or Angular
@localix-ai/flowdown/tui the rows of a terminal

Each target's options are in other targets. Further entries give you the pieces for a renderer of your own: the parser (/engine), a growing reply as blocks (/document), a remark plugin (/remark), the prompt (/prompt), code, math and diagrams (/highlight, /math, /mermaid), and questions and flash cards a reader answers (/quiz, /quiz/react). The API lists them all.

In Rust

A Rust crate with no dependencies reads the same dialect into a tree, for a terminal, a server or an agent written in Rust. It is held to the same specifications as the npm package, passes the same cases of the dialect's forms (spec/) and teaches a model with the same prompt.

[dependencies]
flowdown = { git = "https://github.com/localixai/flowdown", tag = "rust-v0.3.0" }
let doc = flowdown::parse("> [!STEPS] Cut a release\n1. **Run the checks**\n2. **Tag it**\n");

It builds its tree faster than pulldown-cmark pulls its events. Beside it, flowdown-widgets works a reply's components as the npm package does: state, expressions, {#each} and {#if}, and what a press does, with the prompt for the sections a host chooses. What it reads, how fast and how it is made: crates/flowdown and the Rust crate page of the docs.

Documentation

Everything is at flowdown.localix.ai:

Development

bun install
bun run test     # the library's tests
bun run check    # the build's exports, types and entry isolation
bun run bench    # the benchmarks, against other renderers

crates/flowdown/scripts/check   # the Rust crate: fmt, clippy, tests, docs, the wasm build
Folder What it holds
packages/flowdown The npm package.
crates/flowdown The Rust crate, with its own benchmarks.
spec/ What both parsers are held to: CommonMark's and GitHub's specifications, and the dialect's forms.
docs/ The documentation, each file a page of the site.
site/ flowdown.localix.ai.
bench/ The benchmarks every published figure comes from.

How to work on it: CONTRIBUTING.md.

Support

flowdown is free and made by a small lab without investors. If it saves you time, you can buy us a coffee.

Contributing

Start with CONTRIBUTING.md: what a change keeps, and the checks.

License

MIT

探索相关项目

加载中…