mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Improve repr
for SequenceElem
(#3584)
This commit is contained in:
parent
29af23663d
commit
c4001662b6
@ -901,17 +901,11 @@ impl Repr for SequenceElem {
|
|||||||
if self.children.is_empty() {
|
if self.children.is_empty() {
|
||||||
"[]".into()
|
"[]".into()
|
||||||
} else {
|
} else {
|
||||||
eco_format!(
|
let elements = crate::foundations::repr::pretty_array_like(
|
||||||
"[{}]",
|
&self.children.iter().map(|c| c.inner.elem.repr()).collect::<Vec<_>>(),
|
||||||
crate::foundations::repr::pretty_array_like(
|
false,
|
||||||
&self
|
);
|
||||||
.children
|
eco_format!("sequence{}", elements)
|
||||||
.iter()
|
|
||||||
.map(|c| c.inner.elem.repr())
|
|
||||||
.collect::<Vec<_>>(),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
pub fn separated_list(pieces: &[impl AsRef<str>], last: &str) -> String {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
for (i, part) in pieces.iter().enumerate() {
|
for (i, part) in pieces.iter().enumerate() {
|
||||||
@ -142,7 +142,7 @@ pub fn separated_list(pieces: &[impl AsRef<str>], last: &str) -> String {
|
|||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format a comma-separated list.
|
/// Formats a comma-separated list.
|
||||||
///
|
///
|
||||||
/// Tries to format horizontally, but falls back to vertical formatting if the
|
/// Tries to format horizontally, but falls back to vertical formatting if the
|
||||||
/// pieces are too long.
|
/// pieces are too long.
|
||||||
@ -173,7 +173,7 @@ pub fn pretty_comma_list(pieces: &[impl AsRef<str>], trailing_comma: bool) -> St
|
|||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format an array-like construct.
|
/// Formats an array-like construct.
|
||||||
///
|
///
|
||||||
/// Tries to format horizontally, but falls back to vertical formatting if the
|
/// Tries to format horizontally, but falls back to vertical formatting if the
|
||||||
/// pieces are too long.
|
/// pieces are too long.
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 54 KiB |
@ -39,7 +39,9 @@
|
|||||||
#repr("a\n[]\"\u{1F680}string")
|
#repr("a\n[]\"\u{1F680}string")
|
||||||
|
|
||||||
// Content.
|
// 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.
|
// Functions.
|
||||||
#let f(x) = x
|
#let f(x) = x
|
||||||
|
Loading…
x
Reference in New Issue
Block a user