fix: allow access to label of sequence (#342)

This commit is contained in:
GabrielDertoni 2023-03-30 06:38:23 -03:00 committed by GitHub
parent 4d9c6b28d0
commit 84bfb3ca24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -165,11 +165,10 @@ impl Content {
/// Access a field on the content. /// Access a field on the content.
pub fn field(&self, name: &str) -> Option<Value> { pub fn field(&self, name: &str) -> Option<Value> {
if let Some(iter) = self.to_sequence() { if let (Some(iter), "children") = (self.to_sequence(), name) {
(name == "children") Some(Value::Array(iter.cloned().map(Value::Content).collect()))
.then(|| Value::Array(iter.cloned().map(Value::Content).collect())) } else if let (Some((child, _)), "child") = (self.to_styled(), "child") {
} else if let Some((child, _)) = self.to_styled() { Some(Value::Content(child.clone()))
(name == "child").then(|| Value::Content(child.clone()))
} else { } else {
self.field_ref(name).cloned() self.field_ref(name).cloned()
} }