Daniel Kim
Daniel Kim

Reputation: 1025

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

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)

Upvotes: 3

Views: 1537

Answers (1)

Daniel Kim
Daniel Kim

Reputation: 1025

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

Upvotes: 3

Related Questions