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 21, 21:00 UTC
fix(web): collapsed PR comments no longer show raw HTML (#32283)
Saikrishna Ambeti committed
Nov 12, 2026 at 06:53 UTC
82143423858d31b861fd7f225805e3af05e318f8
3 files changed
+88
-10
apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx
+2
-8
@@ -1,3 +1,4 @@
1
+import { pullRequestCommentPreview } from "./pullRequestMarkdown.logic";
2
import { parsePullRequestAnchor } from "@t3tools/shared/pullRequestAnchor";
3
import { holdLinkedNodeInView } from "./holdLinkedNodeInView";
4
import { useAtomValue } from "@effect/atom-react";
@@ -314,14 +315,7 @@ function CollapsedComment({
315
className="mt-2 block w-full truncate text-left text-xs text-muted-foreground hover:text-foreground"
316
onClick={() => statusTriggerRef.current?.focus({ preventScroll: true })}
317
>
317
- {body
318
- .replace(/<!--[\s\S]*?-->/gu, "")
319
- .replace(/^\s*>?\s*\[!\w+\]\s*$/gmu, "")
320
- .replace(/!?(\[([^\]]+)\])\([^)]*\)/gu, "$2")
321
- .replace(/^[\s>#*-]+/gmu, "")
322
- .replace(/[*`]/gu, "")
323
- .replace(/\s+/g, " ")
324
- .trim()}
318
+ {pullRequestCommentPreview(body)}
319
</CollapsibleTrigger>
320
) : null}
321
</div>
apps/web/src/components/pullRequest/pullRequestMarkdown.logic.test.ts
+29
-1
@@ -3,7 +3,7 @@ import remarkParse from "remark-parse";
3
import { unified } from "unified";
4
import { describe, expect, it } from "vite-plus/test";
5
6
-import { remarkPullRequestAutolinks } from "./pullRequestMarkdown.logic";
6
+import { pullRequestCommentPreview, remarkPullRequestAutolinks } from "./pullRequestMarkdown.logic";
7
8
type Node = {
9
type: string;
@@ -44,3 +44,31 @@ describe("remarkPullRequestAutolinks", () => {
44
]);
45
});
46
});
47
+
48
+describe("pullRequestCommentPreview", () => {
49
+ it.each([
50
+ ["<!-- hidden -->\n> [!WARNING]\n**Guard** [this](https://example.com).", "Guard this."],
51
+ [
52
+ '<a href="https://example.com"><img src="badge.svg" /></a>\n<strong>Tasks keep the wrong computer</strong>',
53
+ "Tasks keep the wrong computer",
54
+ ],
55
+ [
56
+ "<details><summary>Review & fixes</summary><p>First<br>Second</p></details>",
57
+ "Review & fixes First Second",
58
+ ],
59
+ ['<p title="value > limit">Keep <strong>this</strong> readable.</p>', "Keep this readable."],
60
+ [
61
+ "Use `<div>` and `Promise<void>`.\n\n```html\n<span>example</span>\n```",
62
+ "Use <div> and Promise<void>. <span>example</span>",
63
+ ],
64
+ [" **Review**", "badge Review"],
65
+ ["```md\n[!TIP]\n> [!WARNING]\n```\n\n [!NOTE]", "[!TIP] > [!WARNING] [!NOTE]"],
66
+ [
67
+ "Review :codex-file-citation{purpose='output'} safely.",
68
+ "Review :codex-file-citation{purpose='output'} safely.",
69
+ ],
70
+ [":codex-followup[Prepare **print** version]", ":codex-followup[Prepare **print** version]"],
71
+ ])("extracts readable text from %s", (body, expected) => {
72
+ expect(pullRequestCommentPreview(body)).toBe(expected);
73
+ });
74
+});
apps/web/src/components/pullRequest/pullRequestMarkdown.logic.ts
+57
-1
@@ -6,7 +6,14 @@ import {
6
sourceControlClients,
7
type ReferenceAutolink,
8
} from "@t3tools/client-runtime/source-control-clients";
9
-import type { PluggableList } from "unified";
9
+import {
10
+ CHAT_MARKDOWN_REHYPE_PLUGINS,
11
+ CHAT_MARKDOWN_REMARK_PLUGINS,
12
+} from "@t3tools/shared/markdownPipeline";
13
+import type { Nodes } from "hast";
14
+import remarkParse from "remark-parse";
15
+import remarkRehype from "remark-rehype";
16
+import { unified, type PluggableList } from "unified";
17
18
export {
19
splitPullRequestBody,
@@ -95,3 +102,52 @@ export function pullRequestMarkdownPlugins(
102
}
103
return plugins;
104
}
105
+
106
+const commentPreviewProcessor = unified()
107
+ .use(remarkParse)
108
+ .use(CHAT_MARKDOWN_REMARK_PLUGINS)
109
+ .use(remarkRehype, { allowDangerousHtml: true })
110
+ .use(CHAT_MARKDOWN_REHYPE_PLUGINS)
111
+ .freeze();
112
+
113
+const PREVIEW_BLOCK_TAGS = new Set([
114
+ "blockquote",
115
+ "br",
116
+ "dd",
117
+ "details",
118
+ "div",
119
+ "dl",
120
+ "dt",
121
+ "h1",
122
+ "h2",
123
+ "h3",
124
+ "h4",
125
+ "h5",
126
+ "h6",
127
+ "hr",
128
+ "li",
129
+ "ol",
130
+ "p",
131
+ "pre",
132
+ "summary",
133
+ "table",
134
+ "td",
135
+ "th",
136
+ "tr",
137
+ "ul",
138
+]);
139
+
140
+function commentPreviewText(node: Nodes): string {
141
+ if (node.type === "text") return node.value;
142
+ if (node.type === "element" && node.tagName === "img") {
143
+ return typeof node.properties.alt === "string" ? node.properties.alt : "";
144
+ }
145
+ if (!("children" in node)) return "";
146
+ const text = node.children.map(commentPreviewText).join("");
147
+ return node.type === "element" && PREVIEW_BLOCK_TAGS.has(node.tagName) ? ` ${text} ` : text;
148
+}
149
+
150
+export function pullRequestCommentPreview(body: string): string {
151
+ const tree = commentPreviewProcessor.runSync(commentPreviewProcessor.parse(body), body);
152
+ return commentPreviewText(tree).replace(/\s+/gu, " ").trim();
153
+}