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

Support HTML comments #68

Closed
whisk opened this issue Nov 7, 2023 · 2 comments
Closed

Support HTML comments #68

whisk opened this issue Nov 7, 2023 · 2 comments

Comments

@whisk
Copy link
Contributor

whisk commented Nov 7, 2023

Problem

Yes, you can render comments as Text nodes:

content := Text("<!-- this is a comment -->").Render()

But it's too verbose and error prone (could easily mix up opening/closing comment quotes)

Possible solution

Add Comment element:

content := Comment("this is a comment").Render()

Pros: intuitive
Cons:

  • it is not a real HTML element or a tag
  • can't use this for inside tag comments (but does anyone need that actually?)

As far as I know, many programming language parsers consider comments as properties of "real" nodes, not as separate nodes. But that seems too complex both to use and implement.

@chasefleming
Copy link
Owner

@whisk great feature idea! Thanks for adding this. I like solution and I think it follows the existing patterns nicely. It's ok that it's not a real HTML element. I just implemented something similar for CSS: https://github.com/chasefleming/elem-go/blob/main/styles/styles.go#L38

I think Comment as a function that returns a CommentNode with a RenderTo and Render method to satisfy the Node interface just like Text and TextNode or CSS and CSSNode is the right solution.

Did you want to take this on as well or just posting the issue?

whisk added a commit to whisk/elem-go that referenced this issue Nov 8, 2023
@whisk
Copy link
Contributor Author

whisk commented Nov 8, 2023

Hi @chasefleming, please check this PR #71 :)

whisk added a commit to whisk/elem-go that referenced this issue Nov 9, 2023
chasefleming added a commit that referenced this issue Nov 10, 2023
added support for HTML comments #68
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

No branches or pull requests

2 participants