Given an inconsistently indented piece of html code your task is to return the same text but correctly indented
- Indent space = 4
- Assume input will be non-empty.
- Input can be taken as string or array/list of lines
- Opening and closing tags must be on the same line as long as there is not any other tag inside.
<td></td>
- Assume there will be only html tags, no text elements whatsoever
- All opening tags that aren't self-closing will have closing tags, and will be given in the correct nesting order. Self-closing tags will be closed with
/>
- Standard code-golf rules apply
Example and test-cases
Input
--------------
<table>
<tr>
<td>
</td>
<td></td></tr></table>
Output
----------
<table>
<tr>
<td></td>
<td></td>
</tr>
</table>
Input
------------
<div>
<ul>
<li></li><li></li></ul>
<ul>
<li></li>
<li></li>
</ul><div><table>
<tbody>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></tbody></table>
</div>
</div>
Output
--------------------
<div>
<ul>
<li></li>
<li></li>
</ul>
<ul>
<li></li>
<li></li>
</ul>
<div>
<table>
<tbody>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</tbody>
</table>
</div>
</div>
Input
--------------
<div><img src=""/><p></p><input/><input/></div>
Output
-------------
<div>
<img src=""/>
<p></p>
<input/>
<input/>
</div>
img
ora
? \$\endgroup\$<p><p></p>
is valid HTML (tag soup). Are you confusing HTML with XML? \$\endgroup\$<foo></foo>
can be meaningfully different than<foo>\n</foo>
if we're just talking about XML in general. \$\endgroup\$<p><p></p>
. \$\endgroup\$