You are not logged in.

#1 2012-03-22 17:56:20

aardwolf
Member
From: Belgium
Registered: 2005-07-23
Posts: 305

Less strict version of tidy, to indent html-like code?

Hello,

When using Copy as HTML in the DOM tree that Chrome's developer tools show, you get the whole thing as one single line (or a few. It is one line when copying a specific element, even if it has many nested elements inside of it). For looking at this, diffing it, and so on, it is of course way handier to have it as nicely indented HTML code instead.

I tried using tidy -i for this, but by default tidy is very strict. For example the fact that if you want to indent a sub section of an html page, there's no <html> tags is already a problem for tidy.

I tried the following way to solve the html tag problem:

tidy -xml -i file.txt

But then it sometimes outputs just a small part of the whole thing.

Basically, tidy seems not to work very well for semi-correct things that you just want to indent.

Does there exist a utility that's designed to indent any part of xml-like or html-like code into nice separate lines with indentation where possible, even if some tags might be missing or not closed or whatever? Or a command line flag of tidy that I might have missed smile

Thanks!

Last edited by aardwolf (2012-03-22 17:59:46)

Offline

#2 2012-03-23 03:09:29

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: Less strict version of tidy, to indent html-like code?

You can try xmllint. (It's probably already installed on your system.  If not, it's part of libxml2 i.e. $ pacman -S libxml2)

$ xmllint --format in.html >out.html

Offline

Board footer

Powered by FluxBB