Skip to content

Commit e10a9c5

Browse files
committed
Sanitize captions
1 parent bcd0e5d commit e10a9c5

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

jacow.typ

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,15 @@
119119
let titlenotenumbering(i) = {
120120
if i < 6 { ("*", "#", "§", "", "").at(i - 1) } else { (i - 4) * "*" }
121121
}
122-
122+
123123
/// Remove white space at begin and end
124124
let strip-white-space(content) = {
125-
if (content.has("children")){
125+
if (content.has("children")) {
126126
let clean = content.children
127-
for i in (0, -1){
128-
while (clean.len() > 0 and repr(clean.at(i).func()) in ("space", "parbreak")) {
127+
for i in (0, -1) {
128+
while (
129+
clean.len() > 0 and repr(clean.at(i).func()) in ("space", "parbreak")
130+
) {
129131
_ = clean.remove(i)
130132
}
131133
}
@@ -137,7 +139,7 @@
137139

138140
/// Check if content ends with string
139141
let ends-with(content, end) = {
140-
if (content.has("children")){
142+
if (content.has("children")) {
141143
return ends-with(content.children.filter(c => c.has("text")).last(), end)
142144
} else if (content.has("text")) {
143145
return content.text.clusters().at(-1).ends-with(end)
@@ -555,12 +557,12 @@
555557
set par(first-line-indent: 0em)
556558
layout(size => context {
557559
let body = strip-white-space(it.body) // removes trailing whitespace
558-
if (it.kind == table){
560+
if (it.kind == table) {
559561
// table captions take the form of a heading (word caps)
560562
body = wordcaps(body)
561563
} else {
562564
// figure captions must end with a period
563-
if (not ends-with(body, ".")){ body += "."}
565+
if (not ends-with(body, ".")) { body += "." }
564566
}
565567
let caption = [#it.supplement #it.counter.display()#it.separator#body]
566568
align(

tests/captions/ref/1.png

1.25 KB
Loading

tests/captions/test.typ

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#figure(
1818
box(fill: silver, width: 100%, height: 1cm),
1919
caption: [
20-
20+
2121
Medium caption with two lines, spanning the entire width and left aligned
22-
22+
2323
],
2424
)
2525

@@ -39,7 +39,7 @@
3939
table(columns: (1fr, 1fr, 1fr))[M],
4040
caption: [
4141
Medium caption with two lines, spanning the entire width and left aligned
42-
42+
4343
],
4444
)
4545

0 commit comments

Comments
 (0)