[Proposal] Block Comment Syntax for Eex/Heex Templates

161 views
Skip to first unread message

Rich Jones

unread,
Nov 17, 2021, 8:37:12 AM11/17/21
to elixir-lang-core
Hey all!

This bubbled up from what I thought was an issue in a VSCode plugin, but is actually an issue with the language:


The issue is that in the current state of the language, there is no way to toggle comments on and off  sections of mixed ERL/HTML in Eex/Heex templates in a way that integrates nicely with a text editor, as the `%>` ending (for instance) a for loop will stop the commenting, leaving the contents of the loop exposed.

The same problem has existed for Ruby ERB templates for a long time and solutions have evolved as the language has matured. There was originally a `=begin` and `=end` syntax (ex: `<% =begin %> <% ruby_code %> <% =end %>`), but I think people found this is kind of clunky. Another strategy was to use `<% if false %><!-- start erb comment --> .. <!-- end erb comment --><% end %>`, but again, this looks weird.

A convention developed to define an empty 'comment' method in the application, as Jose suggests in issue 1761 above, so one can do `<% comment do %>..<% end %>`, however as this is a convention not a requirement, it will work but likely won't change to grey in a text editor.

I think it'd be great if we could standardize this convention, perhaps as `<.ignore>..</.ignore>', into the language itself, so that all of the syntax highlighters/language servers can implement something that works for everybody.

Thoughts?

Cheers!,
Rich

José Valim

unread,
Nov 19, 2021, 6:29:05 AM11/19/21
to elixir-l...@googlegroups.com
Something like <.ignore>..</.ignore> would not be specific to the language (EEx knows nothing about HTML) but HTML specific. Something like ERb's would be EEx specific, so we would need to decide which solution we want. If our preference is on tags, then this should go back to LiveView. :D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/fe426ec4-43b7-4a05-bab6-6075240d0713n%40googlegroups.com.

Simon McConnell

unread,
Dec 6, 2021, 3:55:28 AM12/6/21
to elixir-lang-core
<.ignore>..</ignore> still looks like a component, I guess because it is.  <.#> </#>?  <%!-- ... --%>? Is it even possible to wrap other eex tags inside, like <%!-- <% for x <- y do %> ... <% end %> ... --%>?  

We have {!-- ... --} in Surface which I use all the time.

José Valim

unread,
Dec 6, 2021, 12:32:31 PM12/6/21
to simonmc...@gmail.com, elixir-lang-core
I like the idea of supporting <%!-- --%>, that seems like a natural extension to me. :+1:

Please open up an issue. And if you desire, send a PR too!

José Valim

unread,
Dec 19, 2021, 10:48:09 AM12/19/21
to simonmc...@gmail.com, elixir-lang-core
Hi Simon, I will give a try implementing this during streaming today.

José Valim

unread,
Dec 21, 2021, 4:31:49 AM12/21/21
to elixir-lang-core
This is now in the main branch.
Reply all
Reply to author
Forward
0 new messages