GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): indented tilde lines no longer open a code fence · pingdotgg/t3code@52afcab

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • markdownLinks.test.ts
    • markdownLinks.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/shared/src/markdownLinks.test.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.test.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ describe("extractInlineCodeSpans", () => {
258258
["./a/shared.ts", "./b/shared.ts"],
259259
],
260260
["- ```\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"]],
261263
])("skips fenced code blocks without breaking inline spans in %j", (markdown, spans) => {
262264
expect(extractInlineCodeSpans(markdown)).toEqual(spans);
263265
});
Collapse file

‎packages/shared/src/markdownLinks.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/markdownLinks.ts
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ function parseFilePathLink(path: string, hash: string): FilePathPosition | null
471471
}
472472

473473
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]*)/;
475475

476476
const BACKTICK_RUN_PATTERN = /`+/g;
477477

@@ -480,8 +480,9 @@ export function extractInlineCodeSpans(text: string): string[] {
480480
const spans: string[] = [];
481481
let openFence: { marker: string; prefix: string } | null = null;
482482
for (const line of text.split("\n")) {
483-
const [, prefix = "", marker = "", rest = ""] =
483+
const [, containers = "", indent = "", marker = "", rest = ""] =
484484
(line.includes("```") || line.includes("~~~") ? CODE_FENCE_PATTERN.exec(line) : null) ?? [];
485+
const prefix = containers + indent;
485486
if (openFence) {
486487
if (
487488
marker[0] === openFence.marker[0] &&
@@ -496,7 +497,10 @@ export function extractInlineCodeSpans(text: string): string[] {
496497
}
497498
continue;
498499
}
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("`"))) {
500504
openFence = { marker, prefix };
501505
continue;
502506
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.