fix(markdown): prevent hr tokens from causing frontmatter misparse#898
Open
shaofengluo-ctrl wants to merge 1 commit intoanomalyco:mainfrom
Open
fix(markdown): prevent hr tokens from causing frontmatter misparse#898shaofengluo-ctrl wants to merge 1 commit intoanomalyco:mainfrom
shaofengluo-ctrl wants to merge 1 commit intoanomalyco:mainfrom
Conversation
When buildRenderableTokens groups consecutive non-table tokens into a single CodeRenderable block, an hr token (---) at the start of a group causes Tree-sitter's markdown parser to interpret it as YAML frontmatter (minus_metadata). Everything between two --- delimiters gets rendered as metadata instead of markdown, breaking ordered lists, headings, and other content that follows a table + hr combination. Fix: Add 'hr' to shouldRenderSeparately() so thematic breaks are rendered as independent blocks, preventing them from starting a markdown group.
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.
Summary
table + ---(thematic break) renders as monospace/unstyled text instead of formatted markdownProblem
buildRenderableTokens()groups consecutive non-table/code/blockquote tokens into a singleCodeRenderableblock. When a table is followed by---(hr), the grouped block starts with---, which Tree-sitter's markdown parser interprets as YAML frontmatter (minus_metadata). Everything between two---delimiters is then rendered as metadata instead of markdown.Reproduction: Any markdown with this pattern:
The heading may render correctly, but the ordered list and nested content render as green monospace (metadata style).
Fix
Add
"hr"toshouldRenderSeparately()so thematic breaks are rendered as independent blocks, preventing them from starting a markdown group that Tree-sitter misparses as frontmatter.private shouldRenderSeparately(token: MarkedToken): boolean { - return token.type === "code" || token.type === "table" || token.type === "blockquote" + return token.type === "code" || token.type === "table" || token.type === "blockquote" || token.type === "hr" }Impact
hrtokens now render as separateCodeRenderableblocks (Tree-sitter correctly parses standalone---asthematic_break)---, avoiding frontmatter misinterpretationgetInterBlockMarginreturns 1 forhr(since it's now inshouldRenderSeparately), adding natural spacing after horizontal rulesDiscovered in
opencode TUI (opencode-ai v1.2.25) — PRD review output with tables followed by
---separators and ordered lists.