惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
云风的 BLOG
云风的 BLOG
MongoDB | Blog
MongoDB | Blog
美团技术团队
H
Help Net Security
G
Google Developers Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
aimingoo的专栏
aimingoo的专栏
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
M
MIT News - Artificial intelligence
腾讯CDC
IT之家
IT之家
Vercel News
Vercel News
C
Check Point Blog
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
I
InfoQ
博客园 - 司徒正美
A
About on SuperTechFans

Hacker News: Show HN

PurrrrrFocus: Pomodoro Timer App - App Store Workflow Engine — Multi-Step Orchestration for Bun RapidPhoto: Pro Photo Editor App - App Store GitHub - DheerG/swarms: Achieve extraordinary results with claude code across a variety of tasks SPICE simulation → oscilloscope → verification with Claude Code — Lucas Gerads Show HN: VCoding – A 5 MB native Windows IDE with no dynamic dependencies Show HN: LLMs don't hallucinate because they're bad at math, it's the format GitHub - Agent-FM/agentfm-core: AgentFM is a peer-to-peer network that turns everyday computers into a decentralized AI supercomputer. AgentFM lets you run massive AI workloads directly across a global mesh of idle CPUs and GPUs. Show HN: Tracking Top US Science Olympiad Alumni over Last 25 Years GitHub - Potarix/agent-hub: One place to talk to all your agents Show HN: Runtime security for AI agents(injection,tool abuse, data exfiltration) GitHub - dubeyKartikay/lazyspotify: Terminal Spotify client for macOS and Linux GitHub - the-banana-tool/king-louie: Easy to use GUI Personal AI Assistant. Win/Linux/Mac. Show HN I made my vacation rental bookable by AI agents–no Airbnb, 0% commission GitHub - basteez/jsf-autoreload: maven plugin to enable hot reload on jsf projects uvm32/hosts/host-gdbstub at main · ringtailsoftware/uvm32 GitHub - labsai/EDDI: Config-driven engine that turns JSON into production-grade AI agents. Multi-agent orchestration, 12+ LLM providers, MCP/A2A protocols, RAG, persistent memory, and enterprise compliance (EU AI Act, GDPR, HIPAA). Built on Quarkus. GitHub - glitchnsec/fortyone-oss: AI Executive Assistant Platform Quickstart | Alien GitHub - muxshed/shed: One stream in, or many. Every destination, simultaneously. No cloud middleman, no per-channel fees, no limits. GitHub - ocrbase-hq/ocrbase: 📄 PDF/IMG ->.MD/JSON Document OCR API for PaddleOCR and GLMOCR. Self-hostable. GitHub - impactjo/home-memory: MCP server that lets your AI assistant remember everything about your home. GitHub - Sets88/dbcls: DbCls is a powerful terminal database client that supports various databases GitHub - neptun2000/heor-agent-mcp GitHub - SeanFDZ/macmind: Single-layer transformer in HyperTalk for the classic Macintosh RollQuation: Math Puzzles - Apps on Google Play GitHub - dropbox/witchcraft Show HN: Agent-cache – Multi-tier LLM/tool/session caching for Valkey and Redis GitHub - opentalon/opentalon: OpenTalon is an open-source platform built from the ground up in Go as a robust alternative to OpenClaw LinkedIn™ 职位抓取工具 - Chrome 应用商店
GitHub - nimeshnayaju/markdown-parser: A streaming-capabl...
nayajunimesh · 2026-05-15 · via Hacker News: Show HN

A markdown parser with streaming support, suitable for incrementally parsing LLM markdown streams. Parses markdown into a structured fully typed tree of nodes, following the CommonMark specification. It supports streaming/incremental parsing, so you can feed it growing input and emit only the blocks that have become finalized.

Installation

npm install markdown-parser

Usage

import { MarkdownParser } from "markdown-parser";

const parser = new MarkdownParser();

// Parse complete markdown
const nodes = parser.parse("# Hello World\nThis is a paragraph.");
// [
//   { type: "heading", level: 1, children: [{ type: "text", text: "Hello World" }] },
//   { type: "paragraph", children: [{ type: "text", text: "This is a paragraph." }] }
// ]

// Parse with streaming mode (for incremental content)
const partialNodes = parser.parse("# Hello World\nThis", { stream: true });
// Emits heading, but not the paragraph (still open)
// [
//   { type: "heading", level: 1, children: [{ type: "text", text: "Hello World" }] },
// ]

// Continue parsing as more content arrives
const moreNodes = parser.parse(" is a paragraph\n\nThis is another paragraph.", { stream: true });
// Emits the paragraph
// [
//   { type: "paragraph", children: [{ type: "text", text: "This is a paragraph." }] }
// ]

// Access all finalized blocks parsed so far
const stableNodes = parser.nodes;

// Optionally preview the currently open block while streaming
const openNode = parser.experimental_openNode;

const finalNodes = parser.parse("", { stream: false });
// Closes anything still open and emits remaining blocks
// [
//   { type: "paragraph", children: [{ type: "text", text: "This is another paragraph." }] }
// ]

When stream is false (default), the parser finalizes all open blocks at the end of the input and returns the full set of blocks (for that input). When you parse in streaming mode, the parser keeps internal state across calls and returns only blocks that have become closed and stable since the last call.

API

MarkdownParser

The main parser class that converts markdown text into a structured block AST (headings, paragraphs, lists, etc.).

parse(text: string, options?: { stream: boolean }): BlockNode[]

Parses markdown text and returns an array of block nodes.

  • text - The markdown text to parse
  • options.stream - When true, enables streaming mode which buffers incomplete blocks until they can be fully parsed. Defaults to false.

nodes: BlockNode[]

Returns all finalized top-level block nodes parsed so far. In streaming mode, this does not include the currently open block.

experimental_openNode: OpenBlockNode | null

Returns a best-effort preview of the currently open top-level block while streaming, or null when there is no open block. The open node has not finalized yet, so it may change, disappear, or be reinterpreted as more input arrives.

This property is experimental and subject to change.

Supported Nodes

The parser provides 100% support for the CommonMark specification, and includes full support for GitHub Flavored Markdown (GFM) tables.

Block nodes

  • Heading (ATX and setext style)
  • Paragraph
  • Code block (fenced and indented)
  • Thematic break (horizontal rule)
  • HTML block
  • Blockquote
  • List (ordered and unordered)
  • Link reference definitions
  • Table (GFM)

Inline nodes

  • Text
  • Code span
  • Hard break
  • Soft break
  • HTML (inline)
  • Autolink
  • Link
  • Image
  • Emphasis
  • Strong

Some notes on the implementation

The implementation is inspired by various other markdown parsers, including commonmark.js, markdown-it, and marked.js. In fact, the implementation is structurally very similar to how commonmark.js goes about parsing; the only major difference is how we decide which lines to parse when streaming is set to true. I started with a much simpler and a lot more readable implementation for the parser, but it became complex when adding block container (blockquote and lists) support, so I ended up going for a slightly complex solution but a more robust and extensible one.

Commonmark specification allows link reference definitions to appear after the links that use them. Therefore, when streaming is enabled, it is important to consider that a link reference might not resolve, since its definition could arrive in a later chunk of the input.