* * Licensed under MIT, see LICENSE. */ declare(strict_types=1); namespace Grav\Plugin\PageToc; use Knp\Menu\ItemInterface; use Knp\Menu\Renderer\ListRenderer; use function str_repeat; /** * Class OrderedListRenderer * * @package TOC */ class OrderedListRenderer extends ListRenderer { /** * @param ItemInterface $item * @param array $attributes * @param array $options * @return string */ protected function renderList(ItemInterface $item, array $attributes, array $options): string { if (!$item->hasChildren() || 0 === $options['depth'] || !$item->getDisplayChildren()) { return ''; } $html = $this->format( 'renderHtmlAttributes($attributes) . '>', 'ol', $item->getLevel(), $options ); $html .= $this->renderChildren($item, $options); $html .= $this->format('', 'ol', $item->getLevel(), $options); return $html; } /** * @param string $html * @param string $type * @param int $level * @param array $options * @return string */ protected function format(string $html, string $type, int $level, array $options): string { return $type === 'ol' ? str_repeat(' ', $level * 4) . $html . "\n" : parent::format($html, $type, $level, $options); } }