Commit 5e12e9c

HPCesia <me@hpcesia.com>
2026-02-09 12:29:14
Refactor the structure of typst templates
1 parent 0217709
Changed files (2)
src
contents
_lib
src/contents/_lib/templates/footnote.typ
@@ -0,0 +1,30 @@
+#let side-footnote(body) = {
+  show footnote: it => {
+    if target() == "html" {
+      let number = counter(footnote).display(it.numbering)
+      let fn-id = "fn-" + number
+      let ref-id = "fnref-" + number
+
+      html.sup(
+        html.a(
+          href: "#" + fn-id,
+          id: ref-id,
+          number,
+        ),
+      )
+      html.span(
+        class: "marginnote",
+        id: fn-id,
+        html.sup(html.a(href: "#" + ref-id, number)) + [ ] + it.body,
+      )
+    }
+  }
+
+  body
+}
+
+#let footnote-template(body) = {
+  show: side-footnote
+
+  body
+}
src/contents/_lib/lib.typ
@@ -3,26 +3,12 @@
 #import mathyml: to-mathml
 #import mathyml.prelude: *
 
+#import "./templates/footnote.typ": footnote-template
+
 #let post-template(body) = {
   show math.equation: to-mathml
-  show footnote: it => {
-    if target() == "html" {
-      let number = counter(footnote).display(it.numbering)
-      let fn-id = "fn-" + number
-      let ref-id = "fnref-" + number
 
-      html.sup(html.a(
-        href: "#" + fn-id,
-        id: ref-id,
-        number,
-      ))
-      html.span(
-        class: "marginnote",
-        id: fn-id,
-        html.sup(html.a(href: "#" + ref-id, number)) + [ ] + it.body,
-      )
-    }
-  }
+  show: footnote-template
 
   body
 }