百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

streaming-markdown

> 前端框架
开源

Ⓜ️⬇️ 使用 ChatGPT 进行 Markdown 流式传输 (WIP)

386 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Ⓜ️⬇️ 使用 ChatGPT 进行 Markdown 流式传输 (WIP)

Streaming Markdown

Experiment making a streaming markdown parser à la ChatGPT.


Installation

Install streaming-markdown package from npm.

bash
npm install streaming-markdown

Or just copy smd.js file to your project.

Or use the CDN link.
It's a minified (3kB Gzip) version of the package, with only the necessary functions exported.
See the exports in smd_min_entry.js.
The package uses ES module exports, so you need to use type="module" in your script tag.

xml

Usage

First create new markdown Parser by calling parser function.
It's single argument is a Renderer object, which is an interface to render the parsed markdown tokens to the DOM.
There are two built-in renderers—default_renderer and logger_renderer—that you can try at first.

javascript
import * as smd from "streaming-markdown"

const element  = document.getElementById("markdown")
const renderer = smd.default_renderer(element)
const parser   = smd.parser(renderer)

write function

Then, you can start streaming markdown to the Parser by calling parser_write function with the chunk of markdown string.

javascript
smd.parser_write(parser, "# Streaming Markdown\n\n")

You can write as many times as you want to stream the markdown.

The parser is optimistic. When it sees the start of an inline code block or code block, it will immediately style the element accordingly.

E.g. `print("hello wor should be rendered as print("hello wor

While the text is streamed in, the user should be able to select the text that has already been streamed in and copy it. (The parser is only adding new elements to the DOM, not modifying the existing ones.)

end function

Finally, you can end the stream by calling end function.

It will reset the Parser state and flush the remaining markdown.

javascript
smd.parser_end(parser)

Renderer interface

Field name Type Description
data T User data object.
Available as first param in callbacks.
add_token Renderer_Add_Token When the tokens starts.
end_token Renderer_End_Token When the token ends.
add_text Renderer_Add_Text To append text to current token.
Can be called multiple times or none.
set_attr Renderer_Set_Attr Set additional attributes of current token eg. the link url.

Markdown features

  • Paragraphs
  • Line breaks
    • don't end tokens
    • Escaping line breaks
  • Trim unnecessary spaces
  • Headers
    • Alternate syntax (not planned)
  • Code Block with indent
  • Code Block with triple backticks
    • language attr
    • with many backticks
  • `inline code` with backticks
    • with many backticks
    • trim spaces code
  • italic with single asterisks
  • Bold with double asterisks
  • italic with underscores
  • Bold with double underscores
  • Special cases:
    • boldbold>em
    • bold>embold
    • emem>bold
    • bold>emem
  • * or _ cannot be surrounded by spaces
  • Strikethrough example
  • Escape characters (e.g. * or _ with \* or \_)
  • [Link](url)
    • href attr
  • Raw URLs
    • http://example.com
    • https://example.com
    • www.example.com
    • [email protected]
    • mailto:[email protected]
  • Autolinks
    • www.example.com
    • http://example.com
    • https://example.com
    • [email protected]
    • mailto:[email protected]
  • Reference-style Links
  • Images
    • src attr
  • Horizontal rules
    • With ---
    • With ***
    • With ___
  • Unordered lists
  • Ordered lists
    • start attr
  • Task lists
  • Nested lists
  • One-line nested lists
  • Adding Elements in Lists
  • Blockquotes
  • Tables
    • Align cols right/center
    • Multiline cells
  • Subscript
  • Superscript
  • Emoji Shortcodes
  • Html tags (e.g. , , , , etc.)
    • Line breaks ,
  • LaTex tags for blocks \[...\], $$...$$ and inline \(...\) or $...$

If you think that something is missing or doesn't work, please make an issue.

Ⓜ️⬇️

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptchatbothtmljsmarkdown

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架