Skip to content

Commit 7d6d9a3

Browse files
MarcoDotIOclaude
andcommitted
fix(client-runtime): a line of inline triple-backtick code no longer flips later code blocks in pull request bodies
A backtick fence's info string cannot hold a backtick, so a line such as "```npm test``` passes." is inline code. The pull request body splitter read it as a fence opener, which inverted every fence after it: media links outside code stayed as plain links, and a media link inside a later code block was lifted out, splitting the block. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d51bc58 commit 7d6d9a3

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ describe("pull request body segmentation", () => {
8080
]);
8181
});
8282

83+
// CommonMark: a backtick fence's info string cannot hold a backtick, so this line is inline code.
84+
it("does not open a fence on a line of inline triple-backtick code", () => {
85+
const code = "```\nhttps://example.com/b.png\n```";
86+
expect(
87+
splitPullRequestBody(
88+
`\`\`\`npm test\`\`\` passes.\n\nhttps://example.com/demo.mp4\n\n${code}`,
89+
),
90+
).toEqual([
91+
{ id: "markdown:0", kind: "markdown", text: "```npm test``` passes." },
92+
{
93+
id: "attachment:1",
94+
kind: "attachment",
95+
url: "https://example.com/demo.mp4",
96+
media: "video",
97+
},
98+
{ id: "markdown:2", kind: "markdown", text: code },
99+
]);
100+
});
101+
83102
it("leaves an indented code line alone even when it is only a video link", () => {
84103
const body = " https://example.com/demo.mp4";
85104
expect(splitPullRequestBody(body)).toEqual([

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ export function splitPullRequestBody(body: string): ReadonlyArray<PullRequestBod
6969
for (let index = 0; index < lines.length; index += 1) {
7070
const line = lines[index]!;
7171
const fenceMatch = FENCE_PATTERN.exec(line);
72-
if (fenceMatch !== null) {
72+
// A backtick fence's info string cannot hold a backtick, so ```` ```npm test``` ```` is
73+
// inline code; read as an opener, it would flip every fence after it inside out.
74+
const opensInlineCode =
75+
openFence === null &&
76+
fenceMatch?.[1]!.startsWith("`") === true &&
77+
fenceMatch[2]!.includes("`");
78+
if (fenceMatch !== null && !opensInlineCode) {
7379
const fence = fenceMatch[1]!;
7480
// A fence closes only on the same marker, at least as long as the one that opened it,
7581
// and with nothing after it: `~~~` cannot end a ``` block, and ```` ```ts ```` is an

0 commit comments

Comments
 (0)