protected function html($string)
{
$doc = new \DOMDocument();
// Here for PHP 5.3 compatibility where the constants aren't available
if (!defined('LIBXML_HTML_NOIMPLIED')) {
$doc->loadHTML($string);
} else {
$doc->loadHTML($string, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
}
$doc->preserveWhiteSpace = false;
$html = $doc->saveHTML();
// Trim trailing and leading whitespace
$html = implode("\n", array_map('trim', explode("\n", $html)));
return $html;
}