HTML Utilities API reference for HTML and text formatting utility functions code API Reference
Categories

HTML Utilities

Functions for indenting text and HTML markup.

indentLines

Adds consistent indentation to every line of text.

Syntax

indentLines(text, spaces = 2)

Parameters

NameTypeDescription
textstringThe text to indent
spacesnumberNumber of spaces to indent each line (default: 2)

Returns

Indented text. Returns empty string for non-string input.

Example

indentHTML

Indents HTML markup with nesting awareness.

Syntax

indentHTML(html, { indent = ' ', startLevel = 0, trimEmptyLines = true } = {})

Parameters

NameTypeDescription
htmlstringThe HTML string to indent
optionsobjectOptional configuration

Options

NameTypeDefaultDescription
indentstring’ ‘String to use for each level of indentation
startLevelnumber0Initial nesting level to start indentation from
trimEmptyLinesbooleantrueWhether to remove empty lines from the output

Returns

Indented HTML. Returns empty string for non-string input.

Handles void elements (img, br, hr, input), self-closing tags (<component />), comments, and same-line tags (<tag>content</tag>).

Example

Previous
Functions
Next
Looping