Skip to content

Instantly share code, notes, and snippets.

@TheRolfFR
Created September 22, 2022 15:23
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 TheRolfFR/6ac2fb780682b8f55542a1cc63717e40 to your computer and use it in GitHub Desktop.
Save TheRolfFR/6ac2fb780682b8f55542a1cc63717e40 to your computer and use it in GitHub Desktop.
XML ie format
let value;
let spaces;
spaces = 0;
console.log(value.split('\n').filter(f => f.trim().length !== 0).map(cur => {
if(cur.startsWith('-')) spaces ++;
else if(cur.startsWith('</')) spaces --;
else if(cur.startsWith('<')) spaces++;
let sp = '';
for(let i = 0; i < spaces; ++i) {
sp += ' ';
}
if(cur.endsWith('/>')) spaces --;
return sp + cur.replace('-<', '<');
}).join('\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment