コード例 #1
0
ファイル: HTML5Parser.php プロジェクト: hametuha/hamepub
 /**
  * @param $dom
  *
  * @return null
  */
 public function retrieveBody($dom)
 {
     if (preg_match('/<body>(.*)<\\/body>/s', $this->html5->saveHTML($dom), $match)) {
         return $match[1];
     } else {
         return null;
     }
 }
コード例 #2
0
 public function process($content)
 {
     if (strlen($content) == 0) {
         return '';
     }
     $fragment = $this->html5->loadHTMLFragment($content);
     $fragment = $this->processModifiers($fragment);
     return $this->html5->saveHTML($fragment);
 }
コード例 #3
0
ファイル: MarkupFixer.php プロジェクト: caseyamcl/toc
 /**
  * Fix markup
  *
  * @param string $markup
  * @param int    $topLevel
  * @param int    $depth
  * @return string Markup with added IDs
  * @throws RuntimeException
  */
 public function fix($markup, $topLevel = 1, $depth = 6)
 {
     if (!$this->isFullHtmlDocument($markup)) {
         $partialID = 'toc_generator_' . mt_rand(1000, 4000);
         $markup = sprintf("<body id='%s'>%s</body>", $partialID, $markup);
     }
     $domDocument = $this->htmlParser->loadHTML($markup);
     $domDocument->preserveWhiteSpace = true;
     // do not clobber whitespace
     $sluggifier = new UniqueSluggifier();
     /** @var \DOMElement $node */
     foreach ($this->traverseHeaderTags($domDocument, $topLevel, $depth) as $node) {
         if ($node->getAttribute('id')) {
             continue;
         }
         $node->setAttribute('id', $sluggifier->slugify($node->getAttribute('title') ?: $node->textContent));
     }
     return $this->htmlParser->saveHTML(isset($partialID) ? $domDocument->getElementById($partialID)->childNodes : $domDocument);
 }
コード例 #4
0
 /**
  * {@inheritdoc}
  */
 public function toHtml(\DOMDocument $document, $encoding = 'UTF-8')
 {
     return $this->html5Parser->saveHTML($document);
 }
コード例 #5
0
 /**
  * Write the document to HTML5.
  *
  * This works the same as the other write* functions, but it encodes the output
  * as HTML5 with UTF-8.
  * @see html5()
  * @see innerHTML5()
  * @throws Exception
  *  In the event that a file cannot be written, an Exception will be thrown.
  */
 public function writeHTML5($path = NULL)
 {
     $html5 = new HTML5();
     if ($path == NULL) {
         // Print the document to stdout.
         print $html5->saveHTML($this->document);
         return;
     }
     $html5->save($this->document, $path);
 }
コード例 #6
0
ファイル: Formatter.php プロジェクト: hametuha/wpametu
 /**
  * Return body as string
  *
  * @param \DOMDocument $dom
  *
  * @return mixed
  */
 public static function to_string(\DOMDocument $dom)
 {
     $html5 = new HTML5();
     preg_match('/<body>(.*)<\\/body>/s', $html5->saveHTML($dom), $match);
     return $match[1];
 }
コード例 #7
0
ファイル: Serializer.php プロジェクト: fluentdom/html5
 public function asString()
 {
     $html5 = new HTML5Support($this->_options);
     return (string) $html5->saveHTML($this->_document);
 }