Render #super as <sup>, #sub as <sub> in HTML (#6422)

This commit is contained in:
Lachlan Kermode 2025-06-11 16:07:25 +02:00 committed by GitHub
parent d7e0c52dd5
commit 1f5846ce24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 1 deletions

View File

@ -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) {

View 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>

View File

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