-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtidy-style.typ
More file actions
168 lines (163 loc) · 4.68 KB
/
Copy pathtidy-style.typ
File metadata and controls
168 lines (163 loc) · 4.68 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#import "@preview/tidy:0.4.2": styles
#import "lib.typ": note, wideblock
// #let codeblock(code) = {
// wideblock(
// reverse: true,
// {
// // #set text(size: 0.84em)
// block(stroke: 0.5pt + luma(90%), fill: white, width: 100%, inset: (y: 5pt), code)
// },
// )
// }
#let show-outline(module-doc, style-args: (:)) = {
let prefix = module-doc.label-prefix
let gen-entry(name) = {
if "enable-cross-references" in style-args and style-args.enable-cross-references {
link(label(prefix + name), raw(name, lang: "typc"))
} else {
raw(name, lang: "typc")
}
}
place(top, note(
numbering: none,
// dy: -12pt,
{
if module-doc.functions.len() > 0 {
text([Functions:], weight: "bold")
list(..module-doc.functions.map(fn => gen-entry(fn.name + "()")))
}
if module-doc.variables.len() > 0 {
text([Variables:], weight: "bold")
list(..module-doc.variables.map(var => gen-entry(var.name)))
}
},
))
}
#let show-type(type, style-args: (:)) = {
styles.default.show-type(type, style-args: style-args)
}
#let show-function(fn, style-args) = {
// codeblock(
styles.default.show-function(fn, style-args)
// )
}
#let show-variable(var, style-args) = {
// codeblock(
styles.default.show-variable(var, style-args)
// )
}
#let show-parameter-list(fn, style-args: (:)) = {
pad(
left: 10pt,
{
set text(font: ("Iosevka Term", "IBM Plex Mono", "DejaVu Sans Mono"), size: 0.85em)
let items = ()
let args = fn.args
for (name, info) in fn.args {
if style-args.omit-private-parameters and name.starts-with("_") {
continue
}
let types
if "types" in info {
types = ": " + info.types.map(x => show-type(x, style-args: style-args)).join(" ")
}
if (
style-args.enable-cross-references
and not (info.at("description", default: "") == "" and style-args.omit-empty-param-descriptions)
) {
name = link(label(style-args.label-prefix + fn.name + "." + name.trim(".")), name)
}
let display-name = if "default" in info { name } else { sym.chevron.l + name + sym.chevron.r }
items.push(display-name + types)
}
layout(size => {
let name = text(fn.name, fill: style-args.colors.at("signature-func-name", default: rgb("#4b69c6")))
let params = items.join(", ")
let return-types = if "return-types" in fn and fn.return-types != none {
" → "
fn.return-types.map(x => show-type(x, style-args: style-args)).join(" ")
}
let x = measure({
name
"("
params
")"
return-types
}).width
if x > size.width {
name
"(\n "
items.join(",\n ")
"\n)"
return-types
} else {
name
"("
params
")"
return-types
}
})
// items.join(if inline-args { ", " } else { ",\n " })
// if not inline-args { "\n" } + ")"
// if "return-types" in fn and fn.return-types != none {
// " → "
// fn.return-types.map(x => show-type(x, style-args: style-args)).join(" ")
// }
},
)
}
#let show-parameter-block(
function-name: none,
name,
types,
content,
style-args,
show-default: false,
default: none,
) = block(
inset: (top: 10pt),
// stroke: (top: 1pt + luma(90%)),
width: 100%,
breakable: style-args.break-param-descriptions,
layout(size => {
let title = {
let display-name = if show-default { name } else { sym.chevron.l + name + sym.chevron.r }
[#box(heading(level: style-args.first-heading-level + 3, raw(display-name)))#if (
function-name != none and style-args.enable-cross-references
) { label(function-name + "." + name.trim(".")) }]
if show-default {
raw(": ")
raw(lang: "typc", default)
}
h(1.2em)
types.map(x => (style-args.style.show-type)(x, style-args: style-args)).join([ #text("or", size: .8em) ])
// #if show-default {
// h(1.2em)
// // text(size: .8em)[#style-args.local-names.default:]
// // [ ]
// "("
// raw(lang: "typc", default)
// ")"
// }
if not show-default {
h(1.2em)
text("Positional", size: .8em)
}
h(1.8em)
}
let t = measure(title).width
let c = measure(content).width
if size.width >= t + c {
title
content
} else {
title
parbreak()
content
}
}),
)
#let show-reference(label, name, style-args: (:)) = {
styles.default.show-reference(label, name, style-args: style-args)
}