Skip to main content

ERB Beautify/Minify

Format or minify ERB (Embedded Ruby) templates. Beautify adds indentation for HTML structure; minify collapses whitespace.

Overview

The ERB Beautify/Minify tool processes ERB templates as HTML:
  • Beautify — Indents HTML tags and ERB blocks with 2 spaces
  • Minify — Removes comments, collapses whitespace, and strips spaces between tags
ERB tags (<% %>, <%= %>) are preserved and treated as content nodes.

Use Cases

Rails view cleanup

Format ERB templates from Rails projects for readability

Template optimization

Minify ERB templates for production to reduce view size

Code review

Standardize ERB indentation for diffs and version control

Legacy migration

Reformat old ERB templates with consistent indentation

Actions

Indents HTML tags and ERB blocks with 2 spaces. ERB tags are treated as inline content.Input:
<div><h1><%= @title %></h1><p><%= @content %></p></div>
Output:
<div>
  <h1><%= @title %></h1>
  <p><%= @content %></p>
</div>

Implementation Details

The ERB beautifier uses the same HTML beautification algorithm as the HTML Beautify tool. ERB tags (<% %>, <%= %>, <%# %>) are treated as text content. Source: lib/tools/engine.ts:530-533
Key logic
case 'erb-beautify': {
  if (action === 'minify') return { output: minifyHtml(input) };
  return { output: beautifyHtml(input) };
}
The beautifier does not parse Ruby syntax inside ERB tags. Complex Ruby logic (multiline blocks, conditionals) may not indent perfectly.

ERB Tag Support

<p><%= user.name %></p>
Treated as inline content, no special indentation.
<% if user.admin? %>
  <p>Admin panel</p>
<% end %>
The beautifier indents based on HTML structure, not Ruby block depth.
<%# This is an ERB comment %>
Preserved during beautification, removed during minification.
For Ruby-aware formatting, use a dedicated ERB formatter like htmlbeautifier (Ruby gem). This tool focuses on HTML structure.

Keyboard Shortcuts

  • Cmd/Ctrl+Enter — Beautify (default)
  • Cmd/Ctrl+Shift+C — Copy output
  • Cmd/Ctrl+Shift+S — Download output

HTML Beautify/Minify

Format or minify HTML markup (same algorithm)

HTML Preview

Render HTML safely in an iframe

Build docs developers (and LLMs) love