How to use Tidy |
Release Notes |
Downloading Tidy |
Acknowledgements
Introduction to TIDY
When editing HTML it's easy to make mistakes. Wouldn't it be
nice if there was a simple way to fix these mistakes automatically
and tidy up sloppy editing into nicely layed out markup? Well now
there is! Dave Raggett's HTML TIDY is a free utility for doing just
that. It also works great on the atrociously hard to read markup
generated by specialized HTML editors and conversion tools, and can
help you identify where you need to pay further attention on making
your pages more accessible to people with disabilities.
Tidy is able to fix up a wide range of problems and to bring to
your attention things that you need to work on yourself. Each item
found is listed with the line number and column so that you can see
where the problem lies in your markup. Tidy won't generate a
cleaned up version when there are problems that it can't be sure of
how to handle. These are logged as "errors" rather than
"warnings".
Examples of TIDY at work
Tidy corrects the markup in a way that matches where possible
the observed rendering in popular browsers from Netscape and
Microsoft. Here are just a few examples of how TIDY perfects your
HTML for you:
Missing or mismatched end tags are detected and
corrected
<h1>heading
<h2>subheading</h3>
is mapped to
<h1>heading</h1>
<h2>subheading</h2>
End tags in the wrong order are corrected:
<p>here is a para <b>bold <i>bold italic</b> bold?</i> normal?
is mapped to
<p>here is a para <b>bold <i>bold italic</i> bold?</b> normal?
Fixes problems with heading emphasis
<h1><i>italic heading</h1>
<p>new paragraph
In Netscape and Internet Explorer this causes everything
following the heading to be in the heading font size, not the
desired effect at all!
Tidy maps the example to
<h1><i>italic heading</i></h1>
<p>new paragraph
Recovers from mixed up tags
<i><h1>heading</h1></i>
<p>new paragraph <b>bold text
<p>some more bold text
Tidy maps this to
<h1><i>heading</i></h1>
<p>new paragraph <b>bold text</b>
<p><b>some more bold text</b>
Getting the <hr> in the right place:
<h1><hr>heading</h1>
<h2>sub<hr>heading</h2>
Tidy maps this to
<hr>
<h1>heading</h1>
<h2>sub</h2>
<hr>
<h2>heading</h2>
Adding the missing "/" in end tags for anchors:
<a href="#refs">References<a>
Tidy maps this to
<a href="#refs">References</a>
Perfecting lists by putting in tags missed out:
<body>
<li>1st list item
<li>2nd list item
is mapped to
<body>
<ul>
<li>1st list item</li>
<li>2nd list item</li>
</ul>
Missing quotes around attribute values are added
Tidy inserts quote marks around all attribute values for you. It
can also detect when you have forgotten the closing quote mark,
although this is something you will have to fix yourself.
Unknown/Proprietary attributes are reported
Tidy has a comprehensive knowledge of the attributes defined in
the HTML 4.0 recommendation from W3C. This often allows you to spot
where you have mistyped an attribute or value.
Proprietary elements are recognized and reported as
such.
Tidy will even work out which version of HTML you are using and
insert the appropriate DOCTYPE element, as per the W3C
recommendations.
Tags lacking a terminating '>' are spotted
This is something you then have to fix yourself as Tidy is
unsure of where the > should be inserted.
Layout style
You can choose which style you want Tidy to use when it
generates the cleaned up markup: for instance whether you like
elements to indent their contents or not.
Internationalization issues
Tidy offers you a choice of character encodings: US ASCII, ISO
Latin-1, UTF-8 and the ISO 2022 family of 7 bit encodings. The full
set of HTML 4.0 entities are defined. Cleaned up output uses HTML
entity names for characters when appropriate. Otherwise characters
outside the normal range are output as numeric character
entities.
Accessibility
Tidy offers advice on accessibility problems for people using
non-graphical browsers. The most common thing you will see is the
suggestion you add a summary attribute to table elements. The idea
is to provide a summary of the table's role and structure suitable
for use with aural browsers.
Cleaning up presentational markup
Many tools generate HTML with an excess of FONT, NOBR and CENTER
tags. Tidy's -clean option will replace them by style
properties and rules using CSS. This makes the markup easier to
read and maintain as well as reducing the file size! Tidy is
expected to get smarter at this in the future.
Support for XML
XML processors compliant with W3C's XML 1.0 recommendation are
very picky about which files they will accept. Tidy can help you to
fix errors that cause your XML files to be rejected. Tidy doesn't
yet recognize all XML features though, e.g. it doesn't yet
understand CDATA sections or DTD subsets.
Creating Slides
The -slides option allows you to burst a single HTML
file into a number of linked slides. Each H1 element in the input
file is treated as delimiting the start of a slide. The slides are
named slide1.html, slide2.html, slide3.html etc. This is a new
feature and ideas are welcomed as to how to improve it.
Indenting text for a better layout
<html>
<head>
</head>
<body>
<p>
para which has enough text to cause a line break, and so test
the wrapping mechanism for long lines.
</p>
<pre>This is
<em>genuine
preformatted</em>
text
</pre>
<ul>
<li>
1st list item
</li>
<li>
2nd list item
</li>
</ul>
<!-- end comment -->
</body>
</html>
and this is the default style:
<html>
<head>
</head>
<body>
<p>para which has enough text to cause a line break, and so test
the wrapping mechanism for long lines.</p>
<pre>This is
<em>genuine
preformatted</em>
text
</pre>
<ul>
<li>1st list item </li>
<li>2nd list item</li>
</ul>
<!-- end comment -->
</body>
</html>
tidy [[options] filename]*
HTML tidy is not (yet) a windows program. If you run tidy
without any arguments, it will just sit there waiting to read
markup on the stdin stream. Tidy's input and output default to
stdin and stdout respectively. Errors are written to stderr but can
be redirected to a file with the -f filename option.
I generally use the -m option to get tidy to update the original
file, and if the file is particularly bad I also use the -f option
to write the errors to a file to make it easier to review them.
Tidy supports a small set of character encoding options. The
default is ASCII, which makes it easy to edit markup in regular
text editors.
For instance:
tidy -f errs.txt -m index.html
which runs tidy on the file "index.html" updating it in place
and writing the error messages to the file "errs.txt". Its a good
idea to save your work before tidying it, as with all complex
software, tidy may have bugs. If you find any please let me
know!
To get a list of available options use:
tidy -help
You should see something like this:
options for tidy vers: 11th June 1998
-indent or -i indent element content
-omit or -o omit optional endtags
-wrap 72 wrap text at column 72 (default is 68)
-upper or -u force tags to upper case
-clean or -c replace font, nobr & center tags by CSS
-raw don't o/p entities for chars 128 to 255
-ascii use ASCII for output, Latin-1 for input
-latin1 use Latin-1 for both input and output
-utf8 use UTF-8 for both input and output
-iso2022 use ISO2022 for both input and output
-numeric or -n output numeric rather than named entities
-modify or -m to modify original files
-errors or -e show only error messages
-f file write errors to file
-xml use this when input is in XML
-asxml to convert HTML to XML
-slides to burst into slides on h1 elements
-help list command line options
Input and Output default to stdin/stdout respectively. Single
letter options apart from -f may be combined as in: tidy -f
errs.txt -imu foo.html
22nd January 1999
Tidy no longer complains about a missing </tr> before
a <tbody>. Added link to a free win32 GUI for tidy .
11th January 1999
Added a link to the OS/2 distribution of Tidy made available by
Kaz SHiMZ. No changes to Tidy's source code.
7th January 1999
Fixed bug in ParseBlock that resulted in nested table cells.
Fixed clean.c to add the style property "text-align:" rather than
"align:".
Disabled line wrapping within HTML alt, content and value attribute
values. Wrapping will still occur when output as XML.
16th December 1998
This release fixes a problem with missing quotemarks in attribute
values introduced in the December 14th release. It also fixes problems
with parsing tables when the table cells include naked list items and
when unexpected end tags are encountered for td and tr cells. Warnings
are now generated for unknown entities (those not defined by HTML 4.0).
It may be worth thinking about a new option to determine how to handle
these, especially for XML.
14th December 1998
Rewrote parser for elements with CDATA content to fix problems
with tags in script content.
New pretty printer for XML mode. I have also modified the XML
parser to recognize xml:space attributes appropriately. I have yet
to add support for CDATA marked sections though.
script and noscript are now allowed in inline content.
To make it easier to drive tidy from scripts, it now returns
2 if any errors are found, 1 if any warnings are found, otherwise
it returns 0. Note tidy doesn't generate the cleaned up markup
if it finds errors other than warnings.
Fixed bug causing the column to be reported incorrectly when
there are inline tags early on the same line.
Added -numeric option to force character entities to be written
as numeric rather than as named character entities. Hexadecimal
character entities are never generated since Netscape 4 doesn't
support them.
Entities which aren't part of HTML 4.0 are now passed through
unchanged, e.g. &precompiler-entity; This means that an isolated
& will be pass through unchanged since there is no way to
distinguish this from an unknown entity.
Tidy now detects malformed comments, where something other
than whitespace or '--' is found when '>' is expected at the
end of a comment.
The <br> tags are now positioned at the start of a blank
line to make their presence easier to spot.
The -asxml mode now inserts the appropriate Voyager html namespace
on the html element and strips the doctype. The html namespace will
be usable for rigorous validation as soon as W3C finishes work on
formalizing the definition of document profiles, see: WD-html-in-xml .
13th November 1998 and earlier releases
Fixed bug wherein <style type=text/css> was written
out as <style type="text/ss">.
Tidy now handles wrapping of attributes containing JavaScript
text strings, inserting the line continuation marker as needed, for
instance:
onmouseover="window.status='Mission Statement, \
Our goals and why they matter.'; return true"
You can now set the wrap margin with the -wrap option.
When the output is XML, tidy now ensures the content starts with
<?xml version="1.0"?>.
The Document type for HTML 2.0 is now "-//IETF//DTD HTML 2.0//".
In previous versions of tidy, it was incorrectly set to
"-//W3C//DTD HTML 2.0//".
When using the -clean option isolated FONT elements are now
mapped to SPAN elements. Previously these FONT elements were simply
dropped.
NOFRAMES now works fine with BODY element in frameset
documents.
Future releases may address:
Adding support for a configuration file to cater for a much
wider range of options. Allowing the file to be specified via an
environment variable or command line argument.
Recursion through subdirectories, so you can fix up your entire
web site at one go. This assumes I can find a way that is portable
across a wide range of platforms!
Support for W3C's Document
Object Model (DOM) level one.
Full validation of all attribute values.
Better knowledge of proprietary tags and attributes.
Mapping Unicode bidi control characters to HTML tags.
Full support for parsing XML (still somewhat limited).
How to say which XML elements should be printed "inline".
Acting on the XML encoding attribute, e.g.
<?xml encoding="iso-8859-1">
Translation of attributes in XML documents
Improved mapping from HTML presentation attributes/elements to
CSS.
The code is in ANSI C and uses the C standard library for i/o.
The parser is thread-safe although the code for pretty printing the
parse tree is not (yet). The parser works top down, building a
complete parse tree in memory. Document text is held as Unicode
represented as UTF-8 in a character buffer that expands as needed.
The code has so far been tested on Windows'95, Windows NT, Linux,
MacOS, BeOS, OS2, SunOS, Solaris, IRIX and HP-UX, amongst others.
If you are prepared to maintain a public URL for
HTML Tidy compiled for a specific platform, please let me know so
that I can add a link to your page. This will avoid the need for
me to update this page whether you recompile.
tidy22jan99.tgz
gzipped tar file for source code (Unix line ends)
tidy22jan99.zip
zipped source code (Windows line ends)
tidy.exe
Windows 95/NT executable (32-bit Windows console-mode
program)
tidy17dec98.ppc.tgz
Gzipped archive of the binary for BeOS PPC R4. It also
contains complete tidy distribution and Makefile.BeOS file for
BeOS (from 17dec98 release of tidy).
Tidy on OS/2
Zipped archive of the OS/2 release of tidy, as compiled
by Kaz SHiMZ <kshimz@sfc.co.jp >
tidy.lha
Amiga executable (1st September 1998 version)
platform.h ,
html.h
the include files with common definitions
lexer.c
lexical analysis and buffer management
parser.c
HTML and XML parsers
tags.c
dictionary of tags and their properties
attrs.c
dictionary of attributes and their properties
istack.c
stack of active inline elements
entities.c
dictionary of entities
clean.c
smarts for cleaning up presentational markup
pprint.c
pretty printing for HTML and XML
localize.c
Change this file to localize tidy's messages
tidy.c
main() and error reporting routines
Makefile
Makefile for gcc
Conventions for whether lines end with CRLF, LF or CR vary
from one system to another. I have included the C source for a
utility tab2space which can be used to ensure that files
use the line end convention of your choice, and to expand
tabs to spaces.
tab2space -t4 -unix *.h *.c
tab2space -tabs -unix Makefile
Note use of "-tabs" to ensure that tabs are preserved in
the Makefile (it won't work without them!).
For those of you on Unix, here is a script you can use to strip
carriage returns:
#!/bin/sh
echo Stripping Carriage Returns from files...
for i
do
# If a writable file
if [ -f $i ]
then
if [ -w $i ]
then
echo $i
# strip CRs from input and output to temp file
tr -d '\015' < $i > toix.tmp
mv toix.tmp $i
else
echo $i: write-protected
fi
else
echo $i: not a file
fi
done
Save this script to a file, e.g. "scripcr " and use
"chmod +x stripcr " to make it executable. You can then
run it as "stripcr *.c *.h Overview.html Makefile "
I would like to thank the many people who have written to me
with suggestions for improvments or reporting bugs. Your help
has been invaluable.
Joe D'Andrea,
Jerry Andrews,
Christer Bernerus,
Keith Blakemore-Noble,
Eric Blossom,
Keith B. Brown,
Maurice Buxton,
Trevor Carden,
Kendall Clark,
Jeremy Clulow,
Dan Connolly,
Keith Davies,
Claus André Färber,
Stephanie Foott,
Michael Giroux,
Léa Gris,
Francisco Guardiola,
Juha Häikiö,
G. Ken Holman,
Rick Jelliffe,
Charles LaFountain,
Michael Kay,
Johannes Koch,
Rudy Kohut,
Nick Leverton,
Dietmar Lippold,
Gert-Jan C. Lokhorst,
Anton Marsden,
Ian McKellar,
Matt Oshry,
Gerald Oskoboiny,
Ernst Paalvast,
Ross L. Richardson,
Philip Riebold,
Erik Rossen,
Klaus Johannes Rusch,
Eric Schindler,
J. Schlauch,
Christian Schüler,
Jim Seymour,
Kazuyoshi SHIMIZU,
Geoff Sinclair,
Jo Smith,
Michael J. Suzio,
Oren Tirosh,
Charles A. Upsdell,
Larry W. Virden,
Jez Wain
Dave
Raggett <dsr@w3.org > is
an engineer from Hewlett Packard 's
UK Laboratories , and works on
assignment to the World Wide Web Consortium, where he is the W3C
lead for HTML, Math and Voice Browsers.
O.C. & J.M.B., 12.02.1999 :
J.M.B., 14.02.1999 :
'tidy.c ', add line to line 767:
fprintf(errout, "\n** TIDY **, version 22nd January 1999 for AIUB at work ...\n");
fprintf(errout, "\nParsing \"%s\"\n", file);
searched for in tidy directory by
'grep "Parsing" ` find . -name "*" ` ';
'localize.c ', line 418, changing/adding the lines:
fprintf(errout, "Especially for AIUB users the WWW Manual HPAM is recommended,\n");
fprintf(errout, "see URL: \"http://www.astro.uni-bonn.de/~webstw/w3_man.html\".\n\n");
fprintf(errout, "Please send bug reports for this W3C utility Tidy from AIUB\n");
fprintf(errout, "domain to Jochen M. Braun <jbraun@astro.uni-bonn.de>,\n");
fprintf(errout, "otherwise to the author, Dave Raggett <dsr@w3.org>\n\n");
after original line:
fprintf(errout, "HTML specifications are available at \"http://www.w3.org/\".\n");
searched for by 'grep "advice" ` find . -name "*" ` ';
'localize.c ', line 430, adding the line:
fprintf(errout, "or enter \"man tidy\" after UNIX prompt\n");
after original line:
fprintf(errout, "see http://www.w3.org/People/Raggett/tidy/\n");
'localize.c ', line 454, adding the lines:
fprintf(errout, "or especially for AIUB users the WWW Manual HPAM at URL:\n");
fprintf(errout, " http://www.astro.uni-bonn.de/~webstw/w3_man.html.\n");
after original line:
fprintf(errout, "For further info on HTML see http://www.w3.org/MarkUp\n");
searched for by:
'grep "Input/Output default" ` find . -name "*" ` ';