GeezerVison is showing github.com — fix(client-runtime): a line of inline triple-backtick code no longer … · pingdotgg/t3code@3808e2d
File treeExpand file treeCollapse file tree Open diff view settings packages/client-runtime/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/pullRequestMarkdown.test.ts +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -136,6 +136,28 @@ describe("pull request body segmentation", () => { | 136 | 136 | ]); | 137 | 137 | }); | 138 | 138 |
| | 139 | + it("does not open a fence on a line of inline triple-backtick code", () => { | | 140 | + const code = "```\nhttps://example.com/b.png\n```"; | | 141 | + expect( | | 142 | + splitPullRequestBody( | | 143 | + `\`\`\`npm test\`\`\` passes.\n\nhttps://example.com/demo.mp4\n\n${code}`, | | 144 | + ), | | 145 | + ).toEqual([ | | 146 | + { id: "markdown:0", kind: "markdown", text: "```npm test``` passes.", sourceOffset: 0 }, | | 147 | + { | | 148 | + id: "attachment:1", | | 149 | + kind: "attachment", | | 150 | + url: "https://example.com/demo.mp4", | | 151 | + media: "video", | | 152 | + }, | | 153 | + { id: "markdown:2", kind: "markdown", text: code, sourceOffset: 54 }, | | 154 | + ]); | | 155 | + const multilineSpan = "```foo`\nhttps://example.com/demo.mp4\nbar```"; | | 156 | + expect(splitPullRequestBody(multilineSpan)).toEqual([ | | 157 | + { id: "markdown:0", kind: "markdown", text: multilineSpan, sourceOffset: 0 }, | | 158 | + ]); | | 159 | + }); | | 160 | + | 139 | 161 | it("leaves an indented code line alone even when it is only a video link", () => { | 140 | 162 | const body = " https://example.com/demo.mp4"; | 141 | 163 | expect(splitPullRequestBody(body)).toEqual([ | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/pullRequestMarkdown.ts +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -261,7 +261,13 @@ function splitBodyAt(body: string, baseOffset: number): ReadonlyArray<PullReques | 261 | 261 | const line = lines[index]!; | 262 | 262 | if (markdown.length === 0) markdownStart = lineStart; | 263 | 263 | const fenceMatch = FENCE_PATTERN.exec(line); | 264 | | - if (fenceMatch !== null) { | | 264 | + // ```` ```npm test``` ```` is a code span, not an opener that would flip every later fence. | | 265 | + // A span that runs past this line is left an opener, so its lines stay out of media. | | 266 | + const isInlineCode = | | 267 | + openFence === null && | | 268 | + fenceMatch?.[1]![0] === "`" && | | 269 | + (fenceMatch[2]!.match(/`+/gu) ?? []).some((run) => run.length === fenceMatch[1]!.length); | | 270 | + if (fenceMatch !== null && !isInlineCode) { | 265 | 271 | const fence = fenceMatch[1]!; | 266 | 272 | // A fence closes only on the same marker, at least as long as the one that opened it, | 267 | 273 | // and with nothing after it: `~~~` cannot end a ``` block, and ```` ```ts ```` is an | |
|