Commit f264aba
Changed files (2)
src
contents
_lib
templates
src/contents/_lib/templates/heading.typ
@@ -0,0 +1,27 @@
+#import "../utils/slugger.typ": slugger
+
+#let auto-reslugify-headings(body) = {
+ let headings-slug-record = state("headings-slug-record", (:))
+ show heading: it => context {
+ let record = headings-slug-record.get()
+ let ((slug,), record) = slugger(it.body, record: record)
+ slug = "heading-" + slug
+ headings-slug-record.update(record)
+
+ if target() == "html" {
+ html.elem(
+ "h" + str(it.level + 1),
+ attrs: (id: slug),
+ it.body,
+ )
+ }
+ }
+
+ body
+}
+
+#let heading-template(body) = {
+ show: auto-reslugify-headings
+
+ body
+}
src/contents/_lib/lib.typ
@@ -3,11 +3,13 @@
#import mathyml: to-mathml
#import mathyml.prelude: *
+#import "./templates/heading.typ": heading-template
#import "./templates/footnote.typ": footnote-template
#let post-template(body) = {
show math.equation: to-mathml
+ show: heading-template
show: footnote-template
body