Compare commits

...

2 Commits

Author SHA1 Message Date
Lachlan Kermode
a5f371ea09
Merge 4f6712e3b30b6af56f3809a942a4b06d0e859c2d into 5661c20580584d86897d139cdeffd6fb1a9a6d5c 2025-07-16 19:24:18 +03:00
Lachlan Kermode
4f6712e3b3 Adds a show rule for smallcaps in the HTML target 2025-07-14 21:37:37 +02:00
3 changed files with 21 additions and 2 deletions

View File

@ -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);
@ -390,6 +391,20 @@ const STRIKE_RULE: ShowFn<StrikeElem> =
const HIGHLIGHT_RULE: ShowFn<HighlightElem> =
|elem, _, _| Ok(HtmlElem::new(tag::mark).with_body(Some(elem.body.clone())).pack());
const SMALLCAPS_RULE: ShowFn<SmallcapsElem> = |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<RawElem> = |elem, _, styles| {
let lines = elem.lines.as_deref().unwrap_or_default();

View File

@ -7,5 +7,6 @@
<body>
<p><s>Struck</s> <mark>Highlighted</mark> <span style="text-decoration: underline">Underlined</span> <span style="text-decoration: overline">Overlined</span></p>
<p><span style="text-decoration: overline"><span style="text-decoration: underline"><mark><s>Mixed</s></mark></span></span></p>
<p><span style="font-variant-caps: small-caps">Small Caps</span> <span style="font-variant-caps: all-small-caps">All Small Caps</span></p>
</body>
</html>

View File

@ -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]