Given a string like this:
' \n <div id="a">\n <span class="b">\n<span>Hello</span>\n\n\n</span> <input type="text">\n \n</div>\n '
I'd like to format it like this:
<div id="a">
<span class="b">
<span>Hello</span>
</span>
<input type="text">
</div>
i.e. the result should be: (assume 2 spaces for indentation)
'<div id="a">\n <span class="b">\n <span>\n Hello\n </span>\n </span>\n <input type="text">\n</div>'
What's the most elegant way to achieve this? Is there an established way to do that?
Note:
- I'm not looking for HTML syntax highlighting, just indentation correction
- I'm not looking to support the whole HTML spec, correcting basic HTML like the example above would suffice
<div><span></div></span>
?