From 209f0a11522960351acb63ec424dfdf77e033308 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 8 Sep 2023 17:35:11 +0200 Subject: [PATCH] added footnote support closes #1 --- server/public/index.html | 19 ++++++++++++++++++- test-vault/Cool Test Note.md | 10 +++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/server/public/index.html b/server/public/index.html index d16f6b7..00eafd4 100644 --- a/server/public/index.html +++ b/server/public/index.html @@ -14,6 +14,7 @@ + @@ -46,9 +47,25 @@ placement: "after", ariaHidden: true }), - // prepend current file id to the anchor permalink (see getId) + // prepend current file id to the anchor permalink slugify: s => `${getId() ?? ""}-${encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, "-").replace(/[^A-Za-z0-9_-]/g, ""))}` }); + md.use(markdownitFootnote); + + let rulesToReplace = [ + // prepend current file id to footnotes + ["footnote_ref", [/href="#(fn\d+)"/, `href="#${getId() ?? ""}-$1"`]], + ["footnote_open", [/id="(fn\d+)"/, `id="${getId() ?? ""}-$1"`]], + // prepend current file id to footnote refs + ["footnote_ref", [/id="(fnref\d+)"/, `id="${getId() ?? ""}-$1"`]], + ["footnote_anchor", [/href="#(fnref\d+)"/, `href="#${getId() ?? ""}-$1"`]] + ]; + for (let replacement of rulesToReplace) { + let prevRule = md.renderer.rules[replacement[0]]; + md.renderer.rules[replacement[0]] = (tokens, idx, options, env, self) => { + return prevRule(tokens, idx, options, env, self).replace(...replacement[1]); + }; + } let main = $("#main"); $(window).on("hashchange", display); diff --git a/test-vault/Cool Test Note.md b/test-vault/Cool Test Note.md index f998c79..d2c040e 100644 --- a/test-vault/Cool Test Note.md +++ b/test-vault/Cool Test Note.md @@ -35,9 +35,9 @@ you know WITH A LOT OF TEXT %% -blah blah i added and removed this +blah blah i added and[^text] removed this[^1] -The following is $x^2 = 7$, but more complicated! +The following is $x^2 = 7$, but more^[Inline footnote!] complicated! $$ x^2 + \sum_{i = 1}^{10000} x^2 \cdot 0 = 7 $$ @@ -52,4 +52,8 @@ wikilink image! ![[Pasted image 20230816130420.png]] -nice \ No newline at end of file +nice + +[^1]: Normal footnote! + +[^text]: Text footnote! \ No newline at end of file