The function that is displayed can be replaced by the one below, but care needs to be taken with CSS and Javascript inline.
function compressHtml($buffer)
{
// Iniciando variáveis para busca de tags
$foundTxt = null;
$foundPre = null;
$foundCode = null;
$foundScript = null;
// Procurando tags textarea, pre, code e script
preg_match_all('#\<textarea.*\>.*\<\/textarea\>#Uis', $buffer, $foundTxt);
preg_match_all('#\<pre.*\>.*\<\/pre\>#Uis', $buffer, $foundPre);
preg_match_all('#\<code.*\>.*\<\/code\>#Uis', $buffer, $foundCode);
preg_match_all('#\<script.*\>.*\<\/script\>#Uis', $buffer, $foundScript);
// Substitui o canteúdo da tags por uma palavra chave, assim
// o conteúdo pode ser posto novamente intacto no lugar.
// Exemplo: <textarea>$index</textarea> / <pre>$index</pre>
$buffer = str_replace($foundTxt[0], array_map(function($el){ return '<textarea>'.$el.'</textarea>'; }, array_keys($foundTxt[0])), $buffer);
$buffer = str_replace($foundPre[0], array_map(function($el){ return '<pre>'.$el.'</pre>'; }, array_keys($foundPre[0])), $buffer);
$buffer = str_replace($foundCode[0], array_map(function($el){ return '<code>'.$el.'</code>'; }, array_keys($foundCode[0])), $buffer);
$buffer = str_replace($foundScript[0], array_map(function($el){ return '<script>'.$el.'</script>'; }, array_keys($foundScript[0])), $buffer);
// Minifica o html
$search = array(
'/\>[^\S ]+/s', // Limpando espaços em branco antes das tags
'/[^\S ]+\</s', // Limpando espaços em branco depois das tags
'/(\s)+/s', // Siminuindo espaços repetidos para um apenas
'/<!--(.|\s)*?-->/', // Eetirando comentários do HTML
'#(?://)?<!\[CDATA\[(.*?)(?://)?\]\]>#s' // Deixando CDATA em linhas separadas
);
$replace = array(
'>',
'<',
'\\1',
'',
"//<![CDATA[\n".'\1'."\n//]]>"
);
$buffer = preg_replace($search, $replace, $buffer);
// Replacing back with content
$buffer = str_replace(array_map(function($el){ return '<textarea>'.$el.'</textarea>'; }, array_keys($foundTxt[0])), $foundTxt[0], $buffer);
$buffer = str_replace(array_map(function($el){ return '<pre>'.$el.'</pre>'; }, array_keys($foundPre[0])), $foundPre[0], $buffer);
$buffer = str_replace(array_map(function($el){ return '<code>'.$el.'</code>'; }, array_keys($foundCode[0])), $foundCode[0], $buffer);
$buffer = str_replace(array_map(function($el){ return '<script>'.$el.'</script>'; }, array_keys($foundScript[0])), $foundScript[0], $buffer);
return $buffer;
}
This is not the best solution, but it is the basic process.