A normaliser/beautifier for HTML that also understands embedded Ruby. Ideal for tidying up Rails templates.
What it does
- Normalises hard tabs to spaces (or vice versa)
- Removes trailing spaces
- Indents after opening HTML elements
- Outdents before closing elements
- Collapses multiple whitespace
- Indents after block-opening embedded Ruby (if, do etc.)
- Outdents before closing Ruby blocks
- Outdents elsif and then indents again
From the command line
To update files in-place:
$ htmlbeautifier file1 [file2 ...]
or to operate on standard input and output:
$ htmlbeautifier < input > output
In your code
require 'htmlbeautifier' beautiful = .(messy)
You can also specify how to indent (the default is two spaces):
beautiful = .(messy, indent: "\t")
This is a Ruby gem.
To install the command-line tool (you may need
$ gem install htmlbeautifier
To use the gem with Bundler, add to your
- Follow these guidelines when writing commit messages (briefly, the first line should begin with a capital letter, use the imperative mood, be no more than 50 characters, and not end with a period).
- Include tests.