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

Make it more ergonomic to comment HTML code #2910

Open
1 of 3 tasks
ctron opened this issue Oct 7, 2022 · 2 comments · May be fixed by #3559
Open
1 of 3 tasks

Make it more ergonomic to comment HTML code #2910

ctron opened this issue Oct 7, 2022 · 2 comments · May be fixed by #3559
Labels
A-yew-macro Area: The yew-macro crate documentation

Comments

@ctron
Copy link
Contributor

ctron commented Oct 7, 2022

Problem

It is not possible to ergonomically comment HTML code.

Steps To Reproduce

  1. Try to comment HTML code

Expected behavior

It should be easy as:

html!(
  <div>
   <!-- foo bar -->
  </div>
)

Or:

html!(
  <div>
    { /* foo bar */ }
  </div>
)

In the latter variant, I would expect to comment to just disappear in the output HTML. In former version (<!--) I could image to remove it as well, as it might be trouble updating the DOM tree, and doesn't add too much.

A workaround currently exists:

html!(
  <div>
    { /* foo bar */ html!() }
  </div>
)

Environment:

  • Yew version: 0.19

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later
@ctron ctron added the bug label Oct 7, 2022
@WorldSEnder
Copy link
Member

WorldSEnder commented Oct 7, 2022

html!(
  <div>
    // foo bar
  </div>
)

should work. Remember that the input to rust macros still gets processed by the rust lexer and produces a rust TokenStream. So rusty comments get thrown out before the macro even sees them.

Maybe I misunderstand and the bug is actually about getting comment tags into the output html, in that case, I don't have a quick solution ;)

@ctron
Copy link
Contributor Author

ctron commented Oct 10, 2022

Ah ok. So it is even easier as expected :) I does indeed work. So, maybe adding a section in the documentation about comments would be helpful.

@WorldSEnder WorldSEnder added documentation A-yew-macro Area: The yew-macro crate and removed bug labels Oct 10, 2022
ctron added a commit to ctron/yew that referenced this issue Dec 13, 2023
@ctron ctron linked a pull request Dec 13, 2023 that will close this issue
1 task
ctron added a commit to ctron/yew that referenced this issue Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-yew-macro Area: The yew-macro crate documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants