(I'm unsure whether parsing "normal HTML" - and not only "custom HTML tags" - is in scope of the library. As a user I expected to be able to parse "normal HTML" as it is, so I opened this issue; if it's not in scope, feel free to close!)
HTML5 elements are not necessarily valid XML, e.g.
- HTML void elements such as
<br> must not have a closing tag (here: </br>).
- Above MDN document even states that - in general, "Self-closing tags (
<tag />) do not exist in HTML." - but they can be added to void elements in order to be XHTML compliant. Something like <p /> isn't valid HTML5 though!
In contrast, HtmlParser requires all "HTML" to be valid XML.
In practice this means that:
- Void elements currently require a closing tag (e.g.
<br><br />) or a self-closing tag (<br /), just (<br>) doesn't work.
- Non-void elements are currently allowed to be self-closing (e.g.
<p />) despite this being non-valid.
My pragmatic suggestion would be to
- fix the former, i.e. assume void elements always self-close -> treat
<br> as <br />
- and tolerate the latter, as
<p /> is still valid XHTML and nobody would write this "by accident" anyway -> leave it as it is.
(I'm unsure whether parsing "normal HTML" - and not only "custom HTML tags" - is in scope of the library. As a user I expected to be able to parse "normal HTML" as it is, so I opened this issue; if it's not in scope, feel free to close!)
HTML5 elements are not necessarily valid XML, e.g.
<br>must not have a closing tag (here:</br>).<tag />) do not exist in HTML." - but they can be added to void elements in order to be XHTML compliant. Something like<p />isn't valid HTML5 though!In contrast,
HtmlParserrequires all "HTML" to be valid XML.In practice this means that:
<br><br />) or a self-closing tag (<br /), just (<br>) doesn't work.<p />) despite this being non-valid.My pragmatic suggestion would be to
<br>as<br /><p />is still valid XHTML and nobody would write this "by accident" anyway -> leave it as it is.