-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc.typ
More file actions
149 lines (133 loc) · 4.11 KB
/
src.typ
File metadata and controls
149 lines (133 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* The Code Style of source code:
+ two spaces indent
+ kebab-case names
+ type/value convert: `-to-`, `2`, type(other-type)
+ python-like concise: `)]}` will not fill lines */
#let detail(f, x) = {
x
show f: y => (y,)
x}
#let dec2hex(num) = {
let digits = "0123456789abcdef"
let hex = ""
let rem = 0
while true {
rem = calc.rem(num, 16)
hex = digits.at(rem) + hex
num = calc.quo(num, 16)
if num < 16 {
hex = digits.at(num) + hex
break}}
return hex}
#let string(content) = {
if content == none {""}
else if type(content) == str {content}
else if type(content) == array {content.map(string).join(", ")}
else if content.has("text") {content.text}
else if content.has("children") {
if content.children.len() == 0 {""}
else {content.children.map(string).join("")}}
else if content.has("child") {string(content.child)}
else if content.has("body") {string(string(content.body))}
else if content == [] {""}
else if content == [ ] {" "}
else if content.func() == ref {"_ref_"}
else {let offending = content; ""}}
#let embed-font(compose) = {
set text(font:("Libertinus Serif", "New Computer Modern",
"New Computer Modern Math", "DejaVu Sans Mono"))
compose}
#let cm-link(compose) = {
show link: x => text(blue, underline(x))
compose}
#let cm-ref(compose) = {
show ref: x => text(blue, underline(x))
compose}
#let cm-quote(compose) = {
set quote(block:true)
show quote: x => rect(
width:100%, stroke: (left: 0.5em + luma(240)),
x)
compose}
#let cm-raw(compose) = {
show raw.where(block:false): box.with(
inset:(x:3pt,y:0pt), outset:(y:3pt), radius:2pt,
fill:luma(240),)
show raw.where(block:true): x => {
block(inset:6pt, radius:2pt,
fill:luma(240),
x)}
compose}
#let common-mark(compose) = {
show: embed-font.with()
show: cm-link.with()
show: cm-ref.with()
show: cm-quote.with()
show: cm-raw.with()
compose}
#let gm-heading(compose) = {
show ref: x => {
if x.supplement != auto {
link(x.target, x.supplement)}
else if x.element.supplement != auto {
link(x.target, x.element.supplement)}
else {x}}
show heading: x => {
let id = lower(string(x).replace(
regex("[^\w\d\s]"), "").trim().replace(" ", "-"))
return [
#rect(
height:1em, width:100%, inset:0pt,
stroke:(bottom:0.5pt+luma(220)),
x.body)
#v(-2em)
#figure(kind:heading, supplement:x.body,
numbering: (..nums) => numbering("1.", ..counter(heading).get()))[]
#label(id)
#v(1em)]}
compose}
#let gm-table(compose) = {
show table.cell.where(y:0): strong
set table(
align: (x,y) => (
if y == 0 {center}
else {left+horizon}),
fill: (_,y) => if y>0 and calc.rem(y,2) == 0 {luma(250)},
stroke: 0.5pt + luma(220))
compose}
#let gm-task-list(compose) = {
let f(c, n) = {
text(c, size:1.5em, font:"DejaVu Sans Mono", str.from-unicode(n))}
show regex("(\[\s\])|(\[\])"): f(blue, 0x2610)
show regex("\[x\]"): f(green, 0x2611)
show regex("[\u{2022}\u{2023}\u{2013}]"): set text(baseline:0.35em)
show regex("[0-9]\."): set text(baseline:0.45em)
compose}
#let github-markup(compose) = {
show: common-mark.with()
show: gm-heading.with()
show: gm-table.with()
show: gm-task-list.with()
compose}
#let gm-alert(id, compose) = {
let colr = (blue, olive, purple, orange, red)
let syml = (0x2693, 0x2615, 0x2691, 0x26a0, 0x26a1).map(str.from-unicode)
let kind = "Note Tip Important Warning Caution".split()
if id not in range(0,5) {id = 0}
let (c, s, k) = (colr.at(id), syml.at(id), kind.at(id))
rect(stroke:(left: 0.2em + c))[
#text(c, size:1.6em, font:"DejaVu Sans Mono", s)
#text(c, k)\
#compose]}
#let gm-alert-diy(c:green, s:emoji.parrot, k:"Do-It-Yourself", compose) = {
rect(stroke:(left: 0.2em + c))[
#text(c, s)
#text(c, k)\
#compose]}
#let gm-color-dot(c, m:"hex") = {
box(rect(fill:luma(240))[
#if m == "rgb" [
rgb#[#c.components(alpha:false).map(i => int(i*2.55/1%))].text
] else if m == "hsl" [hsl#[#c.components(alpha:false)].text
] else [#c.to-hex()]
#box(circle(radius:0.3em, fill:c))])}