fix(runner): parse assistant answers as a line grammar (DEV-2047) - #121
Merged
Conversation
…e chunks (DEV-2047)
Headings and bullet lists still rendered literally. The previous parser split
on blank lines and required each chunk to be entirely one thing — all heading,
or all list, or all prose. Models do not write that way:
### Features demonstrated
- **Dropdown menus** (`dropdownMenu: true`) — per-column header menus
- **Filters** (`filters: true`) — filter rows by column values
No blank line anywhere, so the whole chunk fell through to "paragraph" and the
reader saw ### and - as text. Markdown is a line grammar; the parser now walks
lines and groups runs of the same kind, which is what the format actually is.
Inline spans also parse recursively now. **`ht-theme-main`** — bold wrapping
code, which models write constantly — previously rendered as bold text with
visible backticks, because the match was not re-parsed. Code stays terminal:
everything inside a code span is literal, which is what makes it code.
Parsing moved into markdownParser.ts with no React or DOM, so the grammar can
be tested on its own; markdown.tsx only turns nodes into elements. The two are
named differently on purpose — markdown.ts alongside markdown.tsx would make
"./markdown.js" ambiguous, and the renderer could end up importing itself.
Verified against the exact answer from the bug report: 3 headings and 2 lists
parsed (previously 0 and 0), nested bold-around-code correct, no literal ###
or - left, and a javascript: URL still neutralised to plain text.
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.
Headings and bullet lists were still rendering literally in the Ask AI panel after #120 — reported with a screenshot, reproduced exactly.
Why the first fix missed
The parser split text on blank lines and required each chunk to be entirely one thing: all heading, or all list, or all prose. Models do not write that way:
No blank line anywhere, so the whole chunk failed every homogeneity test and fell through to "paragraph" — the reader saw
###and-as text. Markdown is a line grammar; the parser now walks lines and groups runs of the same kind, which is what the format actually is.Inline spans parse recursively too.
**\ht-theme-main`**` — bold wrapping code, which models write constantly — previously rendered as bold text with visible backticks, because a match was never re-parsed. Code stays terminal: everything inside a code span is literal, which is what makes it code.Structure
Parsing moved to
markdownParser.tswith no React and no DOM, so the grammar is testable on its own;markdown.tsxonly turns nodes into elements. The names differ deliberately —markdown.tsbesidemarkdown.tsxmakes./markdown.jsambiguous, and the renderer could resolve to importing itself.Still no Markdown dependency and still no
innerHTML: elements are constructed directly, so model output cannot inject markup, and links are restricted to http(s).Verified against the reported answer
Ran the parser over the exact text from the screenshot:
STRONG[CODE(ht-theme-main)]###/-leftjavascript:URLNote
Low Risk
Authoring UI-only change; keeps direct React rendering and http(s) link filtering without widening the XSS surface.
Overview
Fixes Ask AI answers that still showed literal
###and-when headings and lists appeared back-to-back with no blank line between them.Parsing moves into new
markdownParser.tsas a pure, line-walking grammar: headings, list runs (with indented continuations), paragraphs, and fenced code blocks are recognized per line instead of requiring each blank-line-separated chunk to be homogenous. Inline markup is parsed recursively so patterns like bold wrapping inline code render correctly.markdown.tsxonly maps the resulting nodes to React elements;safeHref(http/https only) lives with the parser.Rendering still avoids
innerHTMLand external Markdown libraries. Heading/list spacing is tweaked slightly.Reviewed by Cursor Bugbot for commit 96c0a11. Bugbot is set up for automated code reviews on this repo. Configure here.