Exemple #1
0
 /**
  * @param Nodes\Tag $tag
  */
 protected function visitTagContents(Tag $tag)
 {
     $inc = $tag->keepWhiteSpaces() ? -$this->indents : 1;
     $this->indents += $inc;
     if (isset($tag->code)) {
         $this->visitCode($tag->code);
     }
     $this->visit($tag->block);
     if ($tag->keepWhiteSpaces() && substr(end($this->buffer), -1) === "\n") {
         $this->trimLastLine();
     }
     $this->indents -= $inc;
 }
Exemple #2
0
 /**
  * @param Nodes\Tag $tag
  */
 protected function visitTagContents(Tag $tag)
 {
     $inc = $tag->keepWhiteSpaces() ? -$this->indents : 1;
     $this->indents += $inc;
     if (isset($tag->code)) {
         $this->visitCode($tag->code);
     }
     if (!$tag->keepWhiteSpaces()) {
         $count = count($tag->block->nodes);
         for ($i = 1; $i < $count; $i++) {
             if ($tag->block->nodes[$i] instanceof Text && $tag->block->nodes[$i - 1] instanceof Text && !preg_match('/^\\s/', $tag->block->nodes[$i]->value) && !preg_match('/\\s$/', $tag->block->nodes[$i - 1]->value)) {
                 $tag->block->nodes[$i - 1]->value .= ' ';
             }
         }
     }
     $this->visit($tag->block);
     if ($tag->keepWhiteSpaces() && substr(end($this->buffer), -1) === "\n") {
         $this->trimLastLine();
     }
     $this->indents -= $inc;
 }
Exemple #3
0
 /**
  * Tag Node test
  */
 public function testTag()
 {
     $foo = new Block();
     $foo->push(new Tag('em'));
     $p = new Tag('p');
     $this->assertFalse($p->isInline(), 'p tag should be inline');
     $foo->nodes[0]->block->push(new Tag('small'));
     $this->assertTrue($foo->nodes[0]->canInline(), 'em tag should can be inline as it only contains a small tag');
     $foo->nodes[0]->block->push(new Tag('blockquote'));
     $this->assertFalse($foo->nodes[0]->canInline(), 'em tag should not can be inline as it contains a blockquote tag');
     $foo->nodes[0]->block->push(new Block(new Tag('blockquote')));
     $this->assertFalse($foo->nodes[0]->canInline(), 'em tag should not can be inline as it contains a blockquote tag');
     $foo->push(new Tag('i'));
     $foo->nodes[1]->block->push(new Text('Hello'));
     $this->assertTrue($foo->nodes[1]->canInline(), 'i tag should can be inline as it only contains text');
     $foo->nodes[1]->block->push(new Tag('blockquote'));
     $this->assertFalse($foo->nodes[1]->canInline(), 'i tag should not can be inline if it contains blockquote');
     $foo->nodes[1]->block->nodes[1] = new Tag('small');
     $foo->nodes[1]->block->nodes[1]->block->push(new Tag('small'));
     $this->assertTrue($foo->nodes[1]->canInline(), 'i tag should can be inline with nested block as it only contains text and inline tags');
     $foo->nodes[1]->block->nodes[1]->block->nodes[0] = new Text('Hello');
     $foo->nodes[1]->block->nodes[1]->block->nodes[1] = new Text('Hello');
     $this->assertTrue($foo->nodes[1]->canInline(), 'i tag should can be inline with nested block as it only contains text');
     $foo->nodes[1] = new Tag('div');
     $foo->nodes[1]->block->push(new Tag('i'));
     $foo->nodes[1]->block->push(new Block());
     $this->assertTrue($foo->nodes[1]->canInline(), 'block should not can be inline with nested block if it contains just an i tag');
     $foo->nodes[1]->block->nodes[0] = new Tag('div');
     $this->assertFalse($foo->nodes[1]->canInline(), 'block should not can be inline with nested block if it contains div');
     $foo->nodes[1]->block->nodes[0] = new Tag('i');
     $foo->nodes[1]->block->nodes[1]->push(new Tag('i'));
     $this->assertTrue($foo->nodes[1]->canInline(), 'block should not can be inline with nested block if it contains just i tags');
     $foo->nodes[1]->block->nodes[1]->push(new Tag('p'));
     $this->assertFalse($foo->nodes[1]->canInline(), 'block should not can be inline with nested block if it contains inline and block tags');
     $foo = new Block();
     $foo->nodes[0] = new Tag('b');
     $foo->nodes[0]->block->push(new Text('Hello'));
     $foo->nodes[0]->block->push(new Text('Hello'));
     $this->assertFalse($foo->nodes[0]->canInline(), 'block should not can be inline if it is multi-line');
 }