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

HtmlPretty PrintTidy

Html Problem Overview


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

  • 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 Solutions


Solution 1 - Html

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

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

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

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

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

tidy inputfile.html

Solution 2 - Html

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

brew install tidy-html5

Original reply:

Tidy from OS X doesn't support HTML5. But there is experimental branch on Github which does.

To get it:

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

That's it! Have fun!

Solution 3 - Html

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

While the original HTMLTidy project 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.

Solution 4 - Html

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

Solution 5 - Html

Just a late followup on an OT question.

Homebrew has a tidy-html5 installed as you'd expect.

It's linked up as tidy5.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionknorvView Question on Stackoverflow
Solution 1 - HtmljonjbarView Answer on Stackoverflow
Solution 2 - HtmlPaul BritView Answer on Stackoverflow
Solution 3 - Htmlzb226View Answer on Stackoverflow
Solution 4 - HtmlPekkaView Answer on Stackoverflow
Solution 5 - HtmlDave NewtonView Answer on Stackoverflow