From 4f6712e3b30b6af56f3809a942a4b06d0e859c2d Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Mon, 14 Jul 2025 21:37:37 +0200 Subject: [PATCH 1/2] Adds a show rule for smallcaps in the HTML target --- crates/typst-html/src/rules.rs | 19 +++++++++++++++++-- tests/ref/html/html-deco.html | 1 + tests/suite/text/deco.typ | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/typst-html/src/rules.rs b/crates/typst-html/src/rules.rs index 04a58ca47..677fbe270 100644 --- a/crates/typst-html/src/rules.rs +++ b/crates/typst-html/src/rules.rs @@ -14,8 +14,8 @@ use typst_library::model::{ RefElem, StrongElem, TableCell, TableElem, TermsElem, }; use typst_library::text::{ - HighlightElem, LinebreakElem, OverlineElem, RawElem, RawLine, SpaceElem, StrikeElem, - SubElem, SuperElem, UnderlineElem, + HighlightElem, LinebreakElem, OverlineElem, RawElem, RawLine, SmallcapsElem, + SpaceElem, StrikeElem, SubElem, SuperElem, UnderlineElem, }; use typst_library::visualize::ImageElem; @@ -47,6 +47,7 @@ pub fn register(rules: &mut NativeRuleMap) { rules.register(Html, OVERLINE_RULE); rules.register(Html, STRIKE_RULE); rules.register(Html, HIGHLIGHT_RULE); + rules.register(Html, SMALLCAPS_RULE); rules.register(Html, RAW_RULE); rules.register(Html, RAW_LINE_RULE); @@ -400,6 +401,20 @@ const STRIKE_RULE: ShowFn = const HIGHLIGHT_RULE: ShowFn = |elem, _, _| Ok(HtmlElem::new(tag::mark).with_body(Some(elem.body.clone())).pack()); +const SMALLCAPS_RULE: ShowFn = |elem, _, styles| { + Ok(HtmlElem::new(tag::span) + .with_attr( + attr::style, + if elem.all.get(styles) { + "font-variant-caps: all-small-caps" + } else { + "font-variant-caps: small-caps" + }, + ) + .with_body(Some(elem.body.clone())) + .pack()) +}; + const RAW_RULE: ShowFn = |elem, _, styles| { let lines = elem.lines.as_deref().unwrap_or_default(); diff --git a/tests/ref/html/html-deco.html b/tests/ref/html/html-deco.html index 87f2ab4c8..e471686ac 100644 --- a/tests/ref/html/html-deco.html +++ b/tests/ref/html/html-deco.html @@ -7,5 +7,6 @@

Struck Highlighted Underlined Overlined

Mixed

+

Small Caps All Small Caps

diff --git a/tests/suite/text/deco.typ b/tests/suite/text/deco.typ index a1d287d9d..e44b682a0 100644 --- a/tests/suite/text/deco.typ +++ b/tests/suite/text/deco.typ @@ -91,3 +91,6 @@ We can also specify a customized value #overline[Overlined] #(strike, highlight, underline, overline).fold([Mixed], (it, f) => f(it)) + +#smallcaps[Small Caps] +#smallcaps(all: true)[All Small Caps] From 99015efa66d14464714facbb60b466f2590d9766 Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Wed, 16 Jul 2025 22:46:37 +0200 Subject: [PATCH 2/2] Removes test from text/deco.typ A test already exists for small caps; it now also tests HTML render. --- tests/ref/html/html-deco.html | 1 - tests/ref/html/smallcaps-all.html | 10 ++++++++++ tests/suite/text/deco.typ | 3 --- tests/suite/text/smallcaps.typ | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 tests/ref/html/smallcaps-all.html diff --git a/tests/ref/html/html-deco.html b/tests/ref/html/html-deco.html index e471686ac..87f2ab4c8 100644 --- a/tests/ref/html/html-deco.html +++ b/tests/ref/html/html-deco.html @@ -7,6 +7,5 @@

Struck Highlighted Underlined Overlined

Mixed

-

Small Caps All Small Caps

diff --git a/tests/ref/html/smallcaps-all.html b/tests/ref/html/smallcaps-all.html new file mode 100644 index 000000000..47b799415 --- /dev/null +++ b/tests/ref/html/smallcaps-all.html @@ -0,0 +1,10 @@ + + + + + + + +

Test 012
Test 012

+ + diff --git a/tests/suite/text/deco.typ b/tests/suite/text/deco.typ index e44b682a0..a1d287d9d 100644 --- a/tests/suite/text/deco.typ +++ b/tests/suite/text/deco.typ @@ -91,6 +91,3 @@ We can also specify a customized value #overline[Overlined] #(strike, highlight, underline, overline).fold([Mixed], (it, f) => f(it)) - -#smallcaps[Small Caps] -#smallcaps(all: true)[All Small Caps] diff --git a/tests/suite/text/smallcaps.typ b/tests/suite/text/smallcaps.typ index 981e41c4c..4b2f85aef 100644 --- a/tests/suite/text/smallcaps.typ +++ b/tests/suite/text/smallcaps.typ @@ -11,6 +11,6 @@ #show smallcaps: set text(fill: red) #smallcaps[Smallcaps] ---- smallcaps-all --- +--- smallcaps-all render html --- #smallcaps(all: false)[Test 012] \ #smallcaps(all: true)[Test 012]