コード例 #1
0
ファイル: CommentedCode.php プロジェクト: stefk/md
 private function processComments(array $comments)
 {
     $processed = [];
     $previousLineComment = null;
     $previousCommentLineNumber = null;
     foreach ($comments as $comment) {
         if ($comment instanceof Doc || in_array($comment, $this->seenComments)) {
             continue;
         }
         $this->seenComments[] = $comment;
         $text = $comment->getReformattedText();
         if (0 === strpos($text, '/*')) {
             $text = substr(substr($text, 0, -2), 2);
             // remove comment delimiters
             $processed[] = new Comment($text, $comment->getLine(), $comment->getFilePos());
             continue;
         }
         $text = substr($text, 2);
         if (!$previousLineComment) {
             $previousLineComment = new Comment($text, $comment->getLine(), $comment->getFilePos());
             $previousCommentLineNumber = $comment->getLine();
             continue;
         }
         if ($previousCommentLineNumber !== $comment->getLine() - 1) {
             // line comments aren't consecutive
             $processed[] = $previousLineComment;
             $previousLineComment = new Comment($text, $comment->getLine(), $comment->getFilePos());
             $previousCommentLineNumber = $comment->getLine();
             continue;
         }
         // merge consecutive line comments
         $previousLineComment = new Comment($previousLineComment->getText() . $text, $previousLineComment->getLine(), $previousLineComment->getFilePos());
         $previousCommentLineNumber = $comment->getLine();
     }
     if ($previousLineComment) {
         $processed[] = $previousLineComment;
     }
     return $processed;
 }
コード例 #2
0
ファイル: CommentNode.php プロジェクト: stefk/md
 public function __construct(Comment $comment)
 {
     parent::__construct(['startLine' => $comment->getLine(), 'endLine' => $comment->getLine()]);
 }