/**
  * Parse input into nodes
  *
  * @param  net.daringfireball.markdown.Input $lines
  * @return net.daringfireball.markdown.Node
  */
 public function parse($lines)
 {
     $result = new CodeBlock($this->language);
     while ($lines->hasMoreLines()) {
         $line = $lines->nextLine();
         if (0 === strncmp($line, '```', 3)) {
             break;
         } else {
             $result->add(new Text($line));
         }
     }
     return $result;
 }
 /**
  * Parse input into nodes
  *
  * @param  net.daringfireball.markdown.Input $lines
  * @return net.daringfireball.markdown.Node
  */
 public function parse($lines)
 {
     $result = new BlockQuote();
     while ($lines->hasMoreLines()) {
         $line = $lines->nextLine();
         if ('>' !== $line->chr()) {
             break;
         }
         $line->forward(2);
         $this->tokenize($line, $result);
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * Parse input into nodes
  *
  * @param  net.daringfireball.markdown.Input $lines
  * @return net.daringfireball.markdown.Node
  */
 public function parse($lines)
 {
     $table = new Table();
     $table->add($this->parseRow($this->headers, 'th'));
     while ($lines->hasMoreLines()) {
         $line = $lines->nextLine();
         if (null === ($row = $this->parseRow($line, 'td'))) {
             $lines->resetLine($line);
             break;
         }
         $table->add($row);
     }
     return $table;
 }
Esempio n. 4
0
 /**
  * Parse input into nodes
  *
  * @param  net.daringfireball.markdown.Input $lines
  * @return net.daringfireball.markdown.Node
  */
 public function parse($lines)
 {
     $empty = false;
     $target = null;
     $result = new Listing($this->type);
     while ($lines->hasMoreLines()) {
         $line = $lines->nextLine();
         // An empty line makes the list use paragraphs, except if it's the last line.
         if (0 === $line->length()) {
             $empty = true;
             continue;
         }
         // Indented elements form additional paragpraphs inside list items. If
         // the line doesn't start with a list bullet, this means the list is at
         // its end.
         if (preg_match('/^(\\s+)?([+*-]+|[0-9]+\\.) /', $line, $m) && !preg_match('/^(\\* ?){3,}$/', $line)) {
             $empty && ($result->paragraphs = true);
             $empty = false;
             // Check whether we need to indent / dedent the list level, or whether
             // the list item belongs to this list
             $level = strlen($m[1]) / 2;
             if ($level > $this->level) {
                 $lines->resetLine($line);
                 $target = $target ?: $result->add(new ListItem($result))->add(new Paragraph());
                 $target->add($this->enter(new self($this->type, $level))->parse($lines));
             } else {
                 if ($level < $this->level) {
                     $lines->resetLine($line);
                     break;
                 } else {
                     $target = $result->add(new ListItem($result))->add(new Paragraph());
                     $line->forward(strlen($m[0]));
                     $this->tokenize($line, $target);
                 }
             }
         } else {
             if ('  ' === substr($line, 0, 2)) {
                 // Add paragraph to existing list item
                 $paragraph = $result->last()->add(new Paragraph());
                 $line->forward(2);
                 $this->tokenize($line, $paragraph);
             } else {
                 $lines->resetLine($line);
                 break;
             }
         }
     }
     return $result;
 }
Esempio n. 5
0
 /**
  * Parse input into nodes
  *
  * @param  net.daringfireball.markdown.Input $lines
  * @return net.daringfireball.markdown.Node
  */
 public function parse($lines)
 {
     $result = new CodeBlock();
     while ($lines->hasMoreLines()) {
         $line = $lines->nextLine();
         if ("\t" === $line->chr()) {
             $result->add(new Text(substr($line, 1)));
         } else {
             if (0 === strncmp($line, '    ', 4)) {
                 $result->add(new Text(substr($line, 4)));
             } else {
                 $lines->resetLine($line);
                 break;
             }
         }
     }
     return $result;
 }
 /**
  * Parse input into nodes
  *
  * @param  net.daringfireball.markdown.Input $lines
  * @return net.daringfireball.markdown.Node
  */
 public function parse($lines)
 {
     $result = new ParseTree();
     $result->add(new Paragraph());
     $target = null;
     while ($lines->hasMoreLines()) {
         $line = $lines->nextLine();
         // An empty line by itself ends the last element and starts a new
         // paragraph (if there are any more lines)
         if (0 === $line->length()) {
             $target = null;
         }
         // Check handlers
         $handled = false;
         foreach ($this->handlers as $pattern => $handler) {
             if (preg_match($pattern, $line, $values)) {
                 if ($handled = $handler($lines, [$line] + $values, $result, $this)) {
                     $target = null;
                     break;
                 }
             }
         }
         if ($handled) {
             continue;
         }
         // We got here, so there is more text, and no target -> we need to open
         // a new paragraph.
         if (null === $target) {
             $target = $result->append(new Paragraph());
         }
         // If previous line was text, add a newline
         // * Hello\nWorld -> <p>Hello\nWorld</p>
         // * Hello\n\nWorld -> <p>Hello</p><p>World</p>
         $last = $target->last();
         if ($last instanceof Text) {
             $last->value .= "\n";
         }
         $this->tokenize($line, $target);
     }
     // DEBUG \util\cmd\Console::writeLine($result);
     return $result;
 }