mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-19 14:40:18 +00:00
LibWeb: Serialize HTML attribute names as per spec
This commit is contained in:
parent
4772e1b0c9
commit
47796e7967
Notes:
github-actions[bot]
2025-09-15 08:09:19 +00:00
Author: https://github.com/lpas 🔰
Commit: 47796e7967
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6187
Reviewed-by: https://github.com/gmta ✅
3 changed files with 606 additions and 10 deletions
|
@ -5205,22 +5205,39 @@ String HTMLParser::serialize_html_fragment(DOM::Node const& node, SerializableSh
|
|||
builder.append(' ');
|
||||
|
||||
// An attribute's serialized name for the purposes of the previous paragraph must be determined as follows:
|
||||
|
||||
// NOTE: As far as I can tell, these steps are equivalent to just using the qualified name.
|
||||
//
|
||||
// -> If the attribute has no namespace:
|
||||
// The attribute's serialized name is the attribute's local name.
|
||||
if (!attribute.namespace_uri().has_value()) {
|
||||
// The attribute's serialized name is the attribute's local name.
|
||||
builder.append(attribute.local_name());
|
||||
}
|
||||
// -> If the attribute is in the XML namespace:
|
||||
// The attribute's serialized name is the string "xml:" followed by the attribute's local name.
|
||||
else if (attribute.namespace_uri() == Namespace::XML) {
|
||||
// The attribute's serialized name is the string "xml:" followed by the attribute's local name.
|
||||
builder.append("xml:"sv);
|
||||
builder.append(attribute.local_name());
|
||||
}
|
||||
// -> If the attribute is in the XMLNS namespace and the attribute's local name is xmlns:
|
||||
// The attribute's serialized name is the string "xmlns".
|
||||
else if (attribute.namespace_uri() == Namespace::XMLNS && attribute.local_name() == "xmlns") {
|
||||
// The attribute's serialized name is the string "xmlns".
|
||||
builder.append("xmlns"sv);
|
||||
}
|
||||
// -> If the attribute is in the XMLNS namespace and the attribute's local name is not xmlns:
|
||||
// The attribute's serialized name is the string "xmlns:" followed by the attribute's local name.
|
||||
else if (attribute.namespace_uri() == Namespace::XMLNS) {
|
||||
// The attribute's serialized name is the string "xmlns:" followed by the attribute's local name.
|
||||
builder.append("xmlns:"sv);
|
||||
builder.append(attribute.local_name());
|
||||
}
|
||||
// -> If the attribute is in the XLink namespace:
|
||||
// The attribute's serialized name is the string "xlink:" followed by the attribute's local name.
|
||||
else if (attribute.namespace_uri() == Namespace::XLink) {
|
||||
// The attribute's serialized name is the string "xlink:" followed by the attribute's local name.
|
||||
builder.append("xlink:"sv);
|
||||
builder.append(attribute.local_name());
|
||||
}
|
||||
// -> If the attribute is in some other namespace:
|
||||
// The attribute's serialized name is the attribute's qualified name.
|
||||
builder.append(attribute.name());
|
||||
else {
|
||||
// The attribute's serialized name is the attribute's qualified name.
|
||||
builder.append(attribute.name());
|
||||
}
|
||||
|
||||
builder.append("=\""sv);
|
||||
builder.append(escape_string(attribute.value().code_points(), AttributeMode::Yes));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue