HTML Tidy is a powerful command-line tool used to clean up, indent, and fix broken HTML, XHTML, and XML files. It helps make markup compliant with web standards and easier to read. How to Use HTML Tidy (Command Line)
Tidy acts on files, taking input and producing cleaned output, typically defaulting to stdout (showing the result in the terminal). 1. Basic Usage (Clean and Display) tidy index.html Use code with caution.
This reads index.html and outputs the fixed HTML to your terminal screen.
2. Modify the File In-Place (Recommended)Use the -m (modify) option to overwrite the original file with the cleaned version. tidy -m index.html Use code with caution.
3. Indent and Clean UpUse -i (indent) to make the code readable. tidy -i -m index.html Use code with caution.
4. Save Errors to a FileUse -f to redirect error messages (warnings/errors) to a separate file instead of cluttering your screen. tidy -f errors.txt -m index.html Use code with caution.
5. Common “Best” CommandThis combination indents, suppresses the meta-tag warning, and keeps the file cleaner: tidy -indent –tidy-mark no -quiet -m index.html Use code with caution. Configuration Files
Instead of typing long commands, you can use a config file (e.g., tidy_config.txt). Create a text file with options, like:
indent: auto indent-spaces: 2 quiet: yes tidy-mark: no wrap: 0 Use code with caution. Run Tidy using the config: tidy -config tidy_config.txt -m index.html Use code with caution. Key Options and Customization -m (Modify): Modifies the original file. -i (Indent): Indents block elements.
-q (Quiet): Suppresses non-essential information (warnings).
–tidy-mark no: Prevents Tidy from adding a tag to the output. -asxhtml: Converts HTML to strict XHTML.
New Tags: You can teach Tidy about new tags (like HTML5 tags) in a config file: new-inline-tags: tag1, tag2 new-blocklevel-tags: tag3, tag4 Use code with caution. Integration
UltraEdit: HTML Tidy is often integrated into text editors like UltraEdit, where you can configure it via the “HTML Tidy Options” dialog.
Environment Variable: You can set the HTML_TIDY environment variable to point to your default configuration file. If you’d like, I can: Show you a sample config file for web standards. Explain how to install Tidy on your specific OS. Provide examples of how to handle specific HTML errors. Let me know what you’d like to dive deeper into. Use HTML Tidy to just indent HTML code? – Stack Overflow
Leave a Reply