Skip to content

Instantly share code, notes, and snippets.

@sleekweasel
Created March 25, 2020 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sleekweasel/800f3fea9e5c4d086264af67f130cc03 to your computer and use it in GitHub Desktop.
Save sleekweasel/800f3fea9e5c4d086264af67f130cc03 to your computer and use it in GitHub Desktop.
Format XML - quick bodge
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