y21 / tl

Fast, zero-copy HTML Parser written in Rust
https://docs.rs/tl
MIT License
336 stars 19 forks source link

Isn't HTMLTag#inner_html actually an outer_html? #39

Closed kelko closed 2 years ago

kelko commented 2 years ago

The method pub fn inner_html<'p>(&'p self, parser: &'p Parser<'a>) -> String { on HTMLTag states in the documentation that it is equivalent to Element#innerHTML in browser. Also the name implies this. The referenced MDN page defines innerHTML as:

A string containing the HTML serialization of the element's descendants.

Now the implementation of inner_html also serialises the element itself including all the attributes. This seems to me more closely to the definition of Element#outerHTML:

Reading the value of outerHTML returns a string containing an HTML serialization of the element and its descendants.

I prefer having the outerHTML-equivalent implementation, but maybe the name of the method should be corrected.

y21 commented 2 years ago

Good point. Yes you are right. 😅

y21 commented 2 years ago

Published a new version on crates.io that fixes this. {Node, HTMLTag}::inner_html now only returns the markup of the contained elements and {Node, HTMLTag}::outer_html will now do what Node::inner_html did before.