Exemplo n.º 1
0
 /**
  * Add HTML parts.
  *
  * Note: $stylesheet parameter is removed to avoid PHPMD error for unused parameter
  *
  * @param \PhpOffice\PhpWord\Element\AbstractContainer $element Where the parts need to be added
  * @param string $html The code to parse
  * @param bool $fullHTML If it's a full HTML, no need to add 'body' tag
  * @return void
  */
 public static function addHtml($element, $html, $fullHTML = false)
 {
     /*
      * @todo parse $stylesheet for default styles.  Should result in an array based on id, class and element,
      * which could be applied when such an element occurs in the parseNode function.
      */
     // Preprocess: remove all line ends, decode HTML entity,
     // fix ampersand and angle brackets and add body tag for HTML fragments
     $html = str_replace(array("\n", "\r"), '', $html);
     $html = str_replace(array('<', '>', '&'), array('_lt_', '_gt_', '_amp_'), $html);
     $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
     $html = str_replace('&', '&', $html);
     $html = str_replace(array('_lt_', '_gt_', '_amp_'), array('<', '>', '&'), $html);
     if ($fullHTML === false) {
         $html = '<body>' . $html . '</body>';
     }
     // Load DOM
     $dom = new \DOMDocument();
     $dom->preserveWhiteSpace = true;
     $dom->loadHTML($html);
     self::$cssParser = new \Xprt64\Css\Parser($dom);
     self::$cssParser->loadRulesFromDom();
     self::$cssRules = self::$cssParser->getRules();
     $node = $dom->getElementsByTagName('body');
     $body = $node->item(0);
     $element->setStyle(self::parseInlineStyle($body, array(), null));
     self::parseNode($body, $element);
 }