Skip to content

Commit 3fff6de

Browse files
committed
fix: break long Typst filenames at separators first
1 parent 9eea8ad commit 3fff6de

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎src/resources/formats/typst/pandoc/quarto/definitions.typ‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@
6060
}
6161

6262
#let quarto-code-filename(filename, body) = {
63-
// Long names without break points would be clipped, so allow a break anywhere
64-
let filename = if type(filename) == str and filename.len() > 60 {
65-
filename.clusters().join(sym.zws)
63+
// Long names would be clipped: allow breaks after separators first, and
64+
// inside runs of more than 30 characters without a separator
65+
let filename = if type(filename) == str and filename.len() > 40 {
66+
filename
67+
.replace(regex("[/_.-]"), m => m.text + "\u{200b}")
68+
.replace(regex("[^/_.\u{200b}-]{31,}"), m => m.text.clusters().join("\u{200b}"))
6669
} else { filename }
6770
show raw.where(block: true): it => it
6871
block(width: 100%, radius: 2pt, clip: true, stroke: 0.5pt + luma(128))[

‎tests/docs/smoke-all/typst/code-filename/edge/e06-special.qmd‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ _quarto:
1313
- 'quarto-code-filename\("c#d\.py"'
1414
- 'quarto-code-filename\("e\*f_g\.py"'
1515
- 'quarto-code-filename\("123"'
16+
- 'replace\(regex\("\[/_\.-\]"\), m => m\.text \+ "\\u\{200b\}"\)'
17+
- 'replace\(regex\("\[\^/_\.\\u\{200b\}-\]\{31,\}"\)'
1618
- []
1719
---
1820

0 commit comments

Comments
 (0)