Skip to content

fix(runner): parse assistant answers as a line grammar (DEV-2047) - #121

Merged
qunabu merged 1 commit into
masterfrom
fix/DEV-2047-markdown-line-grammar
Aug 7, 2026
Merged

fix(runner): parse assistant answers as a line grammar (DEV-2047)#121
qunabu merged 1 commit into
masterfrom
fix/DEV-2047-markdown-line-grammar

Conversation

@qunabu

@qunabu qunabu commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

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:

### 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 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.ts with no React and no DOM, so the grammar is testable on its own; markdown.tsx only turns nodes into elements. The names differ deliberately — markdown.ts beside markdown.tsx makes ./markdown.js ambiguous, 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:

before after
headings parsed 0 3
lists parsed 0 2
nested bold-around-code literal backticks STRONG[CODE(ht-theme-main)]
literal ### / - left yes none
javascript: URL neutralised still neutralised

Note

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.ts as 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.tsx only maps the resulting nodes to React elements; safeHref (http/https only) lives with the parser.

Rendering still avoids innerHTML and 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.

…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.
@qunabu
qunabu merged commit 904259c into master Aug 7, 2026
3 checks passed
@demtario
demtario deleted the fix/DEV-2047-markdown-line-grammar branch August 10, 2026 06:19
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