diff --git a/moli-dom/src/native/html_serialization/engine.rs b/moli-dom/src/native/html_serialization/engine.rs
index d4a93d0d878..93dadc7e3bd 100644
--- a/moli-dom/src/native/html_serialization/engine.rs
+++ b/moli-dom/src/native/html_serialization/engine.rs
@@ -54,6 +54,7 @@ struct HtmlSerializationOptions<'a> {
// whose owner Document has different scripting state from the outer tree.
scripting_enabled_for_node: &'a dyn Fn(NativeNodeId) -> bool,
shadow_root_provider: Option<&'a dyn HtmlShadowRootProvider>,
+ attribute_overrides: Option<&'a dyn Fn(NativeNodeId) -> Vec<(String, String)>>,
}
impl<'a> HtmlSerializationOptions<'a> {
@@ -65,6 +66,7 @@ impl<'a> HtmlSerializationOptions<'a> {
target,
scripting_enabled_for_node,
shadow_root_provider: None,
+ attribute_overrides: None,
}
}
@@ -265,6 +267,9 @@ fn serialize_html_node_frame<'a, S>(
out.push('>');
}
NodeData::Element(element) => {
+ let overrides = options
+ .attribute_overrides
+ .map(|attributes| attributes(node_id));
out.push('<');
out.push_str(element.local_name());
if let Some(is_name) = element.custom_element_is_name()
@@ -278,12 +283,31 @@ fn serialize_html_node_frame<'a, S>(
if out.limit_exceeded() {
return;
}
+ if overrides.as_ref().is_some_and(|attributes| {
+ attributes
+ .iter()
+ .any(|(name, _)| attribute.name_matches(name))
+ }) {
+ continue;
+ }
out.push(' ');
attribute.push_html_serialized_name(|part| out.push_str(part));
out.push_str("=\"");
escape_html_attribute(attribute.value(), out);
out.push('"');
}
+ if let Some(overrides) = overrides {
+ for (name, value) in overrides {
+ if out.limit_exceeded() {
+ return;
+ }
+ out.push(' ');
+ out.push_str(&name);
+ out.push_str("=\"");
+ escape_html_attribute(&value, out);
+ out.push('"');
+ }
+ }
out.push('>');
if !is_void_html_element(element.namespace(), element.local_name()) {
@@ -482,18 +506,24 @@ pub(super) fn serialize_html_with_limit(
dom: &NativeDom,
node_id: NativeNodeId,
max_bytes: usize,
+) -> Result