diff options
| author | Michael Färber <01mf02@gmail.com> | 2025-01-23 13:18:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-23 12:18:46 +0000 |
| commit | e61cd6fb9e9a90de8d78f05a43246f08feddcf8f (patch) | |
| tree | b3f95e4c603ece4d21be1686b82da909ee1e71f0 | |
| parent | dda486a412b31acbf767087c748a62ccc6b510b6 (diff) | |
Support `start` attribute for `enum` in HTML export (#5676)
| -rw-r--r-- | crates/typst-library/src/model/enum.rs | 24 | ||||
| -rw-r--r-- | tests/ref/html/enum-start.html | 12 | ||||
| -rw-r--r-- | tests/suite/model/enum.typ | 7 |
3 files changed, 31 insertions, 12 deletions
diff --git a/crates/typst-library/src/model/enum.rs b/crates/typst-library/src/model/enum.rs index eb3c2ea4..2d774cbb 100644 --- a/crates/typst-library/src/model/enum.rs +++ b/crates/typst-library/src/model/enum.rs @@ -229,19 +229,19 @@ impl Show for Packed<EnumElem> { if TargetElem::target_in(styles).is_html() { let mut elem = HtmlElem::new(tag::ol); if self.reversed(styles) { - elem = - elem.with_attr(const { HtmlAttr::constant("reversed") }, "reversed"); + elem = elem.with_attr(HtmlAttr::constant("reversed"), "reversed"); } - return Ok(elem - .with_body(Some(Content::sequence(self.children.iter().map(|item| { - let mut li = HtmlElem::new(tag::li); - if let Some(nr) = item.number(styles) { - li = li.with_attr(attr::value, eco_format!("{nr}")); - } - li.with_body(Some(item.body.clone())).pack().spanned(item.span()) - })))) - .pack() - .spanned(self.span())); + if let Some(n) = self.start(styles).custom() { + elem = elem.with_attr(HtmlAttr::constant("start"), eco_format!("{n}")); + } + let body = Content::sequence(self.children.iter().map(|item| { + let mut li = HtmlElem::new(tag::li); + if let Some(nr) = item.number(styles) { + li = li.with_attr(attr::value, eco_format!("{nr}")); + } + li.with_body(Some(item.body.clone())).pack().spanned(item.span()) + })); + return Ok(elem.with_body(Some(body)).pack().spanned(self.span())); } let mut realized = diff --git a/tests/ref/html/enum-start.html b/tests/ref/html/enum-start.html new file mode 100644 index 00000000..8a4ff37f --- /dev/null +++ b/tests/ref/html/enum-start.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + </head> + <body> + <ol start="3"> + <li>Skipping</li><li>Ahead</li> + </ol> + </body> +</html> diff --git a/tests/suite/model/enum.typ b/tests/suite/model/enum.typ index 258c6f6b..e957ae9e 100644 --- a/tests/suite/model/enum.typ +++ b/tests/suite/model/enum.typ @@ -101,6 +101,13 @@ a + 0. [Red], [Green], [Blue], [Red], ) +--- enum-start html --- +#enum( + start: 3, + [Skipping], + [Ahead], +) + --- enum-numbering-closure-nested --- // Test numbering with closure and nested lists. #set enum(numbering: n => super[#n]) |
