百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
H

htmlbeautifier

> 编程语言
开源

一个用于 HTML 的正则化/美化工具,还支持嵌入的 Ruby 语言。非常适合整理 Rails 模板。

373 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一个用于 HTML 的正则化/美化工具,还支持嵌入的 Ruby 语言。非常适合整理 Rails 模板。

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:

bash
$ htmlbeautifier file1.html.erb [file2.html.erb ...]

or to operate on standard input and output:

bash
$ htmlbeautifier  formatted.html.erb

In your code

ruby
require 'htmlbeautifier'

beautiful = HtmlBeautifier.beautify(untify_html_string)

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

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

Installation

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

bash
$ gem install htmlbeautifier

To use the gem with Bundler, add to your Gemfile:

ruby
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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言