Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): keep escaped-bracket footnotes across Markdown file chunks #48228

Opensaphid(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/48228/headopened View on GitHub

Showing 2 changed files with 43 additions and 1 deletion.

x
0 of 2 viewed, 2 left
36 additions and 0 deletionspackages/shared/src/markdownChunks.test.tsModified
View file
@@ -1077,4 +1077,40 @@
expect(chunks.length).toBeGreaterThan(1);
expect(footnotes?.chunkRefs.flat()).toEqual(["b"]);
+​
+ it.each([
+ ["escaped closing bracket", "a\\]"],
+ ["escaped opening bracket", "a\\["],
+ ["escaped trailing backslash", "a\\\\"],
+ ["escaped backslash before closing bracket", "a\\\\\\]"],
+ ])("keeps a footnote label with an %s across chunks", (_kind, label) => {
+ const source = `First[^${label}] ${"lead ".repeat(900).trimEnd()}\n\n# Second\n\n[^${label}]: Escaped note`;
+ const { chunks, definitions, footnotes } = splitMarkdown(source);
+ expect(chunks).toHaveLength(2);
+ expect(footnotes?.stubs).toBe(`[^${label}]: .`);
+ expect(footnotes?.chunkRefs).toEqual([[label], []]);
+ expect(footnotes?.definitions).toBe(`[^${label}]: Escaped note`);
+ expect(prepareMarkdownChunk(chunks[0]!.text, 0, definitions, footnotes).text).toContain(
+ `[^${label}]: .`,
+ );
+ expect(buildMarkdownFootnotesSection(definitions, footnotes)?.text).toBe(
+ `[^${label}]\n\n[^${label}]: Escaped note`,
+ );
+ });
+​
+ it("honors backslash parity before a closing bracket in footnote labels", () => {
+ const padding = "lead ".repeat(900).trimEnd();
+ const oddSlash = `First[^a\\] ${padding}\n\n# Second\n\n[^a\\]: Escaped closing bracket`;
+ expect(splitMarkdown(oddSlash).footnotes).toBeUndefined();
+​