Install Tidy on Ubuntu 22.04

Install Tidy on Ubuntu 22.04

Tidy is a command line tool for finding and fixing markup errors in HTML documents. It also supports pretty printing and allows fixing basic well-formedness errors in XML documents.

This tutorial demonstrates how to install Tidy on Ubuntu 22.04.

Install Tidy

Update the package lists:

sudo apt update

Run the following command to install Tidy:

sudo apt install -y tidy

To verify that Tidy is installed, check version:

tidy -version

Testing Tidy

For testing purpose, create HTML file:

echo '<!DOCTYPE html><html><head></head><body>Test</body></html>' > test.html

Run the tidy command by providing filename as argument:

tidy test.html

Tidy cleans up and fixes the HTML document and writes it to standard output. It also shows how many warnings and errors were found.

line 1 column 22 - Warning: inserting missing 'title' element
Info: Document content looks like HTML5
Tidy found 1 warning and 0 errors!

<!DOCTYPE html>
<html>
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 for Linux version 5.6.0">
<title></title>
</head>
<body>
Test
</body>
</html>

The -o option can be used to write an HTML document to the given file.

tidy -o result.html test.html

By default, the <meta name="generator"> tag is embedded in the output. Use --tidy-mark no option to avoid this. Also, the -indent option can be used to indent content.

tidy --tidy-mark no -indent -o result.html test.html

View output as follows:

cat result.html
<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
  Test
</body>
</html>

Uninstall Tidy

If you wish to completely remove Tidy and related dependencies, run the following command:

sudo apt purge --autoremove -y tidy

Leave a Comment

Cancel reply

Your email address will not be published.