mirror of
https://github.com/typst/typst
synced 2025-08-10 05:07:55 +08:00
Support a few MathML tags.
This commit is contained in:
parent
265df6c29f
commit
7088ae4107
@ -80,9 +80,13 @@ fn write_element(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> {
|
|||||||
w.buf.push('"');
|
w.buf.push('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tag::is_self_closing_foreign(element.tag) {
|
||||||
|
w.buf.push_str(" /");
|
||||||
|
}
|
||||||
|
|
||||||
w.buf.push('>');
|
w.buf.push('>');
|
||||||
|
|
||||||
if tag::is_void(element.tag) {
|
if tag::is_void(element.tag) || tag::is_self_closing_foreign(element.tag) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,6 +472,26 @@ pub mod tag {
|
|||||||
wbr
|
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
|
/// Whether nodes with the tag have the CSS property `display: block` by
|
||||||
/// default.
|
/// default.
|
||||||
///
|
///
|
||||||
@ -569,8 +589,9 @@ pub mod tag {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether this is a void tag whose associated element may not have a
|
/// Whether this is a void tag whose elements may not have children.
|
||||||
/// children.
|
///
|
||||||
|
/// Source: <https://html.spec.whatwg.org/#void-elements>
|
||||||
pub fn is_void(tag: HtmlTag) -> bool {
|
pub fn is_void(tag: HtmlTag) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
tag,
|
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
|
||||||
|
/// <https://html.spec.whatwg.org/#foreign-elements>.
|
||||||
|
///
|
||||||
|
/// We use this to determine whether a tag needs to be
|
||||||
|
/// terminated with `/ >` (foreign elements) instead of just `>`.
|
||||||
|
/// See <https://html.spec.whatwg.org/#start-tags>.
|
||||||
|
pub fn is_self_closing_foreign(tag: HtmlTag) -> bool {
|
||||||
|
math::is_self_closing(tag)
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether this is a tag containing raw text.
|
/// Whether this is a tag containing raw text.
|
||||||
pub fn is_raw(tag: HtmlTag) -> bool {
|
pub fn is_raw(tag: HtmlTag) -> bool {
|
||||||
matches!(tag, self::script | self::style)
|
matches!(tag, self::script | self::style)
|
||||||
|
@ -219,6 +219,7 @@ mod exceptions {
|
|||||||
"h5",
|
"h5",
|
||||||
"h6",
|
"h6",
|
||||||
"historical-ligatures",
|
"historical-ligatures",
|
||||||
|
"mmultiscripts",
|
||||||
"number-clearance",
|
"number-clearance",
|
||||||
"number-margin",
|
"number-margin",
|
||||||
"numbering-scope",
|
"numbering-scope",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user