markmark206
HEEX formatter adds a line break in generated html?
HEEX formatter (Phoenix.LiveView.HTMLFormatter / mix format) seems to introduce an unexpected line break in the generated html. User error? A bug? ; )
This looks super-related to Formatter adds space/newline to inline elements · Issue #2237 · phoenixframework/phoenix_live_view · GitHub, but, AFAICT, the fix got merged in LiveView 0.18.2, and I am seeing the problem in 0.18.3.
Details:
Here is my repro (happy to provide a more streamline repro gist, if useful):
I want to add a comma after some text
<%= link to: ... do %>
<%= @item.content %><% end %>,
and this works great. Here is the web page (loaded in Safari, on a Mac):

Running mix format, moves the <% end %> element (and, therefore, the comma that follows) to its own line:
<%= link to: ... do %>
<%= @item.content %>
<% end %>,
which introduces a space before the comma:

I am not expecting a code formatter to change what the code does, only what the code looks like. Am I doing something obviously silly here, or does this look like a bug? ; )
Thank you!
PS A bit more data:
$ cat .formatter.exs
[
line_length: 120,
import_deps: [:ecto, :phoenix],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
$ cat mix.exs | grep phoenix
{:phoenix, "~> 1.6"},
{:phoenix_ecto, "~> 4.4"},
{:phoenix_html, "~> 3.2"},
{:phoenix_live_dashboard, "~> 0.7"},
{:phoenix_live_reload, "~> 1.4", only: :dev},
{:phoenix_live_view, "~> 0.18.3"},
$ elixir --version
Erlang/OTP 25 [erts-13.1.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]
Elixir 1.14.1 (compiled with Erlang/OTP 25)
Most Liked
markmark206
Update: this is by design:
https://github.com/phoenixframework/phoenix_live_view/issues/2374#issuecomment-1367975229
Thank you, José!
BartOtten
I guess this has to do with how how HTML is specced. Browsers condense multiple whitespace characters (including newlines) to a single space for most scripts (Latin for example).
Can you show us the generated HTML source? Won’t be surprised when it looks like
<a href=“http://foo.com”>content</a>
,
or
<a href=“http://foo.com”>
content
</a>
,
However…as this is code and not HTML I guess the formatter should recognize such and this is a bug.
zachallaun
In the meantime, you could do:
<%= link to: ... do %>
<%= "#{@item.content}," %>
<% end %>
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








