Skip to content

Commit 831e9e8

Browse files
fix(client-runtime): media tables with a caption keep it
A table's <caption> sits outside its cells, so the table segment dropped it. Such tables now go through the line splitter, which keeps the caption. Addresses #25988 (comment)
1 parent cfaf032 commit 831e9e8

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎packages/client-runtime/src/pullRequestMarkdown.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,19 @@ describe("media on custom hosts", () => {
166166
{ id: "attachment:1", kind: "attachment", url: "https://example.com/a.mp4", media: "video" },
167167
]);
168168
});
169+
170+
it("keeps the caption of a media table instead of dropping it", () => {
171+
const segments = splitPullRequestBody(
172+
"<table>\n<caption>Before upgrading</caption>\n<tr><td>\n\nhttps://example.com/a.mp4\n\n</td></tr>\n</table>",
173+
);
174+
expect(segments.some((segment) => segment.kind === "table")).toBe(false);
175+
expect(segments).toContainEqual(
176+
expect.objectContaining({
177+
kind: "markdown",
178+
text: expect.stringContaining("Before upgrading"),
179+
}),
180+
);
181+
});
169182
});
170183

171184
describe("change request reference autolinks", () => {

‎packages/client-runtime/src/pullRequestMarkdown.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function mediaTableAt(
8080
}
8181
if (!TABLE_END_PATTERN.test(lines[end]!)) return null;
8282
const html = lines.slice(start, end + 1).join("\n");
83-
if ((html.match(TABLE_TAG_PATTERN)?.length ?? 0) > 1) return null;
83+
if (/<caption\b/iu.test(html) || (html.match(TABLE_TAG_PATTERN)?.length ?? 0) > 1) return null;
8484
const rows = Array.from(html.matchAll(TABLE_ROW_PATTERN), ([, row]) =>
8585
Array.from(row!.matchAll(TABLE_CELL_PATTERN), ([, tag, content]) => ({
8686
header: tag!.toLowerCase() === "th",

0 commit comments

Comments
 (0)