5

I've installed the W3C tidy-html5 bundle here: ~/Library/Application Support/Avian/Pristine Copy/Bundles/tidy-html5

However, when I run the command in Terminal, it doesn't seem to recognize HTML5 tags. It seems like it's probably running the old HTML Tidy method, which only understands XHTML/HTML4.

For example, if I run:

tidy ~/Desktop/tidy-test.html

I get this output:

line 1 column 180 - Error: <aside> is not recognized!
line 1 column 180 - Warning: discarding unexpected <aside>
line 1 column 353 - Error: <section> is not recognized!
line 1 column 353 - Warning: discarding unexpected <section>
line 1 column 418 - Warning: replacing invalid character code 139
line 1 column 419 - Warning: replacing invalid character code 134
line 1 column 421 - Warning: replacing invalid character code 139
line 1 column 422 - Warning: replacing invalid character code 134
line 1 column 424 - Warning: replacing invalid character code 139
line 1 column 425 - Warning: replacing invalid character code 134
line 1 column 427 - Warning: replacing invalid character code 139
line 1 column 428 - Warning: replacing invalid character code 134
line 1 column 430 - Warning: replacing invalid character code 139
line 1 column 431 - Warning: replacing invalid character code 134
line 1 column 432 - Warning: discarding unexpected </section>
line 1 column 443 - Error: <section> is not recognized!
line 1 column 443 - Warning: discarding unexpected <section>
line 1 column 567 - Warning: discarding unexpected </section>
line 1 column 578 - Error: <section> is not recognized!
line 1 column 578 - Warning: discarding unexpected <section>
line 1 column 645 - Warning: discarding unexpected </section>
line 1 column 656 - Warning: discarding unexpected </aside>
line 12 column 4 - Error: <canvas> is not recognized!
line 12 column 4 - Warning: discarding unexpected <canvas>
line 13 column 27 - Warning: discarding unexpected </canvas>
line 13 column 45 - Warning: discarding unexpected </html>
line 1 column 770 - Warning: trimming empty <span>
Info: Document content looks like HTML 4.01 Transitional
Info: No system identifier in emitted doctype
22 warnings, 5 errors were found!

This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.

Character codes 128 to 159 (U+0080 to U+009F) are not allowed in HTML;
even if they were, they would likely be unprintable control characters.
Tidy assumed you wanted to refer to a character with the same byte value in the 
specified encoding and replaced that reference with the Unicode equivalent.

To learn more about HTML Tidy see http://tidy.sourceforge.net
Please send bug reports to html-tidy@w3.org
HTML and CSS specifications are available from http://www.w3.org/
Lobby your company to join W3C, see http://www.w3.org/Consortium

Ideally I would like to be able to just Tidy an entire HTML5 document or selection directly in TextMate, the same way I can now for XHTML. If that's not possible, I'd like to be able to run Tidy on the command line and get back 1. a correctly reformatted/tidied document, and 2. a report of what was done to it.

suigeneris
  • 127
  • 7

1 Answers1

4

Assuming you know and use Homebrew on your machine ( OS X )
and have tidy installed using Homebrew:

$ brew uninstall tidy
$ brew tap homebrew/dupes
$ brew install --HEAD tidy
$ tidy --version
HTML Tidy for HTML5 (experimental) for Mac OS X https://github.com/w3c/tidy-    html5/tree/c63cc39

Remarks:

  • Skip the first step if you did not install tidy using Homebrew before.
  • Skip second step if you already tapped into homebrew/dupes.
Webdevotion
  • 1,223
  • 13
  • 24
  • 1
    Did brew doctor, fixed a path issue and unlinked keg described in the warnings, ran brew update, and then followed your instructions above. The version confirmed HTML Tidy for HTML5 was installed. However, when running Tidy I still get the same errors, such as "Error: – suigeneris Oct 20 '14 at 15:10
  • If I run Tidy on the command line I get different output: line 13 column 43 - Warning: discarding unexpected

    line 1 column 156 - Warning:

    – suigeneris Oct 20 '14 at 15:17
  • Got it working and giving meaningful output and proper indentation in command line by adding a config.txt file and HTML_TIDY environment var to point to it. Would love to get Tidy in TextMate pointed to the new HTML5 Tidy. Trying to do so by using this http://wiki.macromates.com/HowTo/CustomizeTidy and http://manual.macromates.com/en/environment_variables but so far no luck. I've tried adding export TM_TIDY="~/Library/Application Support/Avian/Pristine Copy/Bundles/tidy-html5/bin/tidy" to my .bash_profile, as well as variations within TextMate's Preferences > Variables. GRRRRR. – suigeneris Oct 20 '14 at 16:23
  • Now have it writing the formatted file back to the original with config write-back: yes. The indentation with indent: auto is kind of gross, but that has nothing to do with getting it working in TextMate... – suigeneris Oct 20 '14 at 19:06
  • Please accept my answer if it helped you to get Tidy up and running on the command line for HTML 5 documents. – Webdevotion Oct 22 '14 at 06:02