コード例 #1
0
 /**
  * Parse the given content.
  *
  * Any newly created nodes should be pushed to the stack. Any remaining content should be passed to the next parser
  * in the chain.
  *
  * @param Text $content
  * @param Container $target
  * @return void
  */
 public function parseBlock(Text $content, Container $target)
 {
     $content->handle('{
             ^
             [ ]{0,3}\\[(.+)\\]:  # id = $1
               [ \\t]*
               \\n?               # maybe *one* newline
               [ \\t]*
             (?|                 # url = $2
               ([^\\s<>]+)            # either without spaces
               |
               <([^<>\\n]*)>         # or enclosed in angle brackets
             )
             (?:
               [ \\t]*
               \\n?               # maybe one newline
               [ \\t]*
                 (?<=\\s)         # lookbehind for whitespace
                 ["\'(]
                 (.+?)           # title = $3
                 ["\')]
                 [ \\t]*
             )?  # title is optional
             $
         }xm', function (Text $whole, Text $id, Text $url, Text $title = null) use($target) {
         if (!$this->queue->isEmpty()) {
             $lastPart = $this->queue->dequeue();
             // If the previous line was not empty, we should not parse this as a link reference
             if (!$lastPart->match('/(^|\\n *)\\n$/')) {
                 $lastPart->append($whole);
                 $this->queue->enqueue($lastPart);
                 return;
             }
             $this->parsePart($lastPart, $target);
         }
         $id = $id->lower()->getString();
         // Throw away duplicate reference definitions
         if (!$this->links->exists($id)) {
             $url->decodeEntities();
             // Replace special characters in the URL
             $url->encodeUrl();
             $this->links->set($id, $url);
             if ($title) {
                 $title->decodeEntities();
                 $this->titles->set($id, $title);
             }
         }
     }, function (Text $part) {
         if (!$this->queue->isEmpty()) {
             $lastPart = $this->queue->dequeue();
             $part->prepend($lastPart);
         }
         $this->queue->enqueue($part);
     });
     if (!$this->queue->isEmpty()) {
         $lastPart = $this->queue->dequeue();
         $this->parsePart($lastPart, $target);
     }
 }
コード例 #2
0
ファイル: CollectionTest.php プロジェクト: fluxbb/commonmark
 public function testEach()
 {
     $collection = new Collection(array(1, 2, 3, 4));
     $test = array();
     $collection->each(function ($value) use(&$test) {
         $test[] = $value * 2;
     });
     $this->assertEquals(array(2, 4, 6, 8), $test);
 }
コード例 #3
0
ファイル: Paragraph.php プロジェクト: fluxbb/commonmark
 public function getText()
 {
     return new Text($this->lines->join("\n"));
 }
コード例 #4
0
ファイル: InlineParser.php プロジェクト: fluxbb/commonmark
 public function getReferenceTitle($reference)
 {
     return $this->titles->exists($reference) ? $this->titles->get($reference) : new Text();
 }