mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Fix label in .fields()
accessor (#2884)
This commit is contained in:
parent
0bdd2191c0
commit
3e96f5f75f
@ -922,6 +922,17 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
|
||||
.unless_capability("Unlabellable", || quote! { self.label().is_some() })
|
||||
.unwrap_or_else(|| quote! { false });
|
||||
|
||||
let label_field_dict = element.unless_capability("Unlabellable", || {
|
||||
quote! {
|
||||
if let Some(label) = self.label() {
|
||||
fields.insert(
|
||||
::ecow::EcoString::inline("label").into(),
|
||||
#foundations::IntoValue::into_value(label)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let mark_prepared = element
|
||||
.unless_capability("Unlabellable", || quote! { self.prepared = true; })
|
||||
.unwrap_or_else(|| quote! {});
|
||||
@ -1077,6 +1088,7 @@ fn create_native_elem_impl(element: &Elem) -> TokenStream {
|
||||
|
||||
fn fields(&self) -> #foundations::Dict {
|
||||
let mut fields = #foundations::Dict::new();
|
||||
#label_field_dict
|
||||
#(#field_dict)*
|
||||
#(#field_opt_dict)*
|
||||
fields
|
||||
|
31
tests/typ/bugs/label-fields-dict.typ
Normal file
31
tests/typ/bugs/label-fields-dict.typ
Normal file
@ -0,0 +1,31 @@
|
||||
// Tests whether the label is accessible through the has, field,
|
||||
// and fields accessors
|
||||
// Ref: false
|
||||
|
||||
---
|
||||
// Test whether the label is accessible through the has method
|
||||
#show heading: it => {
|
||||
assert(it.has("label"))
|
||||
it
|
||||
}
|
||||
|
||||
= Hello, world! <my_label>
|
||||
|
||||
---
|
||||
// Test whether the label is accessible through the field method
|
||||
#show heading: it => {
|
||||
assert(str(it.label) == "my_label")
|
||||
it
|
||||
}
|
||||
|
||||
= Hello, world! <my_label>
|
||||
|
||||
---
|
||||
// Test whether the label is accessible through the fields method
|
||||
#show heading: it => {
|
||||
assert("label" in it.fields())
|
||||
assert(str(it.fields().label) == "my_label")
|
||||
it
|
||||
}
|
||||
|
||||
= Hello, world! <my_label>
|
Loading…
x
Reference in New Issue
Block a user