Skip to content

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Nov 16, 2025

This pull request updates the formatter to add intelligent element grouping and improved multiline element spacing.

The formatter now uses capture() to render each element and checks if the output is multiline. If we have multiline elements we add surrounding newlines to help visually separate them. This is in favor of the previous hard-coded list of elements that had this behavior, which should make it more natural and consistent.

The formatter now groups consecutive same-type single-line elements together. When there are 2 or more consecutive single-line elements of the same tag type (like <meta>, <link>, or ERB tags), they're kept together with no spacing within the group, and spacing is only added at boundaries between different groups.

Single-line comments stay attached to following elements without spacing, but when both a comment and the following element are multiline, spacing is added between them for better readability.

<head>
  <meta name="viewport" content="width=device-width">
  <meta name="description" content="My site">
  <meta charset="utf-8">

  <link rel="stylesheet" href="styles.css">
  <link rel="icon" href="favicon.ico">
</head>
<div>
  <% user = current_user %>
  <% time = Time.now %>

  <%= user.name %>
  <%= time.strftime("%Y") %>
</div>

Resolves #504
Resolves #881

@marcoroth marcoroth merged commit 0448cee into main Nov 16, 2025
12 checks passed
@marcoroth marcoroth deleted the formatter-element-spacing branch November 16, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment