@devries-cameron20 / t3code-1 / commits / b62e80e0a3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): copying an alert callout keeps its alert Markdown (#35932)

Julius Marminge committed Nov 12, 2026 at 20:06 UTC b62e80e0a3fa9ab09d8373a49b3f6fb0df88dff0
4 files changed +94 -6
apps/web/src/components/ChatMarkdown.browser.test.tsx
+25
@@ -120,6 +120,7 @@ vi.mock(import("../hooks/useSettings"), async (original) => {
120 });
121
122 import ChatMarkdown from "./ChatMarkdown";
123 +import { chatMarkdownClipboardPayload } from "../markdown-clipboard";
124 import { AudioPreview } from "./files/AudioPreview";
125
126 it("keeps compact audio playback loaded across signed URL renewals", async () => {
@@ -617,6 +618,30 @@ describe("ChatMarkdown inline code selection", () => {
618 });
619 });
620
621 +describe("ChatMarkdown alert copy", () => {
622 + it("copies a fully selected callout as alert Markdown and a partial one as text", async () => {
623 + setup();
624 + await using screen = await renderText("> [!WARNING]\n> Back up first.");
625 + const [label, body] = screen.container.querySelectorAll('[role="note"] > p');
626 + const select = (startNode: Node, endNode: Node, endOffset: number) => {
627 + const range = document.createRange();
628 + range.setStart(startNode, 0);
629 + range.setEnd(endNode, endOffset);
630 + const selection = window.getSelection()!;
631 + selection.removeAllRanges();
632 + selection.addRange(range);
633 + return chatMarkdownClipboardPayload(selection)?.text;
634 + };
635 + const labelText = label!.lastChild!;
636 + const bodyText = body!.firstChild!;
637 +
638 + expect(select(labelText, bodyText, bodyText.textContent!.length)).toBe(
639 + "> [!WARNING]\n> Back up first.",
640 + );
641 + expect(select(labelText, bodyText, "Back up".length)).toBe("Warning\n\nBack up");
642 + });
643 +});
644 +
645 describe("ChatMarkdown file chip tooltips", () => {
646 it("wraps a long path so its file name stays inside the tooltip", async () => {
647 setup();
apps/web/src/components/ChatMarkdown.tsx
+4 -2
@@ -1055,19 +1055,21 @@ const CHAT_MARKDOWN_COMPONENTS = {
1055 );
1056 },
1057 blockquote: function MarkdownBlockquote({ node: _node, children, ...props }) {
1058 - const alert =
1059 - GITHUB_ALERT_PRESENTATIONS[String((props as Record<string, unknown>)["data-alert"] ?? "")];
1058 + const alertKind = String((props as Record<string, unknown>)["data-alert"] ?? "");
1059 + const alert = GITHUB_ALERT_PRESENTATIONS[alertKind];
1060 if (!alert) {
1061 return <blockquote {...props}>{children}</blockquote>;
1062 }
1063 return (
1064 <div
1065 role="note"
1066 + data-markdown-alert={alertKind}
1067 dir={props.dir}
1068 className={cn("my-1 border-s-2 ps-3", alert.borderClassName)}
1069 >
1070 <p
1071 data-thread-find-ignore="true"
1072 + data-markdown-alert-label=""
1073 className={cn("flex items-center gap-1.5 font-medium", alert.titleClassName)}
1074 >
1075 <alert.Icon aria-hidden className="size-3.5 shrink-0" />
apps/web/src/markdown-clipboard.test.ts
+32
@@ -198,6 +198,38 @@ describe("serializeRenderedMarkdownFragment", () => {
198 expect(serializeRenderedMarkdownFragment(asNode(container))).toBe("first line\nsecond line");
199 });
200
201 + it("copies alert and insight callouts as their Markdown instead of the rendered label", () => {
202 + // The shape ChatMarkdown renders for `> [!WARNING]\n> Back up first.`.
203 + const callout = new FakeElement("DIV", [], {
204 + role: "note",
205 + "data-markdown-alert": "warning",
206 + }).append(
207 + new FakeElement("P", [], {
208 + "data-thread-find-ignore": "true",
209 + "data-markdown-alert-label": "",
210 + }).append(new FakeElement("SVG", [], { "aria-hidden": "true" }), new FakeText("Warning")),
211 + new FakeElement("P").append(new FakeText("Back up first.")),
212 + );
213 + const container = new FakeElement("DIV").append(callout);
214 +
215 + expect(serializeRenderedMarkdownFragment(asNode(container))).toBe(
216 + "> [!WARNING]\n> Back up first.",
217 + );
218 + const insight = new FakeElement("DIV", [], {
219 + role: "note",
220 + "data-markdown-alert": "insight",
221 + }).append(
222 + new FakeElement("P", [], {
223 + "data-thread-find-ignore": "true",
224 + "data-markdown-alert-label": "",
225 + }).append(new FakeText("Insight")),
226 + new FakeElement("P").append(new FakeText("Caches are warm.")),
227 + );
228 + expect(serializeRenderedMarkdownFragment(asNode(new FakeElement("DIV").append(insight)))).toBe(
229 + `★ Insight ${"─".repeat(37)}\nCaches are warm.\n${"─".repeat(49)}`,
230 + );
231 + });
232 +
233 it("preserves explicit ordered-list values and continues from resets when copying", () => {
234 const list = new FakeElement("OL", [], { start: "0" }).append(
235 new FakeElement("LI").append(new FakeText("A")),
apps/web/src/markdown-clipboard.ts
+33 -4
@@ -10,6 +10,9 @@ const SANITIZED_HTML_SELECTOR = [
10 ...SKIPPED_CLASS_NAMES.map((className) => `.${className}`),
11 ].join(", ");
12
13 +const ALERT_ATTRIBUTE = "data-markdown-alert";
14 +const ALERT_LABEL = "data-markdown-alert-label";
15 +
16 export interface MarkdownClipboardPayload {
17 text: string;
18 html: string;
@@ -159,10 +162,21 @@ function serializeList(list: Element, ordered: boolean, inTableCell: boolean): s
162 .join("\n")}\n\n`;
163 }
164
162 -function serializeBlockquote(quote: Element, inTableCell: boolean): string {
163 - const content = outsideCode(serializeChildren(quote, inTableCell), (prose) =>
164 - prose.replace(/\n{3,}/g, "\n\n"),
165 - ).trim();
165 +function serializeQuoteBody(quote: Element, inTableCell: boolean): string {
166 + let content = "";
167 + for (const child of quote.childNodes) {
168 + // A callout's rendered label stands for the marker its serializer writes.
169 + if (child.nodeType === Node.ELEMENT_NODE && (child as Element).hasAttribute(ALERT_LABEL)) {
170 + continue;
171 + }
172 + content += serializeNode(child, inTableCell);
173 + }
174 + return outsideCode(content, (prose) => prose.replace(/\n{3,}/g, "\n\n")).trim();
175 +}
176 +
177 +function serializeBlockquote(quote: Element, inTableCell: boolean, marker = ""): string {
178 + const body = serializeQuoteBody(quote, inTableCell);
179 + const content = marker && body ? `${marker}\n${body}` : marker || body;
180 if (!content) return "";
181 const quoted = content
182 .split("\n")
@@ -171,6 +185,11 @@ function serializeBlockquote(quote: Element, inTableCell: boolean): string {
185 return `${quoted}\n\n`;
186 }
187
188 +function serializeInsight(insight: Element, inTableCell: boolean): string {
189 + const body = serializeQuoteBody(insight, inTableCell);
190 + return `★ Insight ${"─".repeat(37)}\n${body ? `${body}\n` : ""}${"─".repeat(49)}\n\n`;
191 +}
192 +
193 function serializeDetails(details: Element): string {
194 const summary =
195 details.querySelector(":scope > [data-markdown-details-summary]")?.textContent?.trim() ??
@@ -231,6 +250,9 @@ function serializeNode(node: Node, inTableCell = false): string {
250 : escapeTablePipes(markdownCopy, inTableCell);
251 }
252 if (isSkippedElement(element)) return "";
253 + const alert = element.getAttribute(ALERT_ATTRIBUTE);
254 + if (alert === "insight") return serializeInsight(element, inTableCell);
255 + if (alert !== null) return serializeBlockquote(element, inTableCell, `[!${alert.toUpperCase()}]`);
256
257 const headingLevel = /^H([1-6])$/.exec(element.tagName)?.[1];
258 if (headingLevel) {
@@ -478,6 +500,13 @@ export function chatMarkdownClipboardPayload(
500 }
501 continue;
502 }
503 + // A range spanning exactly one callout's text clones its contents but not the callout.
504 + const callout = ancestorElement?.closest(`[${ALERT_ATTRIBUTE}]`);
505 + if (callout && range.toString().trim() === (callout.textContent ?? "").trim()) {
506 + const wrapper = callout.cloneNode(false) as Element;
507 + wrapper.append(...container.childNodes);
508 + container.replaceChildren(wrapper);
509 + }
510 const text = serializeRenderedMarkdownFragment(container);
511 if (!text) continue;
512 texts.push(text);