Ejemplo n.º 1
0
 public function testProcessorInstruction()
 {
     $html = '<?foo bar ?>';
     $input = new \Masterminds\HTML5\Parser\StringInputStream($html);
     $dom = $this->html5->parseFragment($input);
     $this->assertInstanceOf('\\DOMDocumentFragment', $dom);
     $stream = fopen('php://temp', 'w');
     $r = new OutputRules($stream, $this->html5->getOptions());
     $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
     $out = $t->walk();
     $this->assertEquals($html, stream_get_contents($stream, -1, 0));
 }
Ejemplo n.º 2
0
 /**
  * @inheritDoc
  */
 public function save($dom, $file, $options = array())
 {
     $close = true;
     if (is_resource($file)) {
         $stream = $file;
         $close = false;
     } else {
         $stream = fopen($file, 'w');
     }
     $options = array_merge($this->getOptions(), $options);
     $rules = new OutputRules($stream, $options);
     $trav = new Traverser($dom, $stream, $rules, $options);
     $trav->walk();
     if ($close) {
         fclose($stream);
     }
 }
Ejemplo n.º 3
0
 function testSerializeWithNamespaces()
 {
     $this->html5 = $this->getInstance(array('xmlNamespaces' => true));
     $source = '
         <!DOCTYPE html>
         <html><body id="body" xmlns:x="http://www.prefixed.com">
                 <a id="bar1" xmlns="http://www.prefixed.com/bar1">
                     <b id="bar4" xmlns="http://www.prefixed.com/bar4"><x:prefixed id="prefixed">xy</x:prefixed></b>
                 </a>
                 <svg id="svg">svg</svg>
                 <c id="bar2" xmlns="http://www.prefixed.com/bar2"></c>
                 <div id="div"></div>
                 <d id="bar3"></d>
                 <xn:d id="bar5" xmlns:xn="http://www.prefixed.com/xn" xmlns="http://www.prefixed.com/bar5_x"><x id="bar5_x">y</x></xn:d>
             </body>
         </html>';
     $dom = $this->html5->loadHTML($source, array('xmlNamespaces' => true));
     $this->assertFalse($this->html5->hasErrors(), print_r($this->html5->getErrors(), 1));
     $stream = fopen('php://temp', 'w');
     $r = new OutputRules($stream, $this->html5->getOptions());
     $t = new Traverser($dom, $stream, $r, $this->html5->getOptions());
     $t->walk();
     $rendered = stream_get_contents($stream, -1, 0);
     $clear = function ($s) {
         return trim(preg_replace('/[\\s]+/', " ", $s));
     };
     $this->assertEquals($clear($source), $clear($rendered));
 }