Footnote references and definitions powered by the markedFootnote extension. Bidirectional linking between references and definitions.
Component Renderers
The built-in FootnoteRef and FootnoteSection components render superscript links and a numbered definition list with back-links.
Footnotes let you add references without cluttering the main text.
Here is a statement1 that needs a citation. You can also use named footnotesnote for clarity.
Multiple references2 can appear throughout the document, and they all link to the definitions at the bottom.
When documenting APIs, footnotesapi help explain edge cases without breaking the flow of the main content.
Usage
<script lang="ts">
import SvelteMarkdown from '@humanspeak/svelte-markdown'
import type { RendererComponent, Renderers }
from '@humanspeak/svelte-markdown'
import {
markedFootnote, FootnoteRef, FootnoteSection
} from '@humanspeak/svelte-markdown/extensions'
const source = 'A statement[^1] with a citation.\n\n[^1]: The citation.'
interface FootnoteRenderers extends Renderers {
footnoteRef: RendererComponent
footnoteSection: RendererComponent
}
const renderers: Partial<FootnoteRenderers> = {
footnoteRef: FootnoteRef,
footnoteSection: FootnoteSection
}
</script>
<SvelteMarkdown
{source}
extensions={[markedFootnote()]}
{renderers}
/>FootnoteRef + FootnoteSection
<!-- FootnoteRef.svelte (built-in) -->
<script lang="ts">
interface Props { id: string }
const { id }: Props = $props()
</script>
<sup class="footnote-ref">
<a href="#fn-{id}" id="fnref-{id}">{id}</a>
</sup>
<!-- FootnoteSection.svelte (built-in) -->
<script lang="ts">
interface Footnote { id: string; text: string }
interface Props { footnotes: Footnote[] }
const { footnotes }: Props = $props()
</script>
<section class="footnotes" role="doc-endnotes">
<ol>
{#each footnotes as { id, text } (id)}
<li id="fn-{id}">
<p>
{text}
<a href="#fnref-{id}"
class="footnote-backref">↩</a>
</p>
</li>
{/each}
</ol>
</section>