diff options
| author | Malo <57839069+MDLC01@users.noreply.github.com> | 2024-04-02 14:47:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-02 12:47:56 +0000 |
| commit | c4001662b686b0d52e99aa0b72a5b82af6f862fd (patch) | |
| tree | b3d809b250a2ae8b9bd297f6282745819698266a | |
| parent | 29af23663d5614f4a66e3b895440dc2048f74a66 (diff) | |
Improve `repr` for `SequenceElem` (#3584)
| -rw-r--r-- | crates/typst/src/foundations/content.rs | 16 | ||||
| -rw-r--r-- | crates/typst/src/foundations/repr.rs | 6 | ||||
| -rw-r--r-- | tests/ref/compiler/repr.png | bin | 32579 -> 55418 bytes | |||
| -rw-r--r-- | tests/typ/compiler/repr.typ | 4 |
4 files changed, 11 insertions, 15 deletions
diff --git a/crates/typst/src/foundations/content.rs b/crates/typst/src/foundations/content.rs index 6184f4cf..5edbb8a1 100644 --- a/crates/typst/src/foundations/content.rs +++ b/crates/typst/src/foundations/content.rs @@ -901,17 +901,11 @@ impl Repr for SequenceElem { if self.children.is_empty() { "[]".into() } else { - eco_format!( - "[{}]", - crate::foundations::repr::pretty_array_like( - &self - .children - .iter() - .map(|c| c.inner.elem.repr()) - .collect::<Vec<_>>(), - false - ) - ) + let elements = crate::foundations::repr::pretty_array_like( + &self.children.iter().map(|c| c.inner.elem.repr()).collect::<Vec<_>>(), + false, + ); + eco_format!("sequence{}", elements) } } } diff --git a/crates/typst/src/foundations/repr.rs b/crates/typst/src/foundations/repr.rs index 62611cc8..00d9931a 100644 --- a/crates/typst/src/foundations/repr.rs +++ b/crates/typst/src/foundations/repr.rs @@ -119,7 +119,7 @@ pub fn display_float(value: f64) -> EcoString { } } -/// Format pieces separated with commas and a final "and" or "or". +/// Formats pieces separated with commas and a final "and" or "or". pub fn separated_list(pieces: &[impl AsRef<str>], last: &str) -> String { let mut buf = String::new(); for (i, part) in pieces.iter().enumerate() { @@ -142,7 +142,7 @@ pub fn separated_list(pieces: &[impl AsRef<str>], last: &str) -> String { buf } -/// Format a comma-separated list. +/// Formats a comma-separated list. /// /// Tries to format horizontally, but falls back to vertical formatting if the /// pieces are too long. @@ -173,7 +173,7 @@ pub fn pretty_comma_list(pieces: &[impl AsRef<str>], trailing_comma: bool) -> St buf } -/// Format an array-like construct. +/// Formats an array-like construct. /// /// Tries to format horizontally, but falls back to vertical formatting if the /// pieces are too long. diff --git a/tests/ref/compiler/repr.png b/tests/ref/compiler/repr.png Binary files differindex 3b1a571e..105b6c80 100644 --- a/tests/ref/compiler/repr.png +++ b/tests/ref/compiler/repr.png diff --git a/tests/typ/compiler/repr.typ b/tests/typ/compiler/repr.typ index 0cdd4bcf..5aaf5710 100644 --- a/tests/typ/compiler/repr.typ +++ b/tests/typ/compiler/repr.typ @@ -39,7 +39,9 @@ #repr("a\n[]\"\u{1F680}string") // Content. -#raw(lang: "typc", repr[*Hey*]) +#raw(lang: "typc", repr[*Hey*]) \ +#raw(lang: "typc", repr[A _sequence_]) \ +#raw(lang: "typc", repr[A _longer_ *sequence*!]) // Functions. #let f(x) = x |
