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[90m##[0m [36m[1mHEADING!![0m[0m\n", $renderer->render($header, $cliRenderer)); }
public function __construct(Heading $content) { $this->content = $content; $this->level = $content->getLevel(); }