diff --git a/crates/typst-library/src/text/shift.rs b/crates/typst-library/src/text/shift.rs index dbf1be8a..7b35dfd3 100644 --- a/crates/typst-library/src/text/shift.rs +++ b/crates/typst-library/src/text/shift.rs @@ -2,7 +2,10 @@ use ecow::EcoString; use crate::diag::SourceResult; use crate::engine::Engine; -use crate::foundations::{elem, Content, Packed, SequenceElem, Show, StyleChain}; +use crate::foundations::{ + elem, Content, NativeElement, Packed, SequenceElem, Show, StyleChain, TargetElem, +}; +use crate::html::{tag, HtmlElem}; use crate::layout::{Em, Length}; use crate::text::{variant, SpaceElem, TextElem, TextSize}; use crate::World; @@ -52,6 +55,13 @@ impl Show for Packed { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult { let body = self.body.clone(); + if TargetElem::target_in(styles).is_html() { + return Ok(HtmlElem::new(tag::sub) + .with_body(Some(body)) + .pack() + .spanned(self.span())); + } + if self.typographic(styles) { if let Some(text) = convert_script(&body, true) { if is_shapable(engine, &text, styles) { @@ -111,6 +121,13 @@ impl Show for Packed { fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult { let body = self.body.clone(); + if TargetElem::target_in(styles).is_html() { + return Ok(HtmlElem::new(tag::sup) + .with_body(Some(body)) + .pack() + .spanned(self.span())); + } + if self.typographic(styles) { if let Some(text) = convert_script(&body, false) { if is_shapable(engine, &text, styles) { diff --git a/tests/ref/html/basic-sup-sub.html b/tests/ref/html/basic-sup-sub.html new file mode 100644 index 00000000..54187215 --- /dev/null +++ b/tests/ref/html/basic-sup-sub.html @@ -0,0 +1,11 @@ + + + + + + + +

1st, 2nd, 3rd.

+

log2, log3, logvariable.

+ + diff --git a/tests/suite/text/shift.typ b/tests/suite/text/shift.typ index 3b8d2ccb..2667ca2f 100644 --- a/tests/suite/text/shift.typ +++ b/tests/suite/text/shift.typ @@ -17,3 +17,8 @@ n#super[1], n#sub[2], ... n#super[N] #underline[The claim#super[\[4\]]] has been disputed. \ The claim#super[#underline[\[4\]]] has been disputed. \ It really has been#super(box(text(baseline: 0pt, underline[\[4\]]))) \ + +--- basic-sup-sub html --- +1#super[st], 2#super[nd], 3#super[rd]. + +log#sub[2], log#sub[3], log#sub[variable].