From 430a890a17910593e26e9654b141ef3855ecceac Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Mon, 27 Jul 2026 21:45:48 +0530 Subject: [PATCH] feat(markdown): support footnotes --- docs/en/guide/markdown.md | 16 ++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 14 ++++++++++++++ .../theme-default/styles/components/vp-doc.css | 13 +++++++++++++ src/node/markdown/markdown.ts | 11 +++++++++++ 5 files changed, 55 insertions(+) diff --git a/docs/en/guide/markdown.md b/docs/en/guide/markdown.md index 76e7fcbb..03efe4d6 100644 --- a/docs/en/guide/markdown.md +++ b/docs/en/guide/markdown.md @@ -115,6 +115,22 @@ For more details, see [Frontmatter](../reference/frontmatter-config). - [ ] Write the press release - [x] Update the website +## Footnotes + +**Input** + +```md +Footnotes are supported[^1], including inline ones^[This is an inline footnote.]. + +[^1]: Definitions can contain **markdown** and are rendered at the end of the page. +``` + +**Output** + +Footnotes are supported[^1], including inline ones^[This is an inline footnote.]. + +[^1]: Definitions can contain **markdown** and are rendered at the end of the page. + ## Emoji :tada: **Input** diff --git a/package.json b/package.json index 1089fce5..6540d490 100644 --- a/package.json +++ b/package.json @@ -131,6 +131,7 @@ "@mdit/plugin-attrs": "^1.0.2", "@mdit/plugin-container": "^1.0.1", "@mdit/plugin-emoji": "^1.1.0", + "@mdit/plugin-footnote": "^1.0.1", "@mdit/plugin-tasklist": "^1.0.1", "@polka/compression": "^1.0.0-next.28", "@rolldown/pluginutils": "^1.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index adce5c77..8a006f5d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,6 +105,9 @@ importers: '@mdit/plugin-emoji': specifier: ^1.1.0 version: 1.1.0(markdown-it@14.3.0) + '@mdit/plugin-footnote': + specifier: ^1.0.1 + version: 1.0.1(markdown-it@14.3.0) '@mdit/plugin-tasklist': specifier: ^1.0.1 version: 1.0.1(markdown-it@14.3.0) @@ -665,6 +668,12 @@ packages: markdown-it: optional: true + '@mdit/plugin-footnote@1.0.1': + resolution: {integrity: sha512-PrH02dlVQT8/vPvfGrLHpcHq8N0+gOaAVNOfuhwlPqWCL4He3o+buUCxm1Uem02+UR8/TRBW50M/XD/dVSe2jw==} + engines: {node: '>=22'} + peerDependencies: + markdown-it: ^14.2.0 + '@mdit/plugin-tasklist@1.0.1': resolution: {integrity: sha512-Ks/Tihw5ibbkP2qOZzltkbiTk8RfpxDRvqdn4hl1wIs3VmeKITIQ36gN4DsuotSauA9SBe/mL0QJIfuSCrXqrw==} engines: {node: '>=22'} @@ -3117,6 +3126,11 @@ snapshots: optionalDependencies: markdown-it: 14.3.0 + '@mdit/plugin-footnote@1.0.1(markdown-it@14.3.0)': + dependencies: + '@types/markdown-it': 14.1.2 + markdown-it: 14.3.0 + '@mdit/plugin-tasklist@1.0.1(markdown-it@14.3.0)': dependencies: '@types/markdown-it': 14.1.2 diff --git a/src/client/theme-default/styles/components/vp-doc.css b/src/client/theme-default/styles/components/vp-doc.css index 24c37d40..86f49bb6 100644 --- a/src/client/theme-default/styles/components/vp-doc.css +++ b/src/client/theme-default/styles/components/vp-doc.css @@ -197,6 +197,19 @@ accent-color: var(--vp-c-brand-1); } +/** + * Footnotes + * -------------------------------------------------------------------------- */ + +.vp-doc .footnote-ref a, +.vp-doc .footnote-backref { + text-decoration: none; +} + +.vp-doc .footnotes { + font-size: 14px; +} + /** * Table * -------------------------------------------------------------------------- */ diff --git a/src/node/markdown/markdown.ts b/src/node/markdown/markdown.ts index 18a42fe2..2ee2a62c 100644 --- a/src/node/markdown/markdown.ts +++ b/src/node/markdown/markdown.ts @@ -20,6 +20,7 @@ import { type MarkdownItAttrsOptions } from '@mdit/plugin-attrs' import { fullEmoji as emojiPlugin } from '@mdit/plugin-emoji' +import { footnote as footnotePlugin } from '@mdit/plugin-footnote' import { tasklist as tasklistPlugin, type MarkdownItTaskListOptions @@ -227,6 +228,13 @@ export interface MarkdownOptions extends MarkdownItAsyncOptions { * @see https://mdit-plugins.github.io/tasklist.html */ tasklist?: MarkdownItTaskListOptions | boolean + /** + * Whether to enable footnotes (`[^1]` references with definitions, plus + * inline `^[note]` syntax). + * @default true + * @see https://mdit-plugins.github.io/footnote.html + */ + footnote?: boolean /** * Improves emphasis (`**bold**`) handling in Japanese, Chinese, and * Korean text. @@ -426,6 +434,9 @@ export async function createMarkdownRenderer( if (options.tasklist !== false) { tasklistPlugin(md, normalizePluginOptions(options.tasklist)) } + if (options.footnote !== false) { + footnotePlugin(md) + } if (options.cjkFriendlyEmphasis !== false) { mditCjkFriendly(md) }