Indenter
This example demonstrates an algorithm for indenting HTML or XML fragment strings. It displays a minified SVG string within a `<pre>` tag, and the indentation width is animated over time using `Math.sin(Date.now() / 1000)` to cycle through different space counts. The core `indent` function parses characters, tracks indentation levels via a stack, and rebuilds the output with newlines and spaces. The rendered output is SVG, and the source string is a generated visualization markup.
AI-generated descriptionI was searching for a way to indent a generated HTML fragment string, and was frustrated that all the packages I could find for doing this seem overly complex for the task at hand:
So I thought to myself, how hard could it be to write a function that indents HTML? It should be about a page of code, and would be a fun little puzzle. This is the result from the experiment, a small function that indents an HTML or XML fragment string.
If you find this useful and would like it released as a proper package, please let me know.
Built with blockbuilder.org
<!-- Start of SimpleHitCounter Code --> <div align="center"><a href="http://www.simplehitcounter.com" target="_blank"><img src="http://simplehitcounter.com/hit.php?uid=2115161&f=16777215&b=0" border="0" height="18" width="83" alt="web counter"></a></div> <!-- End of SimpleHitCounter Code -->