protected function kneadHtml($html, $type, $href)
{
libxml_use_internal_errors(true);
// Load HTMl snippet into DOMDocument using UTF-8 hack
$utf8_hack = '<?xml version="1.0" encoding="UTF-8"?>';
$doc = new \DOMDocument();
$doc->loadHTML($utf8_hack . $html);
// Download images, change to relative paths
$doc = $this->scrapeAndKneadImages($doc, $href);
// Deal with <a href="">, <a href=''>, and other mutations
$doc = $this->kneadHref($doc, $type, $href);
// If you are storing multi-byte characters in XML, then saving the XML using saveXML() will create problems.
// Ie. It will spit out the characters converted in encoded format. Instead do the following:
$html = $doc->saveXML($doc->documentElement);
// Clean up html
$html = $this->regexSearchReplace($html);
$errors = libxml_get_errors();
// TODO: Handle errors gracefully
libxml_clear_errors();
return $html;
}