Наследование: extends AbstractBlock, implements League\CommonMark\Block\Element\InlineContainer
 public function testRender()
 {
     $class = $this->getRendererClass();
     $renderer = new $class();
     $paragraph = new Paragraph();
     $paragraph->appendChild(new Text('Some Text 1'));
     $paragraph->appendChild(new Text('Some Text 2'));
     $color = new Color();
     $color->setForceStyle(true);
     $cliRenderer = new CliRenderer([], [Text::class => new TextRenderer()], $color);
     $this->assertEquals("Some Text 1Some Text 2\n", $renderer->render($paragraph, $cliRenderer));
 }
 public function testRender()
 {
     $class = $this->getRendererClass();
     $renderer = new $class();
     $list = new ListItem(new ListData());
     $paragraph = new Paragraph();
     $paragraph->appendChild(new Text('Item 1'));
     $list->appendChild($paragraph);
     $color = new Color();
     $color->setForceStyle(true);
     $cliRenderer = new CliRenderer([Paragraph::class => new ParagraphRenderer()], [Text::class => new TextRenderer()], $color);
     $this->assertEquals(" * Item 1\n", $renderer->render($list, $cliRenderer));
 }
 public function parse(ContextInterface $context, Cursor $cursor)
 {
     $container = $context->getContainer();
     if (!$container instanceof Paragraph) {
         return false;
     }
     $lines = $container->getStrings();
     if (count($lines) < 1) {
         return false;
     }
     $match = RegexHelper::matchAll(self::REGEXP_DEFINITION, $cursor->getLine(), $cursor->getFirstNonSpacePosition());
     if (null === $match) {
         return false;
     }
     $columns = $this->parseColumns($match);
     $head = $this->parseRow(trim(array_pop($lines)), $columns, TableCell::TYPE_HEAD);
     if (null === $head) {
         return false;
     }
     $table = new Table(function (Cursor $cursor) use(&$table, $columns) {
         $row = $this->parseRow($cursor->getLine(), $columns);
         if (null === $row) {
             if (null !== $table->getCaption()) {
                 return false;
             }
             if (null !== ($caption = $this->parseCaption($cursor->getLine()))) {
                 $table->setCaption($caption);
                 return true;
             }
             return false;
         }
         $table->getBody()->appendChild($row);
         return true;
     });
     $table->getHead()->appendChild($head);
     if (count($lines) >= 1) {
         $paragraph = new Paragraph();
         foreach ($lines as $line) {
             $paragraph->addLine($line);
         }
         $context->replaceContainerBlock($paragraph);
         $context->addBlock($table);
     } else {
         $context->replaceContainerBlock($table);
     }
     return true;
 }
Пример #4
0
 /**
  * @param Entry[] $entries
  * @return ListBlock
  */
 protected function render(array $entries)
 {
     $data = new ListData();
     $data->type = ListBlock::TYPE_UNORDERED;
     $list = new ListBlock($data);
     $list->data['attributes']['class'] = 'TableOfContents';
     foreach ($entries as $entry) {
         $item = new ListItem($data);
         $a = new Link('#' . $entry->getId());
         $content = $entry->getContent();
         if ($content != null) {
             foreach ($this->cloneChildren($content) as $node) {
                 $a->appendChild($node);
             }
         }
         $p = new Paragraph();
         $p->appendChild($a);
         $item->appendChild($p);
         if (!empty($entry->getChildren())) {
             $item->appendChild($this->render($entry->getChildren()));
         }
         $list->appendChild($item);
     }
     return $list;
 }