From cdbf60e883413d6ffbd1575d18439b02046e0069 Mon Sep 17 00:00:00 2001 From: Malo <57839069+MDLC01@users.noreply.github.com> Date: Wed, 16 Jul 2025 09:05:52 +0100 Subject: [PATCH] Change `enum.item.number` to `Smart` instead of `Option` (#6609) --- crates/typst-eval/src/markup.rs | 2 +- crates/typst-html/src/rules.rs | 2 +- crates/typst-library/src/model/enum.rs | 2 +- tests/ref/enum-item-number-optional.png | Bin 0 -> 474 bytes tests/suite/model/enum.typ | 6 +++++- 5 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 tests/ref/enum-item-number-optional.png diff --git a/crates/typst-eval/src/markup.rs b/crates/typst-eval/src/markup.rs index cc9606269..baa548459 100644 --- a/crates/typst-eval/src/markup.rs +++ b/crates/typst-eval/src/markup.rs @@ -251,7 +251,7 @@ impl Eval for ast::EnumItem<'_> { let body = self.body().eval(vm)?; let mut elem = EnumItem::new(body); if let Some(number) = self.number() { - elem.number.set(Some(number)); + elem.number.set(Smart::Custom(number)); } Ok(elem.pack()) } diff --git a/crates/typst-html/src/rules.rs b/crates/typst-html/src/rules.rs index 04a58ca47..0fe5bd087 100644 --- a/crates/typst-html/src/rules.rs +++ b/crates/typst-html/src/rules.rs @@ -103,7 +103,7 @@ const ENUM_RULE: ShowFn = |elem, _, styles| { let body = Content::sequence(elem.children.iter().map(|item| { let mut li = HtmlElem::new(tag::li); - if let Some(nr) = item.number.get(styles) { + if let Smart::Custom(nr) = item.number.get(styles) { li = li.with_attr(attr::value, eco_format!("{nr}")); } // Text in wide enums shall always turn into paragraphs. diff --git a/crates/typst-library/src/model/enum.rs b/crates/typst-library/src/model/enum.rs index 388fb9eda..93a2c1dc6 100644 --- a/crates/typst-library/src/model/enum.rs +++ b/crates/typst-library/src/model/enum.rs @@ -220,7 +220,7 @@ impl EnumElem { pub struct EnumItem { /// The item's number. #[positional] - pub number: Option, + pub number: Smart, /// The item's body. #[required] diff --git a/tests/ref/enum-item-number-optional.png b/tests/ref/enum-item-number-optional.png new file mode 100644 index 0000000000000000000000000000000000000000..2f30566caa355d9ed711ba504ba3136695892727 GIT binary patch literal 474 zcmV<00VV#4P)(4@1y#WNHcCxf_u#xCU`t z^3baTL?uka@hm_aOr*IK!0|9THBh)!liu0@lkjHWDVFSsTo_OTLau&f28LOw2cui$ zfDria!V#T^cKGG+EtwzU#eSrmulj~=_;K1_o@{{*$4I@wTe@Md3x$!Nme<>W(7NOq zs=r=t-doDEbugePEG`mPxGYR5Qaep5Kn9H9NRO#%0PQP>sCx1lV?KR~ll#6#-^ z-SBlAs|x~aqF1LjG_dr{8zJl8gLO=-_YMl3-I6bkaAuKQE&>yn!2cBf2AgM3x~{-? QrT_o{07*qoM6N<$f?)dEJ^%m! literal 0 HcmV?d00001 diff --git a/tests/suite/model/enum.typ b/tests/suite/model/enum.typ index 7ee4dc20c..f7e097bda 100644 --- a/tests/suite/model/enum.typ +++ b/tests/suite/model/enum.typ @@ -56,6 +56,10 @@ a + 0. enum.item(5)[Fifth] ) +--- enum-item-number-optional --- +#enum.item[First] +#enum.item[Second] + --- enum-numbering-pattern --- // Test numbering pattern. #set enum(numbering: "(1.a.*)") @@ -217,7 +221,7 @@ a + 0. --- issue-2530-enum-item-panic --- // Enum item (pre-emptive) -#enum.item(none)[Hello] +#enum.item(auto)[Hello] #enum.item(17)[Hello] --- issue-5503-enum-in-align ---