Inheritance: extends AbstractBlock, implements League\CommonMark\Block\Element\InlineContainer
Ejemplo n.º 1
0
 protected function addId(Heading $node)
 {
     // If the node has an ID, no need to generate it
     $attributes = $node->getData('attributes', []);
     if (array_key_exists('id', $attributes) && !empty($attributes['id'])) {
         // TODO :: check for uniqueness
         return $attributes['id'];
     }
     // Well, seems we have to generate an ID
     $walker = $node->walker();
     $inside = [];
     while ($event = $walker->next()) {
         $insideNode = $event->getNode();
         if ($insideNode instanceof Heading) {
             continue;
         }
         $inside[] = $insideNode;
     }
     $text = '';
     foreach ($inside as $other) {
         if ($other instanceof Text) {
             $text .= ' ' . $other->getContent();
         }
     }
     $text = 'page_' . DauxHelper::slug(trim($text));
     // TODO :: check for uniqueness
     $node->data['attributes']['id'] = $text;
 }
 public function testRender()
 {
     $class = $this->getRendererClass();
     $renderer = new $class();
     $header = new Heading(2, 'HEADING!!');
     $header->appendChild(new Text('HEADING!!'));
     $color = new Color();
     $color->setForceStyle(true);
     $cliRenderer = new CliRenderer([], [Text::class => new TextRenderer()], $color);
     $this->assertEquals("\n## HEADING!!\n", $renderer->render($header, $cliRenderer));
 }
Ejemplo n.º 3
0
 public function __construct(Heading $content)
 {
     $this->content = $content;
     $this->level = $content->getLevel();
 }