The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 00:45 UTC
fix(web): sent messages keep the numbers written on list items (#33820)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Yash Singh <saiansh2525@gmail.com>
Anton 🌻 committed
Nov 10, 2026 at 22:59 UTC
d6d1763d415c59735708036ab790c540ef962cf0
10 files changed
+192
-12
apps/web/src/components/ChatMarkdown.browser.test.tsx
+33
@@ -9,6 +9,7 @@ import "../index.css";
9
10
import { filesystemEnvironment } from "../state/filesystem";
11
import { useRightPanelStore } from "../rightPanelStore";
12
+import { remarkEnableOrderedListNumbers } from "@t3tools/shared/markdownPipeline";
13
import { setMarkdownTaskChecked } from "@t3tools/shared/markdownTaskList";
14
import { HostImageUrlContext } from "./chat/hostImageUrl";
15
@@ -162,6 +163,38 @@ function buttonsLabelled(container: HTMLElement, label: string) {
163
);
164
}
165
166
+const SOURCE_NUMBER_PLUGINS = [remarkEnableOrderedListNumbers];
167
+
168
+it("keeps decimal markers in nested user lists while documents keep their counter styles", async () => {
169
+ setup();
170
+ const text = "1. Outer\n 1. Nested\n 7. Skipped\n 1. Deeper\n 4. Fourth";
171
+ await using screen = await render(
172
+ <div className="grid grid-cols-2 gap-8 p-8">
173
+ <section>
174
+ <h2>User message</h2>
175
+ <ChatMarkdown
176
+ cwd={undefined}
177
+ text={text}
178
+ className="user-message-markdown"
179
+ extraRemarkPlugins={SOURCE_NUMBER_PLUGINS}
180
+ />
181
+ </section>
182
+ <section>
183
+ <h2>Markdown preview</h2>
184
+ <ChatMarkdown cwd={undefined} text={text} />
185
+ </section>
186
+ </div>,
187
+ );
188
+ await expect.element(screen.getByText("User message", { exact: true })).toBeVisible();
189
+ const [message, preview] = screen.container.querySelectorAll(".chat-markdown");
190
+ expect(
191
+ [...message!.querySelectorAll("ol")].map((list) => getComputedStyle(list).listStyleType),
192
+ ).toEqual(["decimal", "decimal", "decimal"]);
193
+ expect(
194
+ [...preview!.querySelectorAll("ol")].map((list) => getComputedStyle(list).listStyleType),
195
+ ).toEqual(["decimal", "lower-alpha", "lower-roman"]);
196
+});
197
+
198
it("shows unavailable audio when a workspace embed has no thread", async () => {
199
setup();
200
await using screen = await renderText("");
apps/web/src/components/ChatMarkdown.tsx
+14
-8
@@ -322,13 +322,18 @@ function CodexArtifactTemplateCard(props: {
322
const WINDOWS_DRIVE_PATH_REGEX = /^[A-Za-z]:[\\/]/;
323
324
function orderedListGutterStyle(
325
- itemCount: number,
325
+ itemValues: ReadonlyArray<unknown>,
326
start: unknown,
327
): { "--list-gutter": string } | undefined {
328
const parsedStart = Number.parseInt(String(start ?? 1), 10);
329
- const firstNumber = Number.isNaN(parsedStart) ? 1 : parsedStart;
330
- const lastNumber = firstNumber + Math.max(itemCount - 1, 0);
331
- const markerWidth = Math.max(String(firstNumber).length, String(lastNumber).length);
329
+ let number = Number.isNaN(parsedStart) ? 1 : parsedStart;
330
+ let markerWidth = String(number).length;
331
+ for (const value of itemValues) {
332
+ const written = Number.parseInt(String(value ?? ""), 10);
333
+ if (!Number.isNaN(written)) number = written;
334
+ markerWidth = Math.max(markerWidth, String(number).length);
335
+ number += 1;
336
+ }
337
if (markerWidth <= 1) return undefined;
338
return { "--list-gutter": `${markerWidth + 2}ch` };
339
}
@@ -1017,10 +1022,11 @@ const CHAT_MARKDOWN_COMPONENTS = {
1022
);
1023
},
1024
ol: function MarkdownOrderedList({ node, start, style, ...props }) {
1020
- const itemCount =
1021
- node?.children?.filter((child) => child.type === "element" && child.tagName === "li")
1022
- .length ?? 0;
1023
- const gutterStyle = orderedListGutterStyle(itemCount, start);
1025
+ const itemValues =
1026
+ node?.children?.flatMap((child) =>
1027
+ child.type === "element" && child.tagName === "li" ? [child.properties.value] : [],
1028
+ ) ?? [];
1029
+ const gutterStyle = orderedListGutterStyle(itemValues, start);
1030
return (
1031
<ol {...props} start={start} style={gutterStyle ? { ...style, ...gutterStyle } : style} />
1032
);
apps/web/src/components/chat/TimelineUserMessageRow.tsx
+5
-1
@@ -1,5 +1,6 @@
1
import { InlineAudioPreview } from "../files/InlineAudioPreview";
2
import { filePreviewKind } from "@t3tools/shared/filePreview";
3
+import { remarkEnableOrderedListNumbers } from "@t3tools/shared/markdownPipeline";
4
import { findRevealRef } from "./markdownFindContext";
5
import {
6
type EnvironmentId,
@@ -1184,6 +1185,8 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
1185
);
1186
});
1187
1188
+const USER_MESSAGE_REMARK_PLUGINS = [remarkEnableOrderedListNumbers];
1189
+
1190
const UserMessageBody = memo(function UserMessageBody(props: {
1191
text: string;
1192
renderContextReference?: (reference: ChatMarkdownContextReference) => ReactNode;
@@ -1200,9 +1203,10 @@ const UserMessageBody = memo(function UserMessageBody(props: {
1203
cwd={props.markdownCwd}
1204
threadRef={ctx.threadRef ?? undefined}
1205
skills={props.skills}
1203
- className="text-foreground"
1206
+ className="text-foreground user-message-markdown"
1207
lineBreaks
1208
parseRawHtml={false}
1209
+ extraRemarkPlugins={USER_MESSAGE_REMARK_PLUGINS}
1210
renderContextReference={props.renderContextReference}
1211
headingLevelOffset={MESSAGE_HEADING_LEVEL}
1212
/>
apps/web/src/index.css
+4
@@ -2012,6 +2012,10 @@ code {
2012
list-style-type: lower-roman;
2013
}
2014
2015
+.chat-markdown.user-message-markdown ol {
2016
+ list-style-type: decimal;
2017
+}
2018
+
2019
.chat-markdown li + li {
2020
margin-top: 0.25rem;
2021
}
apps/web/src/markdown-clipboard.test.ts
+12
@@ -197,6 +197,18 @@ describe("serializeRenderedMarkdownFragment", () => {
197
expect(serializeRenderedMarkdownFragment(asNode(container))).toBe("first line\nsecond line");
198
});
199
200
+ it("preserves explicit ordered-list values and continues from resets when copying", () => {
201
+ const list = new FakeElement("OL", [], { start: "0" }).append(
202
+ new FakeElement("LI").append(new FakeText("A")),
203
+ new FakeElement("LI", [], { value: "5" }).append(new FakeText("B")),
204
+ new FakeElement("LI").append(new FakeText("C")),
205
+ new FakeElement("LI", [], { value: "0" }).append(new FakeText("D")),
206
+ );
207
+ expect(serializeRenderedMarkdownFragment(asNode(new FakeElement("DIV").append(list)))).toBe(
208
+ "0. A\n5. B\n6. C\n0. D",
209
+ );
210
+ });
211
+
212
it("keeps fences when a bare list item sits alongside the code block", () => {
213
const container = new FakeElement("DIV").append(
214
new FakeElement("UL").append(new FakeElement("LI")),
apps/web/src/markdown-clipboard.ts
+9
-2
@@ -144,10 +144,17 @@ function serializeListItem(
144
}
145
146
function serializeList(list: Element, ordered: boolean, inTableCell: boolean): string {
147
- const start = Number.parseInt(list.getAttribute("start") ?? "1", 10) || 1;
147
+ const start = Number.parseInt(list.getAttribute("start") ?? "1", 10);
148
const items = [...list.children].filter((child) => child.tagName === "LI");
149
if (items.length === 0) return "";
150
- return `${items.map((item, index) => serializeListItem(item, ordered, start + index, inTableCell)).join("\n")}\n\n`;
150
+ let next = Number.isNaN(start) ? 1 : start;
151
+ return `${items
152
+ .map((item) => {
153
+ const value = Number.parseInt(item.getAttribute("value") ?? "", 10);
154
+ if (ordered && !Number.isNaN(value)) next = value;
155
+ return serializeListItem(item, ordered, next++, inTableCell);
156
+ })
157
+ .join("\n")}\n\n`;
158
}
159
160
function serializeBlockquote(quote: Element, inTableCell: boolean): string {
packages/shared/src/markdownListIndentation.ts
+5
@@ -1,3 +1,5 @@
1
+import { keepOrderedListNumbers, keepsOrderedListNumbers } from "./markdownOrderedListNumbers.ts";
2
+
3
interface MarkdownPosition {
4
readonly start?: {
5
readonly line?: number;
@@ -91,6 +93,9 @@ function parseRecoveredMarkdown(value: string, parser: MarkdownParser): Recovere
93
function blocksFromIndentedCode(node: MarkdownAstNode, parser: MarkdownParser): RecoveredMarkdown {
94
const value = typeof node.value === "string" ? node.value.trim() : "";
95
const recovered = parseRecoveredMarkdown(value, parser);
96
+ if (keepsOrderedListNumbers(parser)) {
97
+ for (const block of recovered.blocks) keepOrderedListNumbers(block, recovered.source);
98
+ }
99
const first = recovered.blocks[0];
100
return {
101
...recovered,
packages/shared/src/markdownOrderedListNumbers.ts
new
+62
@@ -0,0 +1,62 @@
1
+import type { Root } from "mdast";
2
+import type { Transformer } from "unified";
3
+
4
+interface MarkdownListNode {
5
+ readonly type: string;
6
+ readonly ordered?: boolean | null | undefined;
7
+ readonly start?: number | null | undefined;
8
+ readonly position?:
9
+ | { readonly start?: { readonly offset?: number | undefined } | undefined }
10
+ | undefined;
11
+ data?: { hProperties?: Record<string, unknown> | undefined } | undefined;
12
+ children?: MarkdownListNode[] | undefined;
13
+}
14
+
15
+const WRITTEN_NUMBER = /[ \t]*(\d{1,9})[.)]/y;
16
+
17
+/**
18
+ * CommonMark numbers an ordered list from its first marker only, so answers to questions 3 and 5
19
+ * would render as 3 and 4. An item whose written number breaks the sequence keeps it. `source` is
20
+ * the text the node's offsets point into.
21
+ */
22
+export function keepOrderedListNumbers(node: MarkdownListNode, source: string): void {
23
+ if (!node.children) return;
24
+ if (node.type === "list" && node.ordered) {
25
+ let expected = node.start ?? 1;
26
+ for (const item of node.children) {
27
+ const offset = item.position?.start?.offset;
28
+ WRITTEN_NUMBER.lastIndex = offset ?? 0;
29
+ const digits = offset === undefined ? undefined : WRITTEN_NUMBER.exec(source)?.[1];
30
+ const value = digits === undefined ? expected : Number(digits);
31
+ if (value !== expected) {
32
+ item.data = {
33
+ ...item.data,
34
+ hProperties: { ...item.data?.hProperties, value: String(value) },
35
+ };
36
+ }
37
+ expected = value + 1;
38
+ }
39
+ }
40
+ for (const child of node.children) keepOrderedListNumbers(child, source);
41
+}
42
+
43
+const enabledProcessors = new WeakSet<object>();
44
+
45
+/**
46
+ * Opts a processor in. User messages use it so the sent bubble shows the numbers the composer
47
+ * showed and the agent received; agent replies and files keep CommonMark numbering.
48
+ */
49
+export function remarkEnableOrderedListNumbers(this: object): undefined {
50
+ enabledProcessors.add(this);
51
+}
52
+
53
+export function keepsOrderedListNumbers(processor: object): boolean {
54
+ return enabledProcessors.has(processor);
55
+}
56
+
57
+/** Sits before list recovery so offsets still point into the file. */
58
+export function remarkKeepOrderedListNumbers(this: object): Transformer<Root> {
59
+ return (tree, file) => {
60
+ if (enabledProcessors.has(this)) keepOrderedListNumbers(tree, String(file));
61
+ };
62
+}
packages/shared/src/markdownPipeline.test.ts
+43
-1
@@ -1,5 +1,5 @@
1
import { expect, it } from "vite-plus/test";
2
-import { unified } from "unified";
2
+import { type PluggableList, unified } from "unified";
3
import rehypeRaw from "rehype-raw";
4
import remarkParse from "remark-parse";
5
import remarkRehype from "remark-rehype";
@@ -8,6 +8,7 @@ import {
8
CHAT_MARKDOWN_REHYPE_PLUGINS,
9
CHAT_MARKDOWN_REMARK_PLUGINS,
10
CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS,
11
+ remarkEnableOrderedListNumbers,
12
} from "./markdownPipeline.ts";
13
14
it.each([
@@ -309,6 +310,47 @@ it("keeps an image on its own line under a label but leaves inline images inline
310
expect(render("Hard-wrapped\nprose")).toBe("Hard-wrapped\nprose");
311
});
312
313
+it("keeps the number written on each ordered list item only when enabled", () => {
314
+ type Node = { tagName?: string; properties?: { value?: unknown }; children?: Node[] };
315
+ const values = (node: Node): unknown[] => [
316
+ ...(node.tagName === "li" ? [node.properties?.value] : []),
317
+ ...(node.children ?? []).flatMap(values),
318
+ ];
319
+ const renderer = (plugins: PluggableList) => {
320
+ const processor = unified()
321
+ .use(remarkParse)
322
+ .use(plugins)
323
+ .use(remarkRehype, { allowDangerousHtml: true });
324
+ return (markdown: string) =>
325
+ values(processor.runSync(processor.parse(markdown), markdown) as Node);
326
+ };
327
+ const render = renderer([
328
+ ...CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS,
329
+ remarkEnableOrderedListNumbers,
330
+ ]);
331
+
332
+ expect(render("3. first\n5. second\n6. third")).toEqual([undefined, "5", undefined]);
333
+ expect(render("1. one\n1. one again")).toEqual([undefined, "1"]);
334
+ expect(render("> 1. quoted\n> 4. skipped")).toEqual([undefined, "4"]);
335
+ expect(render("1. outer\n 1. nested\n 7. jump\n9. back")).toEqual([
336
+ undefined,
337
+ undefined,
338
+ "7",
339
+ "9",
340
+ ]);
341
+ expect(render("1. one\n2. two\n- bullet")).toEqual([undefined, undefined, undefined]);
342
+ expect(render("- first block\n\n 3. first\n 5. second")).toEqual([
343
+ undefined,
344
+ undefined,
345
+ "5",
346
+ ]);
347
+ expect(
348
+ renderer(CHAT_MARKDOWN_REMARK_PLUGINS)(
349
+ "3. first\n5. second\n\n- first block\n\n 3. first\n 5. second",
350
+ ),
351
+ ).toEqual([undefined, undefined, undefined, undefined, undefined]);
352
+});
353
+
354
it("moves a <picture>'s color-scheme sources onto its <img>, which the renderer resolves", () => {
355
const processor = unified()
356
.use(remarkParse)
packages/shared/src/markdownPipeline.ts
+5
@@ -11,6 +11,7 @@ import remarkBreaks from "remark-breaks";
11
import remarkGfm from "remark-gfm";
12
import { remarkGithubAlerts } from "./markdownGithubAlerts.ts";
13
import { remarkNormalizeListItemIndentation } from "./markdownListIndentation.ts";
14
+import { remarkKeepOrderedListNumbers } from "./markdownOrderedListNumbers.ts";
15
import {
16
CODEX_ARTIFACT_TEMPLATE_HAST_PROPERTIES,
17
remarkCodexDirectives,
@@ -18,6 +19,8 @@ import {
19
import { isWindowsDrivePathHref, normalizeMarkdownLinkDestination } from "./markdownLinks.ts";
20
import { THREAD_LINK_PROTOCOL } from "./threadLinks.ts";
21
22
+export { remarkEnableOrderedListNumbers } from "./markdownOrderedListNumbers.ts";
23
+
24
type MarkdownImageHastNode = {
25
type?: string;
26
value?: string;
@@ -230,6 +233,7 @@ export const CHAT_MARKDOWN_REMARK_PLUGINS: PluggableList = [
233
remarkKeepAutolinkSuffixes,
234
remarkKeepWindowsPaths,
235
remarkGithubAlerts,
236
+ remarkKeepOrderedListNumbers,
237
remarkNormalizeListItemIndentation,
238
remarkCodexDirectives,
239
remarkBreakAroundImageLines,
@@ -242,6 +246,7 @@ export const CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS: PluggableList = [
246
remarkKeepAutolinkSuffixes,
247
remarkKeepWindowsPaths,
248
remarkGithubAlerts,
249
+ remarkKeepOrderedListNumbers,
250
remarkNormalizeListItemIndentation,
251
remarkCodexDirectives,
252
remarkBreakAroundImageLines,