Closed sanmai-NL closed 1 year ago
As far as I know this is a concern for the parser and serializer for a given syntax (e.g. HTML or XML). In a DOM-like tree data structure, such elements are not special, they are represented simply as element nodes that happen not to have any children.
To create one from Rust code, call for example NodeRef::new_element
and then don’t call methods like append
. To create one by parsing HTML syntax, html5ever
will already take care of parsing <link>
correctly.
The parser used in e.g. Firefox and HTML validators will flag empty elements serialized as normal elements but empty as syntax errors in the strict sense. Using new_element
without append
is what I happened to do, but I did call append
on the containing element in order to place the empty element as child, resulting in <link ...></link>
.
This sounds like a bug in html5ever’s serializier, or in kuchiki’s use of it.
I read some of html5ever's documentation and got a solution: use namespace html
like this: QualName::new(None, ns!(html), local_name!("link"))
. This will make it work correctly.
I will soon archive this repository and make it read-only, so this issue will not be addressed: https://github.com/kuchiki-rs/kuchiki#archived
E.g. a
link
element is an empty element. Looking through the API docs, examples and tests I couldn't figure out how to create such an element usingkuchiki
.