Exemplo n.º 1
0
 protected function parseOrderedLists(Text $content, Container $target)
 {
     $content->handle('{
             ^
             ([ ]{0,3})              # $1 - initial indent
             ([0-9]+)([.)])          # $2 - list marker; $3 - punctuation
             (?|
                 ([ ]{1,4})          # $4 - list indent
                 [^ ].*
               |
                 ()                  # ... which can also be empty
             )
             (
                 \\n\\n?
                 \\1[ ]{2}\\4
                 .*
             )*
             (
                 (?:
                     \\n
                     \\1[0-9]+\\3\\4
                     [^ ].*
                   |                     # empty items
                     \\n
                     \\1\\2
                   |                     # Lazy continuation lines
                     \\n
                     [ ]*
                     (?:
                         [^0-9>\\-+*=\\ \\n]
                       |
                         [0-9]+[^.)]
                     )
                     [^\\n]*
                 )
                 (
                     \\n\\n?
                     \\1[ ]{2}\\4
                     .*
                 )*
             )*
             $
         }mx', function (Text $content, Text $i, Text $start, Text $punctuation, Text $indent) use($target) {
         $isTerse = !$content->match('/^[ ]*$/m');
         $lines = explode("\n", $content->getString());
         $start = $start->getString();
         $indentLength = $i->getLength() + $indent->getLength() + 2;
         $list = new ListBlock('ol', $isTerse, $start);
         // Go through all the lines to assemble the list items
         $curItem = substr(array_shift($lines), $indentLength) . "\n";
         foreach ($lines as $line) {
             if (preg_match('/^[0-9]+' . preg_quote($punctuation) . '/', $line)) {
                 $this->addItemToList($curItem, $list);
                 $curItem = substr($line, $indentLength) . "\n";
             } else {
                 $curItem .= $this->unindentLine($line, $indentLength) . "\n";
             }
         }
         $this->addItemToList($curItem, $list);
         $target->addChild($list);
     }, function (Text $part) use($target) {
         $this->next->parseBlock($part, $target);
     });
 }