Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): keep footnotes with nonbreaking spaces linked in long Markdown files #49083 (GitHub #49077)

Mergedpeakoshi(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/49077/headmerged by juliusmarminge View on GitHub

Showing 2 changed files with 5 additions and 3 deletions.

x
0 of 2 viewed, 2 left
1 addition and 0 deletionspackages/shared/src/markdownChunks.test.tsModified
View file
@@ -959,6 +959,7 @@
{ firstLabel: "ς", secondLabel: "Σ", definitionLabel: "σ" },
{ firstLabel: "ß", secondLabel: "ẞ", definitionLabel: "ss" },
{ firstLabel: "ı", secondLabel: "I", definitionLabel: "i" },
+ { firstLabel: "a\u00a0b", secondLabel: "a\u00a0b", definitionLabel: "a\u00a0b" },
])(
"matches footnote citations $firstLabel and $secondLabel to $definitionLabel across chunks",
({ firstLabel, secondLabel, definitionLabel }) => {
4 additions and 3 deletionspackages/shared/src/markdownChunks.tsModified
View file
@@ -217,7 +217,8 @@
// Definitions past this are not repeated into every piece; their parse cost would outweigh links.
const SHARED_DEFINITIONS_MAX_CHARS = 16 * 1024;
const SHARED_FOOTNOTES_MAX_CHARS = 64 * 1024;
-const FOOTNOTE_DEFINITION_START = /^ {0,3}\[\^((?:[^\s\\[\]]|\\.)+)\]:/;
+// Like micromark, labels end only at ASCII space, tab or line endings; other whitespace is part of them.
+const FOOTNOTE_DEFINITION_START = /^ {0,3}\[\^((?:[^ \t\n\r\\[\]]|\\[^\r\n])+)\]:/;
const FOOTNOTE_CONTINUATION_INDENT = /^(?: {4}| {0,3}\t)/;
// Quote and list markers before a line's content; a definition after them belongs to a container.
const CONTAINER_MARKERS = /^(?: {0,3}(?:>[ \t]?|(?:[-*+]|\d{1,9}[.)])[ \t]+))+/;
@@ -432,7 +433,7 @@
​
// Quote, list and footnote openers before a line's content, so a nested definition label shows.
const CONTAINED_PREFIX =
- /^(?:[ \t]*(?:>|[-*+](?=[ \t])|\d{1,9}[.)](?=[ \t])|\[\^(?:[^\s\\[\]]|\\.)+\]:))*[ \t]*/;
+ /^(?:[ \t]*(?:>|[-*+](?=[ \t])|\d{1,9}[.)](?=[ \t])|\[\^(?:[^ \t\n\r\\[\]]|\\[^\r\n])+\]:))*[ \t]*/;
const containedContent = (line: string) => line.slice(CONTAINED_PREFIX.exec(line)![0].length);