Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Support Incremental Parsing for Streaming Markdown Input/支持流式 Markdown 输入的增量解析

未關閉
#414 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
25/100
Issue 類型
功能
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
java
領域
compilers

研究方向

首先檢視 Parser.parse(String markdown) 以及透過 canContinue() 描述的現有區塊解析器延續邏輯。定義 ParserContext 如何在追加的 chunk 之間保留尚未關閉的解析器、AST 根節點與目前位置。完成的標準是達成一致的增量 API 與行為:在不重新解析未變更輸入的情況下更新現有 AST,並透過測試涵蓋串流情境。

由索引模型根據 Issue 內容生成。

描述

enhancement
English

Background
Currently, commonmark-java parses Markdown via Parser.parse(String markdown), which always processes the entire input from scratch and rebuilds the AST.
In streaming scenarios (e.g., live Markdown preview, collaborative editing, chat messages), new content is appended continuously. Re-parsing the whole document each time is inefficient and can cause performance issues for large documents.

Request
I would like to request incremental parsing support — the ability to parse only the newly added Markdown content and update the existing AST without re-parsing unchanged parts.

Possible Approach

  • Maintain a parsing context (ParserContext) that stores:
    • Current open block parsers
    • AST root node
    • Current line number / position
  • Add a method like:
    Node parseIncremental(String newMarkdown, ParserContext context);
    
    which:
    • Resumes parsing from the saved context
    • Continues open blocks if possible (canContinue() logic)
    • Creates new blocks for new content
    • Parses inline elements only for new blocks
  • Update the AST in place, avoiding full rebuild.

Benefits

  • Significant performance improvement for streaming or real-time editing scenarios.
  • Reduced memory and CPU usage for large documents.
  • Enables more responsive applications using commonmark-java.

Example Use Case

Parser parser = Parser.builder().build();
ParserContext context = new ParserContext();

Node doc = parser.parseIncremental(initialMarkdown, context);
doc = parser.parseIncremental(newMarkdownChunk, context);

Would you consider adding this feature or providing hooks to implement it externally?


中文

背景
目前,commonmark-java 通过 Parser.parse(String markdown) 解析 Markdown,每次都会从头处理整个输入并重建 AST。
在流式场景(例如实时 Markdown 预览、协同编辑、聊天消息)中,内容会不断追加。每次都全量解析会导致性能浪费,尤其是文档较大时。

需求
希望能支持 增量解析 —— 只解析新增的 Markdown 内容,并在已有 AST 基础上更新,而不重新解析未变化的部分。

可能的实现思路

  • 维护一个解析上下文(ParserContext),保存:
    • 当前未闭合的块解析器
    • AST 根节点
    • 当前行号 / 位置
  • 增加一个方法,例如:
    Node parseIncremental(String newMarkdown, ParserContext context);
    
    该方法:
    • 从保存的上下文恢复解析状态
    • 如果可能,继续旧块(依赖 canContinue() 逻辑)
    • 为新增内容创建新块
    • 仅对新增块进行行内解析
  • 在原 AST 上直接更新,避免全量重建。

好处

  • 在流式或实时编辑场景下显著提升性能。
  • 降低大文档的内存和 CPU 消耗。
  • 让基于 commonmark-java 的应用更加流畅、响应更快。

使用示例

Parser parser = Parser.builder().build();
ParserContext context = new ParserContext();

Node doc = parser.parseIncremental(initialMarkdown, context);
doc = parser.parseIncremental(newMarkdownChunk, context);
主要語言
Java
星號
2.7k
分支
336
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

commonmark/commonmark-java 的其他 Issue

查看 commonmark/commonmark-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。