Exemplo n.º 1
0
 protected function pComments(array $comments)
 {
     return $this->pNoIndent(trim(parent::pComments($comments)));
 }
Exemplo n.º 2
0
 protected function pComments(array $comments)
 {
     $lines = Multiline::create(parent::pComments($comments));
     // Trim trailing non-Markdown whitespace
     $lines->apply(function ($line) {
         if (preg_match('/(?<! |\\*)  $/', $line)) {
             return $line;
         }
         return rtrim($line);
     });
     $lastStartPos = -1;
     $consecutive = 0;
     $isFenced = false;
     foreach ($lines->toArray() as $pos => $line) {
         // Ignore fenced Markdown
         if (preg_match('/^\\s*\\*\\s?```\\s*$/', $line)) {
             $isFenced = !$isFenced;
         }
         if ($isFenced) {
             $consecutive = $this->removeConsecutiveEmptyDocs($lines, $consecutive, $lastStartPos, $pos);
             continue;
         }
         // Remember last start /* or /**
         if (preg_match("/^(\\s*\\/\\*+\\s*)\$/", $line)) {
             $lastStartPos = $pos;
             continue;
         }
         // Keep matching whitespacey lines
         if (preg_match("/^\\s*\\*\\s*\$/", $line)) {
             $consecutive++;
             continue;
         }
         if (preg_match('/^\\s*\\*\\/\\s*$/', $line)) {
             $lastStartPos = $pos - $consecutive - 1;
         }
         // Remove lines if possible
         $consecutive = $this->removeConsecutiveEmptyDocs($lines, $consecutive, $lastStartPos, $pos);
     }
     return (string) $lines;
 }