-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtidy-style.typ
More file actions
135 lines (132 loc) · 3.83 KB
/
Copy pathtidy-style.typ
File metadata and controls
135 lines (132 loc) · 3.83 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
#import "@preview/tidy:0.4.2": styles
#let show-outline(module-doc, style-args: (:)) = {
styles.default.show-outline(module-doc, style-args: style-args)
}
#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)
}