test/html-formatter.js
/**
     * Insert leaf elements on one indented line if shorter than the character limit.
     * Insert closing tags of elements with not content immediately after the opening tag if shorter
     *   than the character limit.
     * Otherwise, insert closing tags on new indented lines.
     */
Insert leaf elements on one indented line if shorter than the character limit.
Insert closing tags of elements with not content immediately after the opening tag if shorter
than the character limit.
Otherwise, insert closing tags on new indented lines.
Insert leaf elements on one indented line if shorter than the character limit . Insert closing tags of elements with not content immediately after the opening tag if shorter than the character limit . Otherwise insert closing tags on new indented lines .
insertClosingTag(closingTag, html, indentLevel) {
        const tagName = HtmlFormatter.getTagName(closingTag);
        const formattedClosingTag = `</${tagName}>`;
        const trimmedHtml = html.trim();
        const elementStartIndex = trimmedHtml.lastIndexOf(`<${tagName}`);
        const unclosedElement = trimmedHtml.slice(elementStartIndex);
        const oneLineElement = unclosedElement
            .split("\n")
            .map(HtmlFormatter.normalizeWhitespace)
            .join("") + formattedClosingTag;
        const isLeafElement = oneLineElement.match(HTML_REG_EXP.CAPTURE_TAGS).length === 2;
        if (isLeafElement) {
            if (this.shorterThanCharacterLimit(oneLineElement, indentLevel)) {
                return trimmedHtml.slice(0, elementStartIndex) + oneLineElement;
            }
        }
        const openingTag = unclosedElement.match(HTML_REG_EXP.OPENING_TAG)[0];
        const elementIsEmpty = trimmedHtml.length === elementStartIndex + openingTag.length;
        if (elementIsEmpty) {
            const lastLineTrimmed = HtmlFormatter.getLastLineTrimmed(html) + formattedClosingTag;
            if (this.shorterThanCharacterLimit(lastLineTrimmed, indentLevel)) {
                return trimmedHtml + formattedClosingTag;
            }
        }
        return this.insertIndentedLine(formattedClosingTag, trimmedHtml, indentLevel);
    }
insertClosingTag ( closingTag , html , indentLevel ) { const tagName = HtmlFormatter . getTagName ( closingTag ) ; const formattedClosingTag = ` ${ tagName } ` ; const trimmedHtml = html . trim ( ) ; const elementStartIndex = trimmedHtml . lastIndexOf ( ` ${ tagName } ` ) ; const unclosedElement = trimmedHtml . slice ( elementStartIndex ) ; const oneLineElement = unclosedElement . split ( "\n" ) . map ( HtmlFormatter . normalizeWhitespace ) . join ( "" ) + formattedClosingTag ; const isLeafElement = oneLineElement . match ( HTML_REG_EXP . CAPTURE_TAGS ) . length === 2 ; if ( isLeafElement ) { if ( this . shorterThanCharacterLimit ( oneLineElement , indentLevel ) ) { return trimmedHtml . slice ( 0 , elementStartIndex ) + oneLineElement ; } } const openingTag = unclosedElement . match ( HTML_REG_EXP . OPENING_TAG ) [ 0 ] ; const elementIsEmpty = trimmedHtml . length === elementStartIndex + openingTag . length ; if ( elementIsEmpty ) { const lastLineTrimmed = HtmlFormatter . getLastLineTrimmed ( html ) + formattedClosingTag ; if ( this . shorterThanCharacterLimit ( lastLineTrimmed , indentLevel ) ) { return trimmedHtml + formattedClosingTag ; } } return this . insertIndentedLine ( formattedClosingTag , trimmedHtml , indentLevel ) ; }
Insert leaf elements on one indented line if shorter than the character limit.
Insert leaf elements on one indented line if shorter than the character limit .