replace workaround for HTML markup with a sane way of doing it, via loadHTML()
authorRobert Kaiser <kairo@kairo.at>
Thu, 15 Dec 2016 21:59:12 +0000 (22:59 +0100)
committerRobert Kaiser <kairo@kairo.at>
Thu, 15 Dec 2016 21:59:12 +0000 (22:59 +0100)
classes/document.php-class

index 3e39f0a..dbad743 100755 (executable)
@@ -299,8 +299,13 @@ class ExtendedDocument extends DOMDocument {
 
   public function appendHTMLMarkup($htmldata, $parentNode = null) {
     if (is_null($parentNode)) { $parentNode =& $this; }
-    // XXX: just a workaround for now!
-    $parentNode->appendChild($this->createCDATASection($htmldata));
+    // Use loadHTML() to parse and turn the markup into proper HTML.
+    $tmpdoc = new ExtendedDocument;
+    // The XML line is needed to tell the parser that we need UTF-8 parsing.
+    $tmpdoc->loadHTML('<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html><html><body>'.$htmldata.'</body></html>');
+    foreach ($tmpdoc->getElementsByTagName('body')->item(0)->childNodes as $child) {
+      $parentNode->appendChild($this->importNode($child, true));
+    }
   }
 
   public function appendXMLMarkup($xmldata, $parentNode = null) {