function normalizeWhitespace(content) {
	let compressed = '',
		preformatted = 0,
		p = 0, m;

	REGEXP_TAG.lastIndex = 0;
	while ( (m = REGEXP_TAG.exec(content)) ) {
		if ( m.index > p ) {
			let text = content.slice(p, m.index);
			if ( preformatted ) {
				compressed += text;
				// debug(`  '${text}' (preformatted)`);
			} else {
				text = text.replace(/\s+/g,' ');
				if ( text.trim() ) {
					compressed += text;
				}
				// debug(`  '${text}' (trimmed)`);
			}
		}

		compressed += m[0];
		// debug(`  '${m[0]}' (tag)`);
		p = m.index + m[0].length;

		if ( /^pre$/i.test(m[1]) ) {
			preformatted++;
		} else if ( /^\/pre$/i.test(m[1]) && preformatted ) {
			preformatted--;
		}

	}

	if ( content.length > p ) {
		let text = content.slice(p, content.length);
		if ( preformatted ) {
			compressed += text;
			// debug(`  '${text}' (preformatted)`);
		} else {
			text = text.replace(/\s+/g,' ');
			if ( text.trim() ) {
				compressed += text;
			}
			// debug(`  '${text}' (trimmed)`);
		}
	}

	return compressed;
}
/**
 * Removes unnecessary whitespace from an HTML document:
 *  - if the text between two adjacent HTML tags consists of whitespace only, the whole text is removed
 *  - otherwise, any sequence of whitespace in the text is reduced to a single blank
 *  - inside a <pre> tag, whitespace is preserved
 *
 * Whitespace inside an element tag is not touched (although it could be normalized as well)
 * @param {string} content raw HTML file
 * @returns {string} HTML file with normalized whitespace
 */
Removes unnecessary whitespace from an HTML document:
- if the text between two adjacent HTML tags consists of whitespace only, the whole text is removed
- otherwise, any sequence of whitespace in the text is reduced to a single blank
- inside a  tag, whitespace is preserved

Whitespace inside an element tag is not touched (although it could be normalized as well)
@param {string} content raw HTML file
@returns {string} HTML file with normalized whitespace
Removes unnecessary whitespace from an HTML document : - if the text between two adjacent HTML tags consists of whitespace only the whole text is removed - otherwise any sequence of whitespace in the text is reduced to a single blank - inside a tag whitespace is preserved Whitespace inside an element tag is not touched ( although it could be normalized as well ) @param { string } content raw HTML file @returns { string } HTML file with normalized whitespace
function normalizeWhitespace(content) {
	let compressed = '',
		preformatted = 0,
		p = 0, m;
	REGEXP_TAG.lastIndex = 0;
	while ( (m = REGEXP_TAG.exec(content)) ) {
		if ( m.index > p ) {
			let text = content.slice(p, m.index);
			if ( preformatted ) {
				compressed += text;
			} else {
				text = text.replace(/\s+/g,' ');
				if ( text.trim() ) {
					compressed += text;
				}
			}
		}
		compressed += m[0];
		p = m.index + m[0].length;
		if ( /^pre$/i.test(m[1]) ) {
			preformatted++;
		} else if ( /^\/pre$/i.test(m[1]) && preformatted ) {
			preformatted--;
		}
	}
	if ( content.length > p ) {
		let text = content.slice(p, content.length);
		if ( preformatted ) {
			compressed += text;
		} else {
			text = text.replace(/\s+/g,' ');
			if ( text.trim() ) {
				compressed += text;
			}
		}
	}
	return compressed;
}
function normalizeWhitespace ( content ) { let compressed = '' , preformatted = 0 , p = 0 , m ; REGEXP_TAG . lastIndex = 0 ; while ( ( m = REGEXP_TAG . exec ( content ) ) ) { if ( m . index > p ) { let text = content . slice ( p , m . index ) ; if ( preformatted ) { compressed += text ; } else { text = text . replace ( / \s+ / g , ' ' ) ; if ( text . trim ( ) ) { compressed += text ; } } } compressed += m [ 0 ] ; p = m . index + m [ 0 ] . length ; if ( / ^pre$ / i . test ( m [ 1 ] ) ) { preformatted ++ ; } else if ( / ^\/pre$ / i . test ( m [ 1 ] ) && preformatted ) { preformatted -- ; } } if ( content . length > p ) { let text = content . slice ( p , content . length ) ; if ( preformatted ) { compressed += text ; } else { text = text . replace ( / \s+ / g , ' ' ) ; if ( text . trim ( ) ) { compressed += text ; } } } return compressed ; }
Removes unnecessary whitespace from an HTML document:
  - if the text between two adjacent HTML tags consists of whitespace only, the whole text is removed
  - otherwise, any sequence of whitespace in the text is reduced to a single blank
  - inside a <pre> tag, whitespace is preserved
Removes unnecessary whitespace from an HTML document : - if the text between two adjacent HTML tags consists of whitespace only the whole text is removed - otherwise any sequence of whitespace in the text is reduced to a single blank - inside a <pre > tag whitespace is preserved
// debug(`  '${text}' (preformatted)`); // debug(`  '${text}' (trimmed)`); // debug(`  '${m[0]}' (tag)`); // debug(`  '${text}' (preformatted)`); // debug(`  '${text}' (trimmed)`);