mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
script: Serialize a custom element's "is" value as an attribute (#36888)
Testing: Covered by web platform tests [try run](https://github.com/simonwuelker/servo/actions/runs/14868893249) --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
b2e51820e4
commit
23c327a988
2 changed files with 29 additions and 18 deletions
|
@ -16,6 +16,7 @@ use html5ever::{QualName, local_name, ns};
|
||||||
use markup5ever::TokenizerResult;
|
use markup5ever::TokenizerResult;
|
||||||
use script_bindings::trace::CustomTraceable;
|
use script_bindings::trace::CustomTraceable;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
use style::attr::AttrValue;
|
||||||
use style::context::QuirksMode as StyleContextQuirksMode;
|
use style::context::QuirksMode as StyleContextQuirksMode;
|
||||||
use xml5ever::LocalName;
|
use xml5ever::LocalName;
|
||||||
|
|
||||||
|
@ -116,18 +117,34 @@ impl Tokenizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_element<S: Serializer>(node: &Element, serializer: &mut S) -> io::Result<()> {
|
/// <https://html.spec.whatwg.org/multipage/#html-fragment-serialisation-algorithm>
|
||||||
let name = QualName::new(None, node.namespace().clone(), node.local_name().clone());
|
fn start_element<S: Serializer>(element: &Element, serializer: &mut S) -> io::Result<()> {
|
||||||
let attrs = node
|
let name = QualName::new(
|
||||||
.attrs()
|
None,
|
||||||
.iter()
|
element.namespace().clone(),
|
||||||
.map(|attr| {
|
element.local_name().clone(),
|
||||||
let qname = QualName::new(None, attr.namespace().clone(), attr.local_name().clone());
|
);
|
||||||
let value = attr.value().clone();
|
|
||||||
(qname, value)
|
let mut attributes = vec![];
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
// The "is" value of an element is treated as if it was an attribute and it is serialized before all
|
||||||
let attr_refs = attrs.iter().map(|(qname, value)| {
|
// other attributes. If the element already has an "is" attribute then the "is" value is ignored.
|
||||||
|
if !element.has_attribute(&LocalName::from("is")) {
|
||||||
|
if let Some(is_value) = element.get_is() {
|
||||||
|
let qualified_name = QualName::new(None, ns!(), LocalName::from("is"));
|
||||||
|
|
||||||
|
attributes.push((qualified_name, AttrValue::String(is_value.to_string())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect all the "normal" attributes
|
||||||
|
attributes.extend(element.attrs().iter().map(|attr| {
|
||||||
|
let qname = QualName::new(None, attr.namespace().clone(), attr.local_name().clone());
|
||||||
|
let value = attr.value().clone();
|
||||||
|
(qname, value)
|
||||||
|
}));
|
||||||
|
|
||||||
|
let attr_refs = attributes.iter().map(|(qname, value)| {
|
||||||
let ar: AttrRef = (qname, &**value);
|
let ar: AttrRef = (qname, &**value);
|
||||||
ar
|
ar
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
[serializing-html-fragments-customized-builtins.html]
|
|
||||||
["is" value should be serialized if the custom element has no "is" content attribute]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
["is" value should be serialized even for an undefined element]
|
|
||||||
expected: FAIL
|
|
Loading…
Add table
Add a link
Reference in a new issue