-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29189a5
commit 856e334
Showing
9 changed files
with
164 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
#import "supports-text.typ": plain-text | ||
|
||
#let make-unique-label(it, disambiguator: 1) = label({ | ||
let k = plain-text(it).trim() | ||
if disambiguator > 1 { | ||
k + "_d" + str(disambiguator) | ||
} else { | ||
k | ||
} | ||
}) | ||
|
||
#let label-disambiguator = state("label-disambiguator", (:)) | ||
#let update-label-disambiguator(k) = label-disambiguator.update(it => { | ||
it.insert(k, it.at(k, default: 0) + 1) | ||
it | ||
}) | ||
#let get-label-disambiguator(loc, k) = make-unique-label(k, disambiguator: label-disambiguator.at(loc).at(k)) | ||
|
||
#let heading-reference(it, d: 1) = make-unique-label(it.body, disambiguator: d) | ||
|
||
#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: -20pt, | ||
[ | ||
#set text(fill: hash-color) | ||
#link(loc)[\#] #dest | ||
], | ||
) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
#import "sys.typ": target | ||
|
||
#let book-theme-from(preset, xml: xml, target: target) = { | ||
// todo: move theme style parser to another lib file | ||
let theme-target = if target.contains("-") { | ||
target.split("-").at(1) | ||
} else { | ||
"light" | ||
} | ||
let theme-style = preset.at(theme-target) | ||
|
||
let is-dark-theme = theme-style.at("color-scheme") == "dark" | ||
let is-light-theme = not is-dark-theme | ||
|
||
let main-color = rgb(theme-style.at("main-color")) | ||
let dash-color = rgb(theme-style.at("dash-color")) | ||
|
||
let code-theme-file = theme-style.at("code-theme") | ||
|
||
let code-extra-colors = if code-theme-file.len() > 0 { | ||
let data = xml(theme-style.at("code-theme")).first() | ||
|
||
let find-child(elem, tag) = { | ||
elem.children.find(e => "tag" in e and e.tag == tag) | ||
} | ||
|
||
let find-kv(elem, key, tag) = { | ||
let idx = elem.children.position(e => "tag" in e and e.tag == "key" and e.children.first() == key) | ||
elem.children.slice(idx).find(e => "tag" in e and e.tag == tag) | ||
} | ||
|
||
let plist-dict = find-child(data, "dict") | ||
let plist-array = find-child(plist-dict, "array") | ||
let theme-setting = find-child(plist-array, "dict") | ||
let theme-setting-items = find-kv(theme-setting, "settings", "dict") | ||
let background-setting = find-kv(theme-setting-items, "background", "string") | ||
let foreground-setting = find-kv(theme-setting-items, "foreground", "string") | ||
(bg: rgb(background-setting.children.first()), fg: rgb(foreground-setting.children.first())) | ||
} else { | ||
(bg: rgb(239, 241, 243), fg: none) | ||
} | ||
|
||
|
||
( | ||
style: theme-style, | ||
is-dark: is-dark-theme, | ||
is-light: is-light-theme, | ||
main-color: main-color, | ||
dash-color: dash-color, | ||
code-extra-colors: code-extra-colors, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#import "template-link.typ": * | ||
#import "template-theme.typ": * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters