From 1ae9fdef2d507b31a8002d2aac62ea3efbb74860 Mon Sep 17 00:00:00 2001 From: BrunooMoniz Date: Sat, 18 Jul 2026 01:37:33 +0000 Subject: [PATCH] fix(markdown): render nested lists with an indentation stack The chat markdown renderer built lists with regex passes anchored on the absolute start of the line (`^(\d+)\. `, `^(?:- |\* )...`) and grouped only consecutive sentinel lines, with no notion of depth. An indented item such as ` - Sub` never matched, fell through to the paragraph pass, and rendered as literal `- Sub` text while the parent list fragmented. The ordered-nested case was worse: it emitted an `
    ` inside a `

    `, which is invalid HTML. Replace the flatten-and-group passes with `_buildLists`, which parses each item's indentation and walks a per-run indentation stack: a deeper item opens a child list inside the still-open parent `

  1. ` (`
  2. ...
      ...
  3. `) and a dedent closes levels until the indentation matches an open one. Indentation is compared relatively to the parent on the stack, so inconsistent 2-/3-/4-space and tab widths nest the same way and mixed ordered/unordered nesting produces valid HTML. Task-checkbox items keep their `task-item` class and nest correctly; a small flex-wrap/flex-basis rule drops a sub-list nested under a task item onto its own line instead of sitting inline after the label. Adds nested unordered/ordered/mixed/task/deep cases to tests/test_markdown_rendering_js.py and a mixed-nested sample to the streaming corpus; the existing flat-list, table, code, and autolink contracts are unchanged. --- static/js/markdown.js | 145 +++++++++++++++++++++--- static/style.css | 15 +++ tests/streaming/corpus.mjs | 1 + tests/test_markdown_rendering_js.py | 169 ++++++++++++++++++++++++++++ 4 files changed, 312 insertions(+), 18 deletions(-) diff --git a/static/js/markdown.js b/static/js/markdown.js index 8735b83e7f..88a3b6d077 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -482,6 +482,125 @@ export function processWithThinking(text) { return _useSvgEmoji() ? svgifyEmoji(html) : html; } +// --------------------------------------------------------------------------- +// Nested markdown lists. +// +// Ordered (`1.`), unordered (`- ` / `* `) and GitHub task (`- [ ] `) items are +// grouped into properly nested