public function leaveComment(Comment $comment)
 {
     if (!$comment->isRendered()) {
         return false;
     }
     if ($comment->hasCondition()) {
         $close = '<![endif]-->';
     } else {
         $close = '-->';
     }
     if ($comment->hasContent()) {
         $this->write(' ' . $close, false, $comment->hasParent());
     } else {
         if ($comment->hasChilds()) {
             $this->undent()->write($close, true, true);
         }
     }
 }
예제 #2
0
파일: Printer.php 프로젝트: gunderjt/MtHaml
 public function leaveComment(Comment $node)
 {
     $this->undent()->write(')', $node->hasChilds());
 }
 protected function parseComment($buf)
 {
     if ($buf->match('!(-#|/)\\s*!A', $match)) {
         $pos = $match['pos'][0];
         $rendered = '/' === $match[1];
         $condition = null;
         if ($rendered) {
             // IE conditional comments
             // example: [if IE lte 8]
             //
             // matches nested [...]
             if ($buf->match('!(\\[ ( [^\\[\\]]+ | (?1) )+  \\])$!Ax', $match)) {
                 $condition = $match[0];
             }
         }
         $node = new Comment($pos, $rendered, $condition);
         if ($rendered) {
             if (null !== ($nested = $this->parseNestableStatement($buf))) {
                 $node->setContent($nested);
             }
         } else {
             if ('' !== ($line = trim($buf->getLine()))) {
                 $content = new Text($buf->getPosition(), $line);
                 $node->setContent($content);
             }
             while (null !== ($next = $buf->peekLine())) {
                 $indent = '';
                 if ('' !== trim($next)) {
                     $indent = $this->getIndentString(1, $next);
                     if ('' === $indent) {
                         break;
                     }
                     if (strpos($next, $indent) !== 0) {
                         break;
                     }
                 }
                 $buf->nextLine();
                 if ('' !== trim($next)) {
                     $buf->eatChars(strlen($indent));
                     $str = new Text($buf->getPosition(), $buf->getLine());
                     $node->addChild(new Statement($str->getPosition(), $str));
                 }
             }
         }
         return $node;
     }
 }