]> BookStack Code Mirror - bookstack/blob - app/Entities/Tools/Markdown/CustomStrikethroughRenderer.php
Started work on details/summary blocks
[bookstack] / app / Entities / Tools / Markdown / CustomStrikethroughRenderer.php
1 <?php
2
3 namespace BookStack\Entities\Tools\Markdown;
4
5 use League\CommonMark\ElementRendererInterface;
6 use League\CommonMark\Extension\Strikethrough\Strikethrough;
7 use League\CommonMark\HtmlElement;
8 use League\CommonMark\Inline\Element\AbstractInline;
9 use League\CommonMark\Inline\Renderer\InlineRendererInterface;
10
11 /**
12  * This is a somewhat clone of the League\CommonMark\Extension\Strikethrough\StrikethroughRender
13  * class but modified slightly to use <s> HTML tags instead of <del> in order to
14  * match front-end markdown-it rendering.
15  */
16 class CustomStrikethroughRenderer implements InlineRendererInterface
17 {
18     public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
19     {
20         if (!($inline instanceof Strikethrough)) {
21             throw new \InvalidArgumentException('Incompatible inline type: ' . get_class($inline));
22         }
23
24         return new HtmlElement('s', $inline->getData('attributes', []), $htmlRenderer->renderInlines($inline->children()));
25     }
26 }