/**
 * Simple Regex-based HTML Formatter for Aether Platform.
 * Adds newlines and indentation to raw HTML strings.
 */
export function format_html(html: string): string {
    if (!html) return '';

    let indent = 0;
    const tab = '    ';
    return html
        .replace(/>\s*</g, '>\n<') // Add newlines between tags
        .split('\n')
        .map((line) => {
            line = line.trim();
            if (line.match(/<\//)) indent--; // Decrease indent for closing tags
            const out = tab.repeat(Math.max(0, indent)) + line;
            if (
                line.match(/<[^\/!]/) &&
                !line.match(/\/>/) &&
                !line.match(/<\//)
            )
                indent++; // Increase indent for opening tags
            return out;
        })
        .join('\n');
}
