diff --git a/crates/typst-html/src/encode.rs b/crates/typst-html/src/encode.rs index 62146f867..f2b15a02e 100644 --- a/crates/typst-html/src/encode.rs +++ b/crates/typst-html/src/encode.rs @@ -80,9 +80,13 @@ fn write_element(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> { w.buf.push('"'); } + if tag::is_self_closing_foreign(element.tag) { + w.buf.push_str(" /"); + } + w.buf.push('>'); - if tag::is_void(element.tag) { + if tag::is_void(element.tag) || tag::is_self_closing_foreign(element.tag) { return Ok(()); } diff --git a/crates/typst-library/src/html/dom.rs b/crates/typst-library/src/html/dom.rs index 5b6eab4d6..a5159d47f 100644 --- a/crates/typst-library/src/html/dom.rs +++ b/crates/typst-library/src/html/dom.rs @@ -472,6 +472,26 @@ pub mod tag { wbr } + pub mod math { + use super::HtmlTag; + + tags! { + math + mfrac + mi + mmultiscripts + mprescripts + mrow + msub + msup + munderover + } + + pub fn is_self_closing(tag: HtmlTag) -> bool { + matches!(tag, self::mprescripts) + } + } + /// Whether nodes with the tag have the CSS property `display: block` by /// default. /// @@ -569,8 +589,9 @@ pub mod tag { ) } - /// Whether this is a void tag whose associated element may not have a - /// children. + /// Whether this is a void tag whose elements may not have children. + /// + /// Source: pub fn is_void(tag: HtmlTag) -> bool { matches!( tag, @@ -591,6 +612,18 @@ pub mod tag { ) } + /// Whether this is a self-closing foreign tag. + /// + /// A foreign tag is a tag from the MathML or the SVG namespace + /// . + /// + /// We use this to determine whether a tag needs to be + /// terminated with `/ >` (foreign elements) instead of just `>`. + /// See . + pub fn is_self_closing_foreign(tag: HtmlTag) -> bool { + math::is_self_closing(tag) + } + /// Whether this is a tag containing raw text. pub fn is_raw(tag: HtmlTag) -> bool { matches!(tag, self::script | self::style) diff --git a/crates/typst-utils/src/pico.rs b/crates/typst-utils/src/pico.rs index 2c80d37de..bbe067b7a 100644 --- a/crates/typst-utils/src/pico.rs +++ b/crates/typst-utils/src/pico.rs @@ -219,6 +219,7 @@ mod exceptions { "h5", "h6", "historical-ligatures", + "mmultiscripts", "number-clearance", "number-margin", "numbering-scope",