Created
March 25, 2020 23:32
-
-
Save sleekweasel/800f3fea9e5c4d086264af67f130cc03 to your computer and use it in GitHub Desktop.
Format XML - quick bodge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -ple 'while (/>(<.*?>)/) { | |
s{>(<.*?>)([^<]*)}{ | |
$i++; | |
$i-=1 if substr($1,0,2) eq "</"; | |
$s=">\n".(" "x$i).$1.$2; | |
$i-=1 if substr($1,0,2) eq "</" or $2 ne ""; | |
$i-=2 if substr($1,0,2) eq "</" and $2 ne ""; | |
$i-=1 if substr($1,-2) eq "/>"; | |
$s | |
}e | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment