1<?php 2 3declare(strict_types=1); 4 5/* 6 * This file is part of the clockoon/dokuwiki-commonmark-plugin package. 7 * 8 * (c) Sungbin Jeon <clockoon@gmail.com> 9 * 10 * Original code based on the followings: 11 * - CommonMark JS reference parser (https://bitly.com/commonmark-js) (c) John MacFarlane 12 * - league/commonmark (https://github.com/thephpleague/commonmark) (c) Colin O'Dell <colinodell@gmail.com> 13 * - Commonmark Table extension (c) Martin Hasoň <martin.hason@gmail.com>, Webuni s.r.o. <info@webuni.cz>, Colin O'Dell <colinodell@gmail.com> 14 * 15 * For the full copyright and license information, please view the LICENSE 16 * file that was distributed with this source code. 17 */ 18 19namespace DokuWiki\Plugin\Commonmark\Extension\Renderer\Block; 20 21use League\CommonMark\Block\Element\AbstractBlock; 22use League\CommonMark\Block\Renderer\BlockRendererInterface; 23use League\CommonMark\ElementRendererInterface; 24use League\CommonMark\Extension\Table\TableCell; 25 26final class TableCellRenderer implements BlockRendererInterface 27{ 28 public function render(AbstractBlock $block, ElementRendererInterface $DWRenderer, bool $inTightList = false) 29 { 30 if (!$block instanceof TableCell) { 31 throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block)); 32 } 33 34 # block type indicator on DW 35 $separator = ''; 36 switch ($block->type) { 37 case 'td': 38 $separator = '|'; 39 break; 40 case 'th': 41 $separator = '^'; 42 break; 43 } 44 45 # align indicator on DW 46 $lmargin = ' '; 47 $rmargin = ' '; 48 switch($block->align) { 49 case "right": 50 $lmargin = ' '; 51 break; 52 case "center": 53 $lmargin = ' '; 54 $rmargin = ' '; 55 break; 56 } 57 58 $result = $separator . $lmargin . $DWRenderer->renderInlines($block->children()) . $rmargin; 59 return $result; 60 61 } 62} 63