Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle boolean attributes? #1

Closed
cburgmer opened this issue Sep 16, 2013 · 3 comments
Closed

Handle boolean attributes? #1

cburgmer opened this issue Sep 16, 2013 · 3 comments
Labels

Comments

@cburgmer
Copy link

I am building an html2xhtml converter on top of parse5 (https://github.com/cburgmer/http2xhtml.js/blob/master/lib/converter.js).

It seems I need to handle boolean attributes (e.g. <input type="checkbox" checked>) myself.

parse5 will return such an attribute as {name: "checked", value: ""}. This does not allow me to distinguish from actual attributes with empty string values.

I could not find much more information on those kind of attributes, so I am posing this as a question: should the parser know about those attributes and return something accordingly?

@inikulin
Copy link
Owner

Hi,
According to spec parser doesn't distinguish attributes with value and attributes without value (parser should treat boolean attributes as an attribute with an empty value) :

Set that attribute's name to the current input character, and its value to the empty string.
http://www.w3.org/html/wg/drafts/html/master/syntax.html#before-attribute-name-state

This caused by the fact that attribute values are handled by the later stage of the page processing in browser (e.g. building render tree, when it decide to not consider checked attribute value and just checks it's presence). So, for the browser and parser <input type="checkbox" checked> is an equivalent to <input type="checkbox" checked="">). If you have some specific issue caused by such behavior could you please describe it in details. I'll try to assist you to find workaround for it.

@cburgmer
Copy link
Author

Hi thanks for clearing this up.

As far as I understand checked in fact needs to be converted to checked="checked" amongst others, following http://www.w3.org/TR/xhtml1/dtds.html.

So I guess I need to take care of that on my part.

@inikulin
Copy link
Owner

Yes, checked attribute value has restrictions only in the XHTML. In HTML (4 and 5) only presense of the attribute matters and it can have any value. So if you perform conversion beetween HTML and XHTML you need to handle boolean attributes manually.

inikulin added a commit that referenced this issue Apr 16, 2018
Adding parse errors for tag name state
43081j pushed a commit to 43081j/parse5 that referenced this issue Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants