Skip to content

Conversation

madlep
Copy link
Contributor

@madlep madlep commented Sep 16, 2025

In the case where an inline tag has a nested inline tag, and there are spaces before and after text in the parent tag, extra spaces are continually appended each time HTML is formatted (ie if formatting on autosave in an editor, this keeps pumping on spaces every time a template is saved)

This is funny when you spam save in neovim, and you see a little HTML tag crawl across the buffer like a worm 😆 - but ends up in way too much git diff spam

Screen.Recording.2025-09-16.at.5.47.25.pm.mov

e.g.

str = "<a> foo <b>bar</b></a>"

str
|> Phoenix.LiveView.HTMLFormatter.format([])
# "<a> foo  <b>bar</b></a>\n"

str
|> Phoenix.LiveView.HTMLFormatter.format([])
|> Phoenix.LiveView.HTMLFormatter.format([])
"<a> foo   <b>bar</b></a>\n"

str
|> Phoenix.LiveView.HTMLFormatter.format([])
|> Phoenix.LiveView.HTMLFormatter.format([])
|> Phoenix.LiveView.HTMLFormatter.format([])
"<a> foo    <b>bar</b></a>\n"

Check if text whitespace is being preserved, and don't add flex_break(" ") if so, just allowing cond block to drop down and add "" as a separator in this case.

…e tags

In the case where an inline tag has a nested inline tag, and there are
spaces before and after text in the parent tag, extra spaces are
continually appended each time HTML is formatted (ie if formatting on
autosave in an editor, this keeps pumping on spaces every time a
template is saved)

This is funny when you spam save in neovim, and you see a little HTML
tag crawl across the buffer like a worm :D - but ends up in way too much
git diff spam

e.g.

    ```elixir
    str = "<a> foo <b>bar</b></a>"

    str
    |> Phoenix.LiveView.HTMLFormatter.format([])
    # "<a> foo  <b>bar</b></a>\n"

    str
    |> Phoenix.LiveView.HTMLFormatter.format([])
    |> Phoenix.LiveView.HTMLFormatter.format([])
    "<a> foo   <b>bar</b></a>\n"

    str
    |> Phoenix.LiveView.HTMLFormatter.format([])
    |> Phoenix.LiveView.HTMLFormatter.format([])
    |> Phoenix.LiveView.HTMLFormatter.format([])
    "<a> foo    <b>bar</b></a>\n"
    ```
@SteffenDE SteffenDE requested a review from josevalim September 16, 2025 10:48
@SteffenDE SteffenDE merged commit 975d4a5 into phoenixframework:main Sep 18, 2025
7 checks passed
@SteffenDE
Copy link
Collaborator

Thank you! 🙌🏻

SteffenDE pushed a commit that referenced this pull request Sep 18, 2025
…e tags (#3995)

In the case where an inline tag has a nested inline tag, and there are
spaces before and after text in the parent tag, extra spaces are
continually appended each time HTML is formatted (ie if formatting on
autosave in an editor, this keeps pumping on spaces every time a
template is saved)

This is funny when you spam save in neovim, and you see a little HTML
tag crawl across the buffer like a worm :D - but ends up in way too much
git diff spam

e.g.

    ```elixir
    str = "<a> foo <b>bar</b></a>"

    str
    |> Phoenix.LiveView.HTMLFormatter.format([])
    # "<a> foo  <b>bar</b></a>\n"

    str
    |> Phoenix.LiveView.HTMLFormatter.format([])
    |> Phoenix.LiveView.HTMLFormatter.format([])
    "<a> foo   <b>bar</b></a>\n"

    str
    |> Phoenix.LiveView.HTMLFormatter.format([])
    |> Phoenix.LiveView.HTMLFormatter.format([])
    |> Phoenix.LiveView.HTMLFormatter.format([])
    "<a> foo    <b>bar</b></a>\n"
    ```
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

Successfully merging this pull request may close these issues.

3 participants