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

proposal: Go comments within HTML tags #866

Open
romshark opened this issue Aug 1, 2024 · 1 comment
Open

proposal: Go comments within HTML tags #866

romshark opened this issue Aug 1, 2024 · 1 comment

Comments

@romshark
Copy link

romshark commented Aug 1, 2024

In addition to #79, I'd like to propose // comments within HTML tags, such as:

<form
  class="flex"
  // This comment here explains why the following attribute is necessary,
  // namely to prevent submit when hitting the enter key.
  // But templ won't allow this comment to be here and throws syntax errors.
  action="javascript:void(0)"
>

image

Current Workaround

Currently, the comments must be put above the HTML tag, which is not always convenient.

// Use action="javascript:void(0)" to prevent submit on enter
<form
  class="flex"
  action="javascript:void(0)"
>

Since // is not a valid token inside an HTML tag IMHO it should be possible to allow Go comments within tags that aren't included in the compiled HTML.

@bastianwegge
Copy link
Contributor

I would also love this. We are currently developing libraries for internal use and I'd also like to add some comments between alpine relevant directives:

<div
  // Alpine data initialization
  // makes this
  // does that
  x-data="{
    ...
  }"
  // Alpine component initialization
  // makes this
  // does that
  x-init="
    ...
  "
  @keydown.escape.window="commandOpen = false"
  class="relative z-50 w-auto h-auto"
>
...
</div>

We do lots of these and I'd like to add some comments to make things clearer.

@joerdav joerdav added parser NeedsDecision Issue needs some more discussion so a decision can be made proposal labels Aug 19, 2024
@linear linear bot added Migrated and removed Migrated parser NeedsDecision Issue needs some more discussion so a decision can be made proposal labels Sep 4, 2024
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

3 participants