Skip to content

Commit f9d5307

Browse files
fix(web): show minimap previews as plain text, not raw markdown
The minimap hover preview only collapsed whitespace, so assistant replies with tables, links, code, or lists showed raw syntax such as "| Used for | Model | | --- | --- |". Strip common markdown syntax from the assistant text before compacting it, keeping cell text, link labels, and code contents.
1 parent 4ee6bfd commit f9d5307

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

‎apps/web/src/components/chat/timelineMinimapItems.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,36 @@ describe("timeline minimap previews", () => {
6464
expect(resolveTimelineMinimapPreview(null)).toBeNull();
6565
});
6666

67+
it("previews assistant markdown as plain text", () => {
68+
const [item] = deriveTimelineMinimapItems(
69+
rows([
70+
["user", "what **model** are we using?"],
71+
[
72+
"assistant",
73+
[
74+
"## Models",
75+
"We use **two** models, see [the docs](https://example.com/docs):",
76+
"",
77+
"| Used for | Model |",
78+
"| --- | :---: |",
79+
"| Titles | `@cf/meta/llama` |",
80+
"",
81+
"- [x] Set in `config/ai.ts`",
82+
"> Note: ~~old~~ new",
83+
"```ts",
84+
"const snake_case = a * b;",
85+
"```",
86+
].join("\n"),
87+
],
88+
]),
89+
);
90+
expect(resolveTimelineMinimapPreview(item!)).toMatchObject({
91+
userText: "what **model** are we using?",
92+
assistantText:
93+
"Models We use two models, see the docs: Used for Model Titles @cf/meta/llama Set in config/ai.ts Note: old new const snake_case = a * b;",
94+
});
95+
});
96+
6797
it("shows fresh streaming text without changing the jump target", () => {
6898
const first = deriveTimelineMinimapItems(
6999
rows([

‎apps/web/src/components/chat/timelineMinimapItems.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ function resolveFinalAssistantTextForTurn(
4848
return finalAssistantText;
4949
}
5050

51+
/** Drops markdown syntax so table, list, and link sources read as plain preview text. */
52+
function stripMarkdownForPreview(text: string) {
53+
return (
54+
text
55+
// Code fence lines, then table delimiter rows and thematic breaks.
56+
.replace(/^[ \t]*(?:```|~~~).*$/gm, "")
57+
.replace(/^[ \t]*\|?[ \t]*:?-{3,}:?[ \t]*(?:\|[ \t]*:?-{3,}:?[ \t]*)*\|?[ \t]*$/gm, "")
58+
// Table rows keep their cell text.
59+
.replace(/^[ \t]*\|(.*?)\|?[ \t]*$/gm, (_, cells: string) => cells.replace(/\s*\|\s*/g, " "))
60+
// Blockquote, heading, list, and task markers at the start of a line.
61+
.replace(/^[ \t]*(?:>[ \t]*)*(?:(?:#{1,6}|[-*+]|\d+[.)])[ \t]+)?(?:\[[ xX]\][ \t]+)?/gm, "")
62+
// Links and images keep their label.
63+
.replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1")
64+
.replace(/`+([^`]+)`+/g, "$1")
65+
// Paired bold and strikethrough only; single `*` and `_` are common in identifiers.
66+
.replace(/(\*\*|__|~~)(\S(?:.*?\S)?)\1/g, "$2")
67+
);
68+
}
69+
5170
function compactMinimapPreview(text: string | null | undefined) {
5271
const compact = text?.replace(/\s+/g, " ").trim() ?? "";
5372
return compact.length > 0 ? compact : null;
@@ -61,6 +80,8 @@ export function resolveTimelineMinimapPreview(
6180
: {
6281
...item,
6382
userText: compactMinimapPreview(item.userText),
64-
assistantText: compactMinimapPreview(item.assistantText),
83+
assistantText: compactMinimapPreview(
84+
item.assistantText === null ? null : stripMarkdownForPreview(item.assistantText),
85+
),
6586
};
6687
}

0 commit comments

Comments
 (0)