Support Incremental Parsing for Streaming Markdown Input/支持流式 Markdown 输入的增量解析
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu bằng việc xem xét Parser.parse(String markdown) và logic tiếp tục của bộ phân tích cú pháp khối hiện có được mô tả thông qua canContinue(). Xác định cách ParserContext sẽ duy trì các bộ phân tích cú pháp đang mở, gốc AST và vị trí hiện tại qua các chunk được nối thêm. Công việc được xem là hoàn tất khi có một API tăng dần và hành vi đã được thống nhất, cập nhật AST hiện có mà không phân tích cú pháp lại phần đầu vào không thay đổi, đồng thời các kịch bản streaming được kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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:
which:Node parseIncremental(String newMarkdown, ParserContext context);- 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);
- Ngôn ngữ chính
- Java
- Star
- 2.7k
- Fork
- 336
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của commonmark/commonmark-java
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
commonmark/commonmark-java#460 ·
-
Second code span not recognised after an unclosed backtick string and another code spanCó thể đã có người làm @TanbirRamim đã nhận 12 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
commonmark/commonmark-java#458 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 74/100
commonmark/commonmark-java#457 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
commonmark/commonmark-java#443 · 4 bình luận ·
-
Option to define custom flanking/canOpen/canClose rules for delimitersCó thể làm lại được @abhiramaab đã nhận 56 ngày trước và không có pull request nào đang mở. Đang mởenhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
commonmark/commonmark-java#428 · 4 bình luận ·
Tất cả issue của commonmark/commonmark-java
Issue tương tự
-
GeminiUtil placeholder user turn ("Continue output. DO NOT look at this line ...") is flagged by prompt injection filtersCó thể đã có người làm @innoprej đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Broken links in the docsĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
salesforce/multicloudj#667 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add ZammadCó thể đã có người làm @Arslan-TR đã nhận hôm nay. Đang mởrequest
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
endoflife-date/endoflife.date#11298 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
electron tech debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày