Using Terminal To Tidy HTML Code 8
Terminal
Hey
I like writing in HTML code, its a simple programming language (if you can call it that) that offers you the ability to construct web pages for people to use. One of the most enjoyable parts of writing HTML from my point of view is making sure it is as efficient and as simple as possible. I also like having web structured code. One cool little app I have found is Tidy. Its run from Terminal, it doesn’t have many functions but is quite useful and for anyone who wants nice HTML code.
To access Tidy, open up Terminal. The following will indent all of your code so the nested elements are indent by one tab stop.
tidy -i test.html
This will create code that is well indented. Due to the way the program works you have to copy and paste the resultant code out of the Terminal window. I can’t find a simple method to copy the resulting code.
You can do more than indent code. If you replace “i” in the code above with -omit, it will omit additional tags. You can add -u to make tags to upper case. -e will show your errors which is very useful for finding problems and making sure you code is up to scratch. Finally -q will make the output be in quite mode, which means that any no-essential text will not be shown.
This tool is quite useful. To find out more information about it simply type “man tidy” into Terminal to see the manual page.
If Terminal is not up your street you can also use a Service menu item. Its called Tidy Service, and is designed to do a similar thing to the Terminal option.
Where To Next?
8 Responses to “Using Terminal To Tidy HTML Code”
-
1
Nice tip. I did not know that tidy was installed on OS X. Another great utility is perltidy. It’s not on OS X but can be installed quite easily using perl’s CPAN.
As admin
:~ admin: sudo cpan
cpan> install Perl::TidyComment By Khürt Williams on July 16th, at 12:20 pm
-
2
I’ll have a look at that, thanks for the heads up.
Comment By admin on July 16th, at 2:01 pm
-
3
“-$ man tidy
No manual entry for tidy”Is there a way to install additional man pages?
Comment By mdbookworm on July 16th, at 3:18 pm
-
4
There is but I can’t remember what it is. Just search the net for the man page (its somewhere). You could also do “tidy -h” to get a condensed version.
Comment By admin on July 16th, at 3:40 pm
-
5
There is a way to output the resulting code output to a file … But I’m not sure because I do not ofen use it… But I think it’s along the lines of “> file.ext”
tidy -i file.html > file_tidy.html
if you do that to a file that already exists, or the same file, I think you will just append the output …
Comment By NickiSophie on July 16th, at 4:37 pm
-
6
tidy -i INPUT_FILE -o OUTPUT_FILE will do the same job as the redirect in the previous comment.
There is a ton of documentation available on http://tidy.sourceforge.net/
Comment By Francis Mahon on July 16th, at 7:44 pm
-
7
Looking forward to reading more. Great blog.Much thanks again. Cool.
Comment By Jovanni Hausman on January 4th, at 9:17 am
-
8
Thanks again for the article post.Thanks Again.
Comment By Rey Damiano on January 9th, at 7:27 am