1656793f4SSungbin Jeon<?php 2656793f4SSungbin Jeon 3656793f4SSungbin Jeondeclare(strict_types=1); 4656793f4SSungbin Jeon 5656793f4SSungbin Jeon/* 6656793f4SSungbin Jeon * This file is part of the clockoon/dokuwiki-commonmark-plugin package. 7656793f4SSungbin Jeon * 8656793f4SSungbin Jeon * (c) Sungbin Jeon <clockoon@gmail.com> 9656793f4SSungbin Jeon * 10656793f4SSungbin Jeon * Original code based on the followings: 11656793f4SSungbin Jeon * - CommonMark JS reference parser (https://bitly.com/commonmark-js) (c) John MacFarlane 12656793f4SSungbin Jeon * - league/commonmark (https://github.com/thephpleague/commonmark) (c) Colin O'Dell <colinodell@gmail.com> 13656793f4SSungbin Jeon * - Commonmark Table extension (c) Martin Hasoň <martin.hason@gmail.com>, Webuni s.r.o. <info@webuni.cz>, Colin O'Dell <colinodell@gmail.com> 14656793f4SSungbin Jeon * 15656793f4SSungbin Jeon * For the full copyright and license information, please view the LICENSE 16656793f4SSungbin Jeon * file that was distributed with this source code. 17656793f4SSungbin Jeon */ 18656793f4SSungbin Jeon 19656793f4SSungbin Jeonnamespace DokuWiki\Plugin\Commonmark\Extension\Renderer\Block; 20656793f4SSungbin Jeon 21*b0a36678SSungbin Jeonuse League\CommonMark\Node\Node; 2294a075eeSSungbin Jeonuse League\CommonMark\Renderer\NodeRendererInterface; 23*b0a36678SSungbin Jeonuse League\CommonMark\Renderer\ChildNodeRendererInterface; 24656793f4SSungbin Jeonuse League\CommonMark\Extension\Table\TableCell; 25656793f4SSungbin Jeon 2694a075eeSSungbin Jeonfinal class TableCellRenderer implements NodeRendererInterface 27656793f4SSungbin Jeon{ 28*b0a36678SSungbin Jeon public function render(Node $node, ChildNodeRendererInterface $DWRenderer): string 29656793f4SSungbin Jeon { 30*b0a36678SSungbin Jeon TableCell::assertInstanceOf($node); 31656793f4SSungbin Jeon 32656793f4SSungbin Jeon # block type indicator on DW 33*b0a36678SSungbin Jeon $separator = $node->getType() === TableCell::TYPE_HEADER ? '^' : '|'; 34656793f4SSungbin Jeon 35656793f4SSungbin Jeon # align indicator on DW 36656793f4SSungbin Jeon $lmargin = ' '; 37656793f4SSungbin Jeon $rmargin = ' '; 38*b0a36678SSungbin Jeon switch($node->getAlign()) { 39656793f4SSungbin Jeon case "right": 40656793f4SSungbin Jeon $lmargin = ' '; 41656793f4SSungbin Jeon break; 42656793f4SSungbin Jeon case "center": 43656793f4SSungbin Jeon $lmargin = ' '; 44656793f4SSungbin Jeon $rmargin = ' '; 45656793f4SSungbin Jeon break; 46656793f4SSungbin Jeon } 47656793f4SSungbin Jeon 48*b0a36678SSungbin Jeon $result = $separator . $lmargin . $DWRenderer->renderNodes($node->children()) . $rmargin; 49656793f4SSungbin Jeon return $result; 50656793f4SSungbin Jeon 51656793f4SSungbin Jeon } 52656793f4SSungbin Jeon} 53