summaryrefslogtreecommitdiff
path: root/crates/typst-library/src
diff options
context:
space:
mode:
author+merlan #flirora <uruwi@protonmail.com>2024-12-16 08:45:57 -0500
committerGitHub <noreply@github.com>2024-12-16 13:45:57 +0000
commitd3620df4c63b5856832b23b26eba71aecd9f543e (patch)
treeed453720634c2da05186680e551e2cb6564eab07 /crates/typst-library/src
parent7f139517b9ba8cf4f51083d5387971571d1aa950 (diff)
Add reversed numbering (#5563)
Diffstat (limited to 'crates/typst-library/src')
-rw-r--r--crates/typst-library/src/model/enum.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/crates/typst-library/src/model/enum.rs b/crates/typst-library/src/model/enum.rs
index e0121ba2..eb3c2ea4 100644
--- a/crates/typst-library/src/model/enum.rs
+++ b/crates/typst-library/src/model/enum.rs
@@ -9,7 +9,7 @@ use crate::foundations::{
cast, elem, scope, Array, Content, NativeElement, Packed, Show, Smart, StyleChain,
Styles, TargetElem,
};
-use crate::html::{attr, tag, HtmlElem};
+use crate::html::{attr, tag, HtmlAttr, HtmlElem};
use crate::layout::{Alignment, BlockElem, Em, HAlignment, Length, VAlignment, VElem};
use crate::model::{ListItemLike, ListLike, Numbering, NumberingPattern, ParElem};
@@ -127,8 +127,7 @@ pub struct EnumElem {
/// [Ahead],
/// )
/// ```
- #[default(1)]
- pub start: usize,
+ pub start: Smart<usize>,
/// Whether to display the full numbering, including the numbers of
/// all parent enumerations.
@@ -144,6 +143,17 @@ pub struct EnumElem {
#[default(false)]
pub full: bool,
+ /// Whether to reverse the numbering for this enumeration.
+ ///
+ /// ```example
+ /// #set enum(reversed: true)
+ /// + Coffee
+ /// + Tea
+ /// + Milk
+ /// ```
+ #[default(false)]
+ pub reversed: bool,
+
/// The indentation of each item.
#[resolve]
pub indent: Length,
@@ -217,7 +227,12 @@ impl EnumElem {
impl Show for Packed<EnumElem> {
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
if TargetElem::target_in(styles).is_html() {
- return Ok(HtmlElem::new(tag::ol)
+ let mut elem = HtmlElem::new(tag::ol);
+ if self.reversed(styles) {
+ elem =
+ elem.with_attr(const { 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) {