Repository navigation
fix: treat only spaces and tabs as blank when picking the streaming parser's stable boundary - #235
Merged
Peter Gromov (donnerpeter) merged 1 commit intoOct 7, 2026
Conversation
…arser's stable boundary The block parser treats a line as blank only when it holds nothing but spaces and tabs, while the streaming parser looked for the last blank line with `isWhitespace()`, which also accepts `\r`, a non-breaking space and other whitespace. With CRLF line endings `\r\n\r\n` is no blank line to the block parser, so a full parse gives one paragraph, but once a chunk ends right after it the streaming parser settles a boundary there and the text after it starts a second paragraph. The streamed tree then depends on how the text was chunked. Use the block parser's definition of a blank line.
Peter Gromov (donnerpeter)
approved these changes
Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The block parser treats a line as blank only when it holds nothing but spaces and tabs (
MarkdownParserUtil.isEmptyOrSpaces), butlastBlankLineEndOrNull, which picks the streaming parser's stable boundary, testsisWhitespace(), which also accepts\r, a non-breaking space and other whitespace. With CRLF line endings,line one\r\nline two\r\n\r\nnext\r\nis a single paragraph to a full parse, since\r\n\r\nis not a blank line to the block parser. Streamed one character at a time, the boundary settles after\r\n\r\nandnextbecomes a second paragraph, so the streamed tree depends on how the text was chunked. A line holding only a non-breaking space does the same with LF line endings.Approach
Use the block parser's definition of a blank line in
lastBlankLineEndOrNull. The range also drops the two\nendpoints, which were only there becauseisWhitespace()accepts them.With CRLF line endings the boundary now never settles on a blank line, so the whole document stays in the unstable tail and is reparsed on every append, as it would be for a document without blank lines. That is consistent with what a full parse produces; recognizing
\r\nas a line ending in the block parser would restore incremental parsing but is a much larger change.Tests
A CRLF document and an LF document with a line holding only a non-breaking space, each streamed one character at a time, produce the same top-level children as a full parse. Each input fails on its own without the fix.