fix(chat-ui): render lists that continue numbering after a paragraph line

Merged
HA
4h ago
+91-1

Problem

Agents often split a numbered list into sections and continue the numbering:

**Narrow edge cases**
4. First
5. Second

CommonMark lets only a list that starts at 1. interrupt a paragraph. So the chat rendered everything from 4. onward as one run-on paragraph.

Fix

ChatMarkdown now passes its text through separateOrderedLists. When an ordered item numbered other than 1 comes right after a paragraph line, it adds a blank line before the item, so the list renders and keeps its start number.

It does not change:

  • lines inside code fences
  • lists and their continuation lines
  • lines after headings
  • blockquotes and tables

Validation

  • Unit tests for the change and for the cases left untouched. packages/chat-ui suite: 86 pass.
  • Rendered the sample: it now produces <ol start="4">.
  • tsc and biome are clean.

Out of scope: mobile uses its own renderer (apps/mobile/components/ai-elements/message.tsx).


Summary by cubic

Fixes chat rendering of numbered lists that continue numbering after a paragraph line. Agents often split a numbered list into sections (e.g., **Follow-ups**\n4. First), but CommonMark only lets a list starting at 1 interrupt a paragraph, so everything rendered as one run-on paragraph.

  • ChatMarkdown now passes its text through separateOrderedLists, which inserts a blank line before ordered items numbered other than 1 that follow a paragraph line, so the list renders and keeps its start number.
  • Code fences, existing lists, and lines after headings, blockquotes, and tables are left untouched.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Markdown rendering for numbered lists that continue after a paragraph, so they appear as distinct lists.
    • Preserved existing formatting for numbered lists and other Markdown content.