diff --git a/deps.ts b/deps.ts index 7199448..5b06b26 100644 --- a/deps.ts +++ b/deps.ts @@ -13,6 +13,8 @@ export { default as GitHubSlugger } from "https://esm.sh/github-slugger@2.0.0?pi export { default as markedAlert } from "https://esm.sh/marked-alert@2.0.1?pin=v135"; +export { default as markedFootnote } from "https://esm.sh/marked-footnote@1.2.2?pin=v135"; + export { gfmHeadingId } from "https://esm.sh/marked-gfm-heading-id@3.1.2?pin=v135"; export { default as Prism } from "https://esm.sh/prismjs@1.29.0?pin=v135"; diff --git a/mod.ts b/mod.ts index 4027e82..b7f852c 100644 --- a/mod.ts +++ b/mod.ts @@ -6,6 +6,7 @@ import { katex, Marked, markedAlert, + markedFootnote, Prism, sanitizeHtml, } from "./deps.ts"; @@ -14,6 +15,7 @@ export { CSS, KATEX_CSS, Marked }; Marked.marked.use(markedAlert()); Marked.marked.use(gfmHeadingId()); +Marked.marked.use(markedFootnote()); const slugger = new GitHubSlugger(); diff --git a/test/fixtures/footnote.html b/test/fixtures/footnote.html new file mode 100644 index 0000000..93533be --- /dev/null +++ b/test/fixtures/footnote.html @@ -0,0 +1,42 @@ +

Here is a simple footnote1. With some additional text after it2 and +without disrupting the blocks3.

+
+

Footnotes

+
    +
  1. +

    This is a footnote content.

    +
  2. +
  3. +

    A footnote on the label: "@#$%".

    +
  4. +
  5. +

    The first paragraph of the definition.

    +

    Paragraph two of the definition.

    +
    +

    A blockquote with +multiple lines.

    +
    +
    a code block
    + + + + + + + + + + +
    Header 1Header 2
    Cell 1Cell 2
    +

    A `final` paragraph before list.

    +
      +
    • Item 1
    • +
    • Item 2
        +
      • Subitem 1
      • +
      • Subitem 2
      • +
      +
    • +
    +
  6. +
+
diff --git a/test/fixtures/footnote.md b/test/fixtures/footnote.md new file mode 100644 index 0000000..f431fec --- /dev/null +++ b/test/fixtures/footnote.md @@ -0,0 +1,28 @@ +[^1]: This is a footnote content. + +Here is a simple footnote[^1]. With some additional text after it[^@#$%] and +without disrupting the blocks[^bignote]. + +[^bignote]: The first paragraph of the definition. + + Paragraph two of the definition. + + > A blockquote with + > multiple lines. + + ~~~ + a code block + ~~~ + + | Header 1 | Header 2 | + | -------- | -------- | + | Cell 1 | Cell 2 | + + A \`final\` paragraph before list. + + - Item 1 + - Item 2 + - Subitem 1 + - Subitem 2 + +[^@#$%]: A footnote on the label: "@#$%". diff --git a/test/test.ts b/test/test.ts index d82c661..41d8f97 100644 --- a/test/test.ts +++ b/test/test.ts @@ -325,3 +325,11 @@ Deno.test("basic md table with dollar signs", () => { const expected = Deno.readTextFileSync("./test/fixtures/basic_md_table.html"); assertEquals(html, expected); }); + +Deno.test("footnotes", () => { + const markdown = Deno.readTextFileSync("./test/fixtures/footnote.md"); + const expected = Deno.readTextFileSync("./test/fixtures/footnote.html"); + + const html = render(markdown); + assertEquals(html, expected); +});