Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): keep footnotes in GFM tables after unmatched backticks #48263

Opensaphid(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/48263/headopened View on GitHub

Showing 2 changed files with 133 additions and 0 deletions (loading 1).

x
0 of 2 viewed, 2 left
133 additions and 0 deletionspackages/shared/src/markdownChunks.test.tsModified
View file
@@ -2,6 +2,7 @@
​
import { toHtml } from "hast-util-to-html";
import remarkGfm from "remark-gfm";
+import remarkMath from "remark-math";
import remarkParse from "remark-parse";
import remarkRehype from "remark-rehype";
import { unified } from "unified";
@@ -1031,6 +1032,138 @@
expect(section.startsWith("[^a] [^b]\n\n")).toBe(true);
+ it.each([
+ ["across rows", "| a | b |\n| --- | --- |\n| `unclosed | x |\n| [^1] | ` |"],
+ ["across header cells", "| ` | [^1] | ` |\n| --- | --- | --- |"],
+ ["with an escaped pipe inside code", "| a | b |\n| --- | --- |\n| `a\\|[^2]` | [^1] |"],
+ ])("matches GFM table footnotes %s", (_name, table) => {
+ const filler = "filler paragraph text.\n\n".repeat(10);
+ const text = `${filler}${table}\n\n${filler}[^1]: note\n[^2]: hidden\n`;
+ const parser = unified().use(remarkParse).use(remarkGfm).use(remarkRehype);
+ const render = (source: string) => toHtml(parser.runSync(parser.parse(source)));
+ const reference = 'href="#user-content-fn-1"';
+ expect(render(text)).toContain(reference);
+ expect(render(text)).not.toContain('href="#user-content-fn-2"');
+​
+ const { chunks, definitions, footnotes } = splitMarkdown(text, 100);
+ expect(chunks.length).toBeGreaterThan(1);
+ expect(footnotes?.chunkRefs.flat()).toEqual(["1"]);
+ const tableIndex = chunks.findIndex((chunk) => chunk.text.includes(table));