-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.typ
More file actions
97 lines (96 loc) · 3.69 KB
/
Copy pathcode.typ
File metadata and controls
97 lines (96 loc) · 3.69 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
#let code(
caption: none, // content of caption bubble (string, none)
bgcolor: rgb("#fefae0"), // back ground color (color)
strokecolor: 1pt + maroon, // frame color (color)
hlcolor: auto, // color to use for highlighted lines (auto, color)
width: 100%,
radius: 3pt,
inset: 5pt,
numbers: false, // show line numbers (boolean)
stepnumber: 1, // only number lines divisible by stepnumber (integer)
numberfirstline: false, // if the firstline isn't divisible by stepnumber, force it to be numbered anyway (boolean)
numberstyle: auto, // style function to apply to line numbers (auto, style)
firstnumber: 1, // number of the first line (integer)
highlight: none, // line numbers to highlight (none, array of integer)
content
) = {
if type(hlcolor) == "auto" {
hlcolor = bgcolor.darken(10%)
}
if type(highlight) == "none" {
highlight = ()
}
block(
width: width,
fill: bgcolor,
stroke: strokecolor,
radius: radius,
inset: inset,
clip: false,
{
// Draw the caption bubble if a caption was set
if caption != none {
style(styles => {
let caption_block = block(width: auto,
inset: inset,
radius: radius,
fill: bgcolor,
stroke: strokecolor,
h(.5em) + caption + h(.5em))
place(
top + left,
dx: 0em,
dy: -(measure(caption_block, styles).height / 2 + inset),
caption_block
)
})
// skip some vertical space to avoid the caption overlapping with
// the beginning of the content
v(.6em)
}
let (columns, align, make_row) = {
if numbers {
// line numbering requested
if type(numberstyle) == "auto" {
numberstyle = text.with(style: "italic",
slashed-zero: true,
size: .6em)
}
( ( auto, 1fr ),
( right + horizon, left ),
e => {
let (i, l) = e
let n = i + firstnumber
let n_str = if (calc.rem(n, stepnumber) == 0) or (numberfirstline and i == 0) { numberstyle(str(n)) } else { none }
(n_str + h(0em), raw(lang: content.lang, l))
}
)
} else {
( ( 1fr, ),
( left, ),
e => {
let (i, l) = e
raw( lang:content.lang, l)
}
)
}
}
table(
stroke:none,
columns: columns,
rows: (auto,),
gutter: 0pt,
inset: 2pt,
align: (col, _) => align.at(col),
fill: (c, row) => if (row / 2 + firstnumber) in highlight { hlcolor } else { none },
..content
.text
.split("\n")
.enumerate()
.map(make_row)
.flatten()
.map(c => if c.has("text") and c.text == "" { v(1em) } else { c })
)
}
)
}