main
1#import "@preview/bullseye:0.1.0": show-target
2
3#import "../utils/slugger.typ": slugger
4#import "../utils/to-string.typ": to-string
5
6#let auto-reslugify-headings(body) = {
7 let headings-slug-record = state("headings-slug-record", (:))
8
9 context {
10 if headings-slug-record.get().len() == 0 {
11 let slugs = slugger(query(heading).map(h => to-string(h.body)))
12 headings-slug-record.update(slugs)
13 }
14 }
15
16 show heading: it => context {
17 let slugs = headings-slug-record.get()
18 let idx = query(heading).position(h => h == it)
19 html.elem(
20 "h" + str(it.level + 1),
21 attrs: (id: slugs.at(idx)),
22 it.body,
23 )
24 }
25
26 body
27}
28
29#let heading-template-html(body) = {
30 show heading: auto-reslugify-headings
31
32 body
33}
34
35#let heading-template-paged(body) = {
36 // TODO: Headings style in PDF target
37
38 body
39}
40
41#let heading-template(body) = {
42 show: show-target(paged: heading-template-paged, html: heading-template-html)
43
44 body
45}