Need help with htmlbeautifier?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

threedaymonk
230 Stars 46 Forks MIT License 135 Commits 9 Opened issues

Description

A normaliser/beautifier for HTML that also understands embedded Ruby. Ideal for tidying up Rails templates.

Services available

!
?

Need anything else?

Contributors list

# 156,040
Ruby
govuk
HTML
Shell
98 commits
# 34,247
Ruby
HTML
Shell
gitlab
10 commits
# 20,999
springf...
excepti...
Django
bottlep...
7 commits
# 187,368
ops
Git
HTML
unix
6 commits
# 733,017
Ruby
1 commit
# 169,879
Ruby
Shell
C
postgre...
1 commit
# 437,666
excel
xls
gplv3
CSS
1 commit
# 571,832
C++
Shell
C
1 commit

HTML Beautifier

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
  • Indents the left-hand margin of JavaScript and CSS blocks to match the indentation level of the code

Usage

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 = HtmlBeautifier.beautify(messy)

You can also specify how to indent (the default is two spaces):

beautiful = HtmlBeautifier.beautify(messy, indent: "\t")

Installation

This is a Ruby gem. To install the command-line tool (you may need

sudo
):
$ gem install htmlbeautifier

To use the gem with Bundler, add to your

Gemfile
:
gem 'htmlbeautifier'

Contributing

  1. 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).
  2. Include tests.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.