命令行 HTML 漂亮打印机:使凌乱的 HTML 可读

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2191989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:06:12  来源:igfitidea点击:

A command-line HTML pretty-printer: Making messy HTML readable

htmlpretty-printtidy

提问by knorv

I'm looking for recommendations for HTML pretty printers which fulfill the following requirements:

我正在寻找符合以下要求的 HTML 漂亮打印机的建议:

  • Takes HTML as input, and then output a nicely formatted/correctly indented but "graphically equivalent" version of the given input HTML.
  • Must support command-line operation.
  • Must be open-source and run under Linux.
  • 将 HTML 作为输入,然后输出给定输入 HTML 的格式良好/缩进正确但“图形等效”的版本。
  • 必须支持命令行操作。
  • 必须是开源的并在 Linux 下运行。

采纳答案by jonjbar

Have a look at the HTML Tidy Project: http://www.html-tidy.org/

看看 HTML Tidy 项目:http: //www.html-tidy.org/

The granddaddy of HTML tools, with support for modern standards.

HTML 工具的鼻祖,支持现代标准。

There used to be a fork called tidy-html5 which since became the official thing. Here is its GitHub repository.

曾经有一个名为 tidy-html5 的叉子,它后来成为官方的东西。这是它的GitHub 存储库

Tidy is a console application for Mac OS X, Linux, Windows, UNIX, and more. It corrects and cleans up HTML and XML documents by fixing markup errors and upgrading legacy code to modern standards.

Tidy 是适用于 Mac OS X、Linux、Windows、UNIX 等的控制台应用程序。它通过修复标记错误和将遗留代码升级到现代标准来纠正和清理 HTML 和 XML 文档。

For your needs, here is the command line to call Tidy:

根据您的需要,这里是调用 Tidy 的命令行:

tidy inputfile.html

回答by Paul Brit

Update 2018:The homebrew/dupesis now deprecated, tidy-html5 may be directly installed.

更新2018:homebrew/dupes现在已经废弃,整洁,HTML5可以直接安装。

brew install tidy-html5


Original reply:

原回复:

Tidyfrom OS X doesn't support HTML5. But there is experimental branch on Githubwhich does.

Tidy从 OS X 不支持HTML5. 但是有一个实验分支Github

To get it:

为拿到它,为实现它:

 brew tap homebrew/dupes
 brew install tidy --HEAD
 brew untap homebrew/dupes

That's it! Have fun!

就是这样!玩得开心!

回答by zb226

To have an updated, OS-agnostic answer to this question:

要对此问题提供更新的、与操作系统无关的答案:

While the originalHTMLTidyproject has been dormant for over 6 years, a "W3C Community & Business group"that goes by the name "HTML Tidy Advocacy Community Group (HTACG)"has now begun to continue its development, with the goal of making it fully HTML5-compatible. The group was formed in January 2015 and although they describe the current state as "work in progress", binaries are already available for download.

虽然最初的HTMLTidy项目已经休眠了 6 年多,但一个名为“HTML Tidy Advocacy Community Group (HTACG)”“W3C Community & Business group”现在已经开始继续发展,其目标是使完全兼容 HTML5。该小组成立于 2015 年 1 月,尽管他们将当前状态描述为“正在进行中”,但二进制文件已经可供下载。

回答by Pekka

I think HTML tidyis one of the household names in that field.

我认为HTML tidy是该领域家喻户晓的名字之一。

回答by Dave Newton

Just a late followup on an OT question.

只是对 OT 问题的迟到跟进。

Homebrew has a tidy-html5installed as you'd expect.

Homebrewtidy-html5如您所愿安装了。

It's linked up as tidy5.

它链接为tidy5.