Possible typo in code example and a question about difference between hast and DOM property values
flurmbo opened this issue · 5 comments
I'm new to hast so I might be misunderstanding this, but I think the "no" in <div hidden=no></div> in the following excerpt of readme.md should be in quotation marks:
The DOM is strict in reflecting HTML and hast is not.
Where the DOM treats<div hidden=no></div>as having a value oftrueand
<img width="yes">as having a value of0, these should be reflected as
'no'and'yes', respectively, in hast.
Also, I'm confused about the meaning of the first sentence in this excerpt. If hast always reflects the written value of html and the DOM is flexible about it, shouldn't this sentence read "hast is strict in reflecting HTML and the DOM is not"? Thanks for any clarification
<div hidden=no></div>, <div hidden='no'></div>, and <div hidden="no"></div> are all treated the same. This example omits them for brevity. But if it’s very confusing then we can add them.
The DOM is strict in reflecting HTML and hast is not.
I get what you’re saying. What’s meant here is that The DOM is strict in how it reflects things. If it expects a number, it’ll cast to a number. Maybe I’ve read the specifications too much, for me “reflecting” is that casting that the DOM does.
Confusing, what do you suggest?
Hey @wooorm, thanks for the quick response. My confusion about the first issue arose because I thought unquoted attribute values are considered invalid HTML. I double checked and apparently in some cases they are allowed though not recommended. Either way I understand that you want to cover them since browsers can still understand them.
I don't think the example is too confusing and I think it would be a bit overkill to include all three examples you gave. Maybe replace the unquoted 'no' with single quotes, depending on how you feel about unquoted attributes values.
Thanks for the clarification on the second question, I see what you mean now. It might be clearer if it said something like "the DOM follows strict rules in how it parses HTML whereas hast reflects the source file". Not sure if that is accurate but that's what I suggest!
I double checked and apparently in some cases they are allowed though not recommended
I wouldn’t go so far. It’s the same with JS: You could quote all your properties ({"foo": "bar"}), but often it’s not needed. Same for HTML. They’re perfectly valid and normal. Just not many people know that it’s valid.
I don't think the example is too confusing and I think it would be a bit overkill to include all three examples you gave. Maybe replace the unquoted 'no' with single quotes, depending on how you feel about unquoted attributes values.
I’ll accept a PR to add double quotes, I think those are more often used in HTML, and it’ll be good if that clears things up. I don’t think it’s a very big problem though!
Thanks for the clarification on the second question, I see what you mean now. It might be clearer if it said something like "the DOM follows strict rules in how it parses HTML whereas hast reflects the source file". Not sure if that is accurate but that's what I suggest!
I think “parses HTML” is a bit confusing because that’s not really what the DOM does. HTML is parsed, but the DOM doesn’t really do that.
How about “The DOM has strict rules on how it coerces HTML to expected values, whereas hast is more lenient in how it reflects the source”?
I’ll accept a PR to add double quotes, I think those are more often used in HTML, and it’ll be good if that clears things up. I don’t think it’s a very big problem though!
Sure thing, done
“The DOM has strict rules on how it coerces HTML to expected values, whereas hast is more lenient in how it reflects the source”
Sounds fine to me! I'll let you take that one
Done!