summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-05-22 13:49:09 +0200
committerLaurenz <laurmaedje@gmail.com>2023-05-22 13:49:09 +0200
commit8aa0ae197d9f77f77dcf9de46b48a4ef7719d562 (patch)
treed04ba58a8a28aa3013a4afc69c76a7f7255b7516
parent3d83960322e1a2053f2e6ef64cf5139b0b04cb47 (diff)
Fix field access on styled element
Fixes #1197
-rw-r--r--src/model/content.rs2
-rw-r--r--tests/typ/compiler/label.typ7
2 files changed, 8 insertions, 1 deletions
diff --git a/src/model/content.rs b/src/model/content.rs
index 71a5cb84..8b60ab44 100644
--- a/src/model/content.rs
+++ b/src/model/content.rs
@@ -177,7 +177,7 @@ impl Content {
pub fn field(&self, name: &str) -> Option<Value> {
if let (Some(iter), "children") = (self.to_sequence(), name) {
Some(Value::Array(iter.cloned().map(Value::Content).collect()))
- } else if let (Some((child, _)), "child") = (self.to_styled(), "child") {
+ } else if let (Some((child, _)), "child") = (self.to_styled(), name) {
Some(Value::Content(child.clone()))
} else {
self.field_ref(name).cloned()
diff --git a/tests/typ/compiler/label.typ b/tests/typ/compiler/label.typ
index 58b0dee9..407a849d 100644
--- a/tests/typ/compiler/label.typ
+++ b/tests/typ/compiler/label.typ
@@ -56,3 +56,10 @@ _Visible_
---
// Test that incomplete label is text.
1 < 2 is #if 1 < 2 [not] a label.
+
+---
+// Test label on text, styled, and sequence.
+// Ref: false
+#test([Hello<hi>].label, <hi>)
+#test([#[A *B* C]<hi>].label, <hi>)
+#test([#text(red)[Hello]<hi>].label, <hi>)