Skip to content

fix(markdown): prevent hr tokens from causing frontmatter misparse#898

Open
shaofengluo-ctrl wants to merge 1 commit intoanomalyco:mainfrom
shaofengluo-ctrl:fix/hr-frontmatter-misparse
Open

fix(markdown): prevent hr tokens from causing frontmatter misparse#898
shaofengluo-ctrl wants to merge 1 commit intoanomalyco:mainfrom
shaofengluo-ctrl:fix/hr-frontmatter-misparse

Conversation

@shaofengluo-ctrl
Copy link
Copy Markdown

Summary

  • Fix markdown rendering bug where content after table + --- (thematic break) renders as monospace/unstyled text instead of formatted markdown

Problem

buildRenderableTokens() groups consecutive non-table/code/blockquote tokens into a single CodeRenderable block. 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:

| col1 | col2 |
|------|------|
| a    | b    |

---

## Heading

1. **Bold item**: description
   - nested list

The heading may render correctly, but the ordered list and nested content render as green monospace (metadata style).

Fix

Add "hr" to shouldRenderSeparately() 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

  • hr tokens now render as separate CodeRenderable blocks (Tree-sitter correctly parses standalone --- as thematic_break)
  • Subsequent content starts with headings/paragraphs instead of ---, avoiding frontmatter misinterpretation
  • getInterBlockMargin returns 1 for hr (since it's now in shouldRenderSeparately), adding natural spacing after horizontal rules

Discovered in

opencode TUI (opencode-ai v1.2.25) — PRD review output with tables followed by --- separators and ordered lists.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant