GeezerVison is showing github.com — fix(shared): indented tilde lines no longer open a code fence · pingdotgg/t3code@52afcab
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.test.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -258,6 +258,8 @@ describe("extractInlineCodeSpans", () => { | 258 | 258 | ["./a/shared.ts", "./b/shared.ts"], | 259 | 259 | ], | 260 | 260 | ["- ```\n `./a/shared.ts`\n ```\nEdit `./b/shared.ts`", ["./b/shared.ts"]], | | 261 | + [" ~~~\n\nEdit `./a/shared.ts` and `./b/shared.ts`", ["./a/shared.ts", "./b/shared.ts"]], | | 262 | + ["> ~~~\n> `./a/shared.ts`\n> ~~~\nEdit `./b/shared.ts`", ["./b/shared.ts"]], | 261 | 263 | ])("skips fenced code blocks without breaking inline spans in %j", (markdown, spans) => { | 262 | 264 | expect(extractInlineCodeSpans(markdown)).toEqual(spans); | 263 | 265 | }); | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.ts +7-3Lines changed: 7 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -471,7 +471,7 @@ function parseFilePathLink(path: string, hash: string): FilePathPosition | null | 471 | 471 | } | 472 | 472 |
| 473 | 473 | const CODE_FENCE_PATTERN = | 474 | | - /^((?:[ \t]*(?:>|[-*+](?=[ \t])|\d{1,9}[.)](?=[ \t])))*[ \t]*)(`{3,}|~{3,})([^\n]*)/; | | 474 | + /^((?:[ \t]*(?:>|[-*+](?=[ \t])|\d{1,9}[.)](?=[ \t])))*)([ \t]*)(`{3,}|~{3,})([^\n]*)/; | 475 | 475 |
| 476 | 476 | const BACKTICK_RUN_PATTERN = /`+/g; | 477 | 477 |
| @@ -480,8 +480,9 @@ export function extractInlineCodeSpans(text: string): string[] { | 480 | 480 | const spans: string[] = []; | 481 | 481 | let openFence: { marker: string; prefix: string } | null = null; | 482 | 482 | for (const line of text.split("\n")) { | 483 | | - const [, prefix = "", marker = "", rest = ""] = | | 483 | + const [, containers = "", indent = "", marker = "", rest = ""] = | 484 | 484 | (line.includes("```") || line.includes("~~~") ? CODE_FENCE_PATTERN.exec(line) : null) ?? []; | | 485 | + const prefix = containers + indent; | 485 | 486 | if (openFence) { | 486 | 487 | if ( | 487 | 488 | marker[0] === openFence.marker[0] && | @@ -496,7 +497,10 @@ export function extractInlineCodeSpans(text: string): string[] { | 496 | 497 | } | 497 | 498 | continue; | 498 | 499 | } | 499 | | - if (marker && (marker[0] === "~" || !rest.includes("`"))) { | | 500 | + // Deeper indentation is indented code, except inside a list item, which is not tracked here; | | 501 | + // only tilde openers are held to it so backtick fences keep their old behaviour there. | | 502 | + const tildeIsIndentedCode = indent.replaceAll("\t", " ").length > (containers ? 4 : 3); | | 503 | + if (marker && (marker[0] === "~" ? !tildeIsIndentedCode : !rest.includes("`"))) { | 500 | 504 | openFence = { marker, prefix }; | 501 | 505 | continue; | 502 | 506 | } | |
|