HTML UtilitiesAPI reference for HTML and text formatting utility functionscodeAPI 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

Name Type Description
text string The text to indent
spaces number Number 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

Name Type Description
html string The HTML string to indent
options object Optional configuration

Options

Name Type Default Description
indent string ’ ’ String to use for each level of indentation
startLevel number 0 Initial nesting level to start indentation from
trimEmptyLines boolean true Whether 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