Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Tidy-html5 (aka HTML Tidy) recursively on all html files?

Tags:

tidy

htmltidy

I would like to run HTML Tidy (aka tidy-html5) recursively on all the html files including those in the sub-directories. While tidy -mq ./src/*.html works on all html files in the src directory, it does not run on sub-directories.

My HTML directory structure looks like this, and each directory contains multiple html files:

└── src/
    ├── 2017-12-01-post1/*.html
    ├── 2017-12-15-post2/*.html
    ├── 2018-01-03-post3/*.html
    ├── 2018-04-01-post4/*.html
    └── ... (more dir)

Is it possible to do something like tidy -mq ./src/**/*.html? (Similar to how Prettier works)

like image 885
Daniel Kim Avatar asked Nov 21 '25 03:11

Daniel Kim


1 Answers

I settled on using find command (Linux, Mac, *nix, BSD) like this :

find . -name '*.html' -type f -print -exec tidy -mq '{}' \;

This will search through the directories recursively for all HTML files and execute tidy on them.

Alternatively, in Bash, use shopt -s globstar:

shopt -s globstar
tidy -mq **/*.html

In ZSH, it just works without any other setting:

tidy -mq **/*.html
like image 152
Daniel Kim Avatar answered Nov 22 '25 18:11

Daniel Kim