Skip to content

Commit

Permalink
feat: disable heading hash in code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Dec 4, 2024
1 parent c07cbe1 commit 4a9976d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
8 changes: 7 additions & 1 deletion src/mod.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import "/typ/templates/term.typ": _term
#import "/typ/templates/side-notes.typ": side-note, side-attrs
#import "/typ/templates/page.typ": main-color, get-page-width
#import "/typ/templates/template-link.typ": enable-heading-hash

#import "/typ/typst-meta/docs.typ": typst-v11

Expand Down Expand Up @@ -111,15 +112,20 @@
rect(
width: 100%,
inset: 10pt,
{
context {
// Don't corrupt normal headings
set heading(outlined: false)

let prev = enable-heading-hash.get()
enable-heading-hash.update(false)

if res != none {
res
} else {
eval(cc.text, mode: "markup", scope: scope)
}

enable-heading-hash.update(prev)
},
)
}
Expand Down
30 changes: 15 additions & 15 deletions typ/templates/template-link.typ
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@

#let heading-reference(it, d: 1) = make-unique-label(it.body, disambiguator: d)

#let enable-heading-hash = state("enable-heading-hash", true)

#let heading-hash(it, hash-color: blue) = {
let title = plain-text(it.body)
if title != none {
let title = title.trim()
update-label-disambiguator(title)
context (
{
let loc = here()
let dest = get-label-disambiguator(loc, title)
let h = measure(it.body).height
place(
left,
dx: -16pt,
[
#set text(fill: hash-color)
#link(loc)[\#] #dest
],
)
}
)
context if enable-heading-hash.get() {
let loc = here()
let dest = get-label-disambiguator(loc, title)
let h = measure(it.body).height
place(
left,
dx: -16pt,
[
#set text(fill: hash-color)
#link(loc)[\#] #dest
],
)
}
}
}

0 comments on commit 4a9976d

Please sign in to comment.