Install Tidy on Raspberry Pi

Tidy is a command line tool that finds and fixes markup errors in HTML documents. This tool also supports pretty printing and fixes basic well-formedness errors in XML documents.

This tutorial explains how to install Tidy on Raspberry Pi.

Connect to Raspberry Pi via SSH. Update the package lists and install Tidy by using the following commands:

sudo apt update
sudo apt install -y tidy

When the installation is completed, we can check version of Tidy:

tidy -version

Now create HTML file for testing:

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

Run the tidy command and specify a filename as argument:

tidy test.html

Tidy cleans up and fixes HTML document and writes it to standard output. It also shows how many warnings and errors was 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>

We can use -o option to write HTML document to the specified file.

tidy -o result.html test.html

By default, Tidy embeds <meta name="generator"> tag. We can avoid this by using --tidy-mark no option. We can also use -indent option to indent content.

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

We can view the content of a HTML file:

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

If you want to completely remove Tidy and related dependencies, execute the following command:

sudo apt purge --autoremove -y tidy

Leave a Comment

Your email address will not be published. Required fields are marked *