giovedì 4 marzo 2010

HTML Tidy batch process

How to loop HTML Tidy through an offline website structure?
Using some simple batch commands we can tidy up our files.
Obviously we'll write a file and name it as "mybatch.bat" and we'll save it in the same folder of the tidy.exe executable. Optionally we can move it to the rootfolder of our website

The charset used is "charset=iso-8859-1" -> parameter --char-encoding latin1

A simple version

@echo off
for /r "C:\yourfolder" %%i in (*.html *.htm) do (
echo %%i
tidy.exe --char-encoding latin1 -m "%%i"
)


Launching the batch from the command line we can pass the root folder of the website to it. e.g. this.bat "myrootfolder"
@echo off
for /r %1 %%i in (*.html *.htm) do (
echo %%i
tidy.exe --char-encoding latin1 -m "%%i"
)


If you're using css for defining custom tags you'll need a parameter of HTMLtidy called --new-inline-tags and you must specify the tag inside the quotes.
--new-inline-tags "def"
@echo off
for /r %1 %%i in (*.html *.htm) do (
echo %%i
tidy.exe --char-encoding latin1 --new-inline-tags "def" -m "%%i"
)


For istance also in this case we can pass the tags as parameters changing the code as follows:
@echo off
for /r %1 %%i in (*.html *.htm) do (
echo %%i
tidy.exe --char-encoding latin1 --new-inline-tags "%2" "%3" -m "%%i"
)

and calling the batch as
this.bat "myrootfolder" mytag1 mytag2


Have fun,
Stefano

Nessun commento:

Posta un commento

Lascia un commento...