diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-12-02 14:19:24 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2024-12-04 10:12:07 +0100 |
| commit | 885c7d96eea73f478faea9877f0dbc40c00b0d7b (patch) | |
| tree | e2472515076ed17a24f8ec23e6aeec82b83466c1 /crates/typst-library/src/model/enum.rs | |
| parent | 0ef97c104acb01e4a03b65c4120a0deeb15ff3ea (diff) | |
A few basic HTML show rules
These are very incomplete and ignore various properties. They are just to get things started.
Diffstat (limited to 'crates/typst-library/src/model/enum.rs')
| -rw-r--r-- | crates/typst-library/src/model/enum.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/typst-library/src/model/enum.rs b/crates/typst-library/src/model/enum.rs index bac792d3..e0121ba2 100644 --- a/crates/typst-library/src/model/enum.rs +++ b/crates/typst-library/src/model/enum.rs @@ -1,13 +1,15 @@ use std::str::FromStr; +use ecow::eco_format; use smallvec::SmallVec; use crate::diag::{bail, SourceResult}; use crate::engine::Engine; use crate::foundations::{ cast, elem, scope, Array, Content, NativeElement, Packed, Show, Smart, StyleChain, - Styles, + Styles, TargetElem, }; +use crate::html::{attr, tag, HtmlElem}; use crate::layout::{Alignment, BlockElem, Em, HAlignment, Length, VAlignment, VElem}; use crate::model::{ListItemLike, ListLike, Numbering, NumberingPattern, ParElem}; @@ -214,6 +216,19 @@ 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) + .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())); + } + let mut realized = BlockElem::multi_layouter(self.clone(), engine.routines.layout_enum) .pack() |
