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

added support for boolean attributes #48 #49

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

whisk
Copy link
Contributor

@whisk whisk commented Oct 31, 2023

Added support to boolean attributes.
HTML has 24 such attributes, but this package supports only 8 so far.

Copy link
Owner

@chasefleming chasefleming left a 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{}{
Copy link
Owner

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?
  • 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.

Copy link
Contributor Author

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
Copy link
Owner

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?

Copy link
Contributor Author

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.

Copy link
Owner

@chasefleming chasefleming left a 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!

@chasefleming chasefleming merged commit a802822 into chasefleming:main Nov 1, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants