mirror of
https://github.com/typst/typst
synced 2025-06-16 10:22:51 +08:00
Render #super
as <sup>
, #sub
as <sub>
in HTML (#6422)
This commit is contained in:
parent
d7e0c52dd5
commit
1f5846ce24
@ -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<SubElem> {
|
||||
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
||||
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<SuperElem> {
|
||||
fn show(&self, engine: &mut Engine, styles: StyleChain) -> SourceResult<Content> {
|
||||
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) {
|
||||
|
11
tests/ref/html/basic-sup-sub.html
Normal file
11
tests/ref/html/basic-sup-sub.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<p>1<sup>st</sup>, 2<sup>nd</sup>, 3<sup>rd</sup>.</p>
|
||||
<p>log<sub>2</sub>, log<sub>3</sub>, log<sub>variable</sub>.</p>
|
||||
</body>
|
||||
</html>
|
@ -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].
|
||||
|
Loading…
x
Reference in New Issue
Block a user