18ec9a8f2SSungbin Jeon<?php 28ec9a8f2SSungbin Jeon 38ec9a8f2SSungbin Jeon/* 404312fe3SSungbin Jeon * This file is part of the clockoon/dokuwiki-commonmark-plugin package. 58ec9a8f2SSungbin Jeon * 604312fe3SSungbin Jeon * (c) Sungbin Jeon <clockoon@gmail.com> 78ec9a8f2SSungbin Jeon * 804312fe3SSungbin Jeon * Original code based on the followings: 904312fe3SSungbin Jeon * - CommonMark JS reference parser (https://bitly.com/commonmark-js) (c) John MacFarlane 1004312fe3SSungbin Jeon * - league/commonmark (https://github.com/thephpleague/commonmark) (c) Colin O'Dell <colinodell@gmail.com> 118ec9a8f2SSungbin Jeon * 128ec9a8f2SSungbin Jeon * For the full copyright and license information, please view the LICENSE 138ec9a8f2SSungbin Jeon * file that was distributed with this source code. 148ec9a8f2SSungbin Jeon */ 158ec9a8f2SSungbin Jeon 168a43364eSSungbin Jeonnamespace DokuWiki\Plugin\Commonmark\Extension\Renderer\Block; 178ec9a8f2SSungbin Jeon 1894a075eeSSungbin Jeonuse League\CommonMark\Extension\CommonMark\Node\Block\Heading; 1994a075eeSSungbin Jeonuse League\CommonMark\Node\Node; 2094a075eeSSungbin Jeonuse League\CommonMark\Renderer\ChildNodeRendererInterface; 2194a075eeSSungbin Jeonuse League\CommonMark\Renderer\NodeRendererInterface; 2294a075eeSSungbin Jeonuse League\CommonMark\Xml\XmlNodeRendererInterface; 238ec9a8f2SSungbin Jeon 2494a075eeSSungbin Jeonfinal class HeadingRenderer implements NodeRendererInterface 258ec9a8f2SSungbin Jeon{ 268ec9a8f2SSungbin Jeon /** 278ec9a8f2SSungbin Jeon * @param Heading $block 28*b0a36678SSungbin Jeon * @param ChildNodeRendererInterface $DWRenderer 298ec9a8f2SSungbin Jeon * @param bool $inTightList 308ec9a8f2SSungbin Jeon * 3104312fe3SSungbin Jeon * @return string 328ec9a8f2SSungbin Jeon */ 33*b0a36678SSungbin Jeon public function render(Node $node, ChildNodeRendererInterface $DWRenderer): string 348ec9a8f2SSungbin Jeon { 3594a075eeSSungbin Jeon Heading::assertInstanceOf($node); 368ec9a8f2SSungbin Jeon 37*b0a36678SSungbin Jeon $heading = str_repeat('=', max(7 - $node->getLevel(), 2)) . ' '; 388ec9a8f2SSungbin Jeon 3994a075eeSSungbin Jeon $result = $heading . $DWRenderer->renderNodes($node->children()) . strrev($heading); 408ec9a8f2SSungbin Jeon 418ec9a8f2SSungbin Jeon return $result; 428ec9a8f2SSungbin Jeon } 438ec9a8f2SSungbin Jeon} 44