Exemplo n.º 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}       # Optional leading spaces
             (\\#{1,6})       # $1 = string of #\'s
             (([ ].+?)??)    # $2 = Header text
             ([ ]\\#*[ ]*)?   # optional closing #\'s (not counted)
             $
         }mx', function (Text $whole, Text $marks, Text $content) use($target) {
         $level = $marks->getLength();
         $heading = new Heading($content->trim(), $level);
         $target->addChild($heading);
         $this->inlineParser->queue($heading->getText(), $heading);
     }, function (Text $part) use($target) {
         $this->next->parseBlock($part, $target);
     });
 }
Exemplo n.º 2
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}
             ([^>\\-*=\\ \\n].*)
             [ ]*
             \\n
             [ ]{0,3}
             (=+|-+)
             [ ]*
             \\n*
             $
         }mx', function (Text $whole, Text $content, Text $mark) use($target) {
         $level = substr($mark, 0, 1) == '=' ? 1 : 2;
         $heading = new Heading($content->trim(), $level);
         $target->addChild($heading);
         $this->inlineParser->queue($heading->getText(), $heading);
     }, function (Text $part) use($target) {
         $this->next->parseBlock($part, $target);
     });
 }
Exemplo n.º 3
0
 protected function makeLines(Text $text)
 {
     return $text->trim()->split('/\\n/')->apply(function (Text $line) {
         return $line->copy()->ltrim();
     });
 }