-
Notifications
You must be signed in to change notification settings - Fork 27
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
added support for boolean attributes #48 #49
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I prefer this approach with the boolean attributes list—it's closer to the HTML spec than the initial proposal. Thanks for tackling this. I've added a few comments.
attrs/attrs.go
Outdated
|
||
// list of supported boolean attributes | ||
// see https://html.spec.whatwg.org/multipage/indices.html#attributes-3 for reference | ||
var BooleanAttrs = map[string]struct{}{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I'm not sure this needs to be publicly to people and since it's only used in
elem.go
can we move it there for now like thevoidElements
? - Also, can we add the full list and add anything missing from the
attrs
constants to there. We can make separate ticket for that as well and link it in this as well or do it as a followup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this needs to be publicly to people and since it's only used in elem.go can we move it there for now like the voidElements?
I think you are probably right, though I feel it's more proper to keep this boolean attrs list close to attrs themselves. But for sake of keeping things simple I agree that is completely fine to have it in elem.go
.
Also, can we add the full list and add anything missing from the attrs constants to there. We can make separate ticket for that as well and link it in this as well or do it as a followup.
I think it's better to add an attribute to the booleanAttrs
map when we want't to support it in the code.
elem.go
Outdated
@@ -91,6 +93,26 @@ func (e *Element) RenderTo(builder *strings.Builder) { | |||
builder.WriteString(`>`) | |||
} | |||
|
|||
// return string representation of given attribute with its value | |||
func (e *Element) renderAttr(attrName string) string { | |||
var builder strings.Builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a new string for every attribute and slows down performance. Can we pass in the builder like appendAttrToBuilder(builder *strings.Builder, attrName string)
and append the string to the existing builder instead of creating a new one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out, I fixed this to use a builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, thank you!
Added support to boolean attributes.
HTML has 24 such attributes, but this package supports only 8 so far.