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