2010-02-03 80 views
52

我正在尋找一個它滿足以下要求HTML漂亮打印機建議:一個命令行HTML漂亮打印機:讓凌亂的HTML可讀

  • 注意到HTML作爲輸入,然後再輸出一個很好的格式化/正確縮進但給定輸入HTML的「圖形等同」版本。
  • 必須支持命令行操作。
  • 必須是開放源代碼並在Linux下運行。
+4

其他選項是'pup'(不帶參數),' xmllint --format --html -'和'xml fo --html'。 – user4669748 2016-09-08 19:25:50

+0

curl https://httpbin.org/ | tidy -im – 2017-08-25 07:18:32

回答

54

更新2015:Tidy-html5也應該考慮,因爲它支持包括HTML5在內的現代標準。這是它的GitHub repository

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

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.


原件回覆:

看一看的HTML精簡項目:http://tidy.sourceforge.net/

Tidy reads HTML, XHTML and XML files and writes cleaned up markup. For HTML variants, it detects and corrects many common coding errors and strives to produce visually equivalent markup that is both W3C compliant and works on most browsers.

您的需求,這裏是命令行調用整理:

tidy -im inputfile.html 
+8

謝謝! 「tidy -i -m -w 160 -ashtml -utf8 index.html」做到了!結果在MacOS X中默認安裝完美 - 非常棒! – knorv 2010-02-03 20:07:53

+1

Tidy正在努力獲得縮進,直到我用這個選項運行它(而不是讓它默認爲「自動」與-i:tidy --indent是 – 2013-04-05 12:18:30

+1

這應該更新提及http://www.html-tidy .org。 – 2015-09-29 18:54:36

2

我認爲HTML tidy是該領域的家喻戶曉的名字之一。

7

Tidy從OS X不支持HTML5。但是有Github這樣的實驗分支。

爲了得到它:

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

這就是它!玩的開心!

+1

'錯誤: 「整潔」'。 'brew install tidy-html5'的作品。 – Pysis 2017-04-04 13:34:27

+0

確實'brew install tidy-html5'的作品,你不需要自制軟件/傻瓜水龍頭。 – 2017-11-15 10:33:57

0

只是OT問題的後期跟進。

Homebrew根據您的預期安裝了tidy-html5

它被鏈接爲tidy5

1

爲了有一個更新,操作系統無關的回答了這個問題:

雖然originalHTMLTidy項目已經dormant for over 6 years,一個"W3C Community & Business group"由名"HTML Tidy Advocacy Community Group (HTACG)"推移現在已經開始繼續發展,與目標使其完全兼容HTML5。該小組於2015年1月成立,雖然他們將當前狀態描述爲「正在進行中」,但二進制文件已經可供下載。