mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Add MathML support + test. (#3121)
Co-authored-by: Jonas Scholz <jonas.scholz123@gmail.com>
This commit is contained in:
parent
8387af4fe2
commit
b85313b2a2
@ -15,7 +15,7 @@ use web_sys::{Element, HtmlTextAreaElement as TextAreaElement};
|
|||||||
|
|
||||||
use super::{BList, BNode, BSubtree, DomSlot, Reconcilable, ReconcileTarget};
|
use super::{BList, BNode, BSubtree, DomSlot, Reconcilable, ReconcileTarget};
|
||||||
use crate::html::AnyScope;
|
use crate::html::AnyScope;
|
||||||
use crate::virtual_dom::vtag::{InputFields, VTagInner, Value, SVG_NAMESPACE};
|
use crate::virtual_dom::vtag::{InputFields, VTagInner, Value, MATHML_NAMESPACE, SVG_NAMESPACE};
|
||||||
use crate::virtual_dom::{Attributes, Key, VTag};
|
use crate::virtual_dom::{Attributes, Key, VTag};
|
||||||
use crate::NodeRef;
|
use crate::NodeRef;
|
||||||
|
|
||||||
@ -232,6 +232,7 @@ impl Reconcilable for VTag {
|
|||||||
impl VTag {
|
impl VTag {
|
||||||
fn create_element(&self, parent: &Element) -> Element {
|
fn create_element(&self, parent: &Element) -> Element {
|
||||||
let tag = self.tag();
|
let tag = self.tag();
|
||||||
|
|
||||||
if tag == "svg"
|
if tag == "svg"
|
||||||
|| parent
|
|| parent
|
||||||
.namespace_uri()
|
.namespace_uri()
|
||||||
@ -241,6 +242,15 @@ impl VTag {
|
|||||||
document()
|
document()
|
||||||
.create_element_ns(namespace, tag)
|
.create_element_ns(namespace, tag)
|
||||||
.expect("can't create namespaced element for vtag")
|
.expect("can't create namespaced element for vtag")
|
||||||
|
} else if tag == "math"
|
||||||
|
|| parent
|
||||||
|
.namespace_uri()
|
||||||
|
.map_or(false, |ns| ns == MATHML_NAMESPACE)
|
||||||
|
{
|
||||||
|
let namespace = Some(MATHML_NAMESPACE);
|
||||||
|
document()
|
||||||
|
.create_element_ns(namespace, tag)
|
||||||
|
.expect("can't create namespaced element for vtag")
|
||||||
} else {
|
} else {
|
||||||
document()
|
document()
|
||||||
.create_element(tag)
|
.create_element(tag)
|
||||||
@ -588,6 +598,19 @@ mod tests {
|
|||||||
assert_namespace(&g_tag, SVG_NAMESPACE);
|
assert_namespace(&g_tag, SVG_NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn supports_mathml() {
|
||||||
|
let (root, scope, parent) = setup_parent();
|
||||||
|
let mfrac_node = html! { <mfrac> </mfrac> };
|
||||||
|
let math_node = html! { <math>{mfrac_node}</math> };
|
||||||
|
|
||||||
|
let math_tag = assert_vtag(math_node);
|
||||||
|
let (_, math_tag) = math_tag.attach(&root, &scope, &parent, DomSlot::at_end());
|
||||||
|
assert_namespace(&math_tag, MATHML_NAMESPACE);
|
||||||
|
let mfrac_tag = assert_btag_ref(math_tag.children().get(0).unwrap());
|
||||||
|
assert_namespace(mfrac_tag, MATHML_NAMESPACE);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_compares_values() {
|
fn it_compares_values() {
|
||||||
let a = html! {
|
let a = html! {
|
||||||
|
|||||||
@ -15,6 +15,9 @@ use crate::html::{IntoPropValue, NodeRef};
|
|||||||
/// SVG namespace string used for creating svg elements
|
/// SVG namespace string used for creating svg elements
|
||||||
pub const SVG_NAMESPACE: &str = "http://www.w3.org/2000/svg";
|
pub const SVG_NAMESPACE: &str = "http://www.w3.org/2000/svg";
|
||||||
|
|
||||||
|
/// MathML namespace string used for creating MathML elements
|
||||||
|
pub const MATHML_NAMESPACE: &str = "http://www.w3.org/1998/Math/MathML";
|
||||||
|
|
||||||
/// Default namespace for html elements
|
/// Default namespace for html elements
|
||||||
pub const HTML_NAMESPACE: &str = "http://www.w3.org/1999/xhtml";
|
pub const HTML_NAMESPACE: &str = "http://www.w3.org/1999/xhtml";
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user