BookStack/app/Entities/Tools/Markdown/CustomStrikethroughRenderer.php

25 lines
860 B
PHP
Raw Normal View History

2021-06-26 11:23:15 -04:00
<?php
namespace BookStack\Entities\Tools\Markdown;
use League\CommonMark\Extension\Strikethrough\Strikethrough;
2023-02-06 15:00:44 -05:00
use League\CommonMark\Node\Node;
use League\CommonMark\Renderer\ChildNodeRendererInterface;
use League\CommonMark\Renderer\NodeRendererInterface;
use League\CommonMark\Util\HtmlElement;
/**
* This is a somewhat clone of the League\CommonMark\Extension\Strikethrough\StrikethroughRender
* class but modified slightly to use <s> HTML tags instead of <del> in order to
* match front-end markdown-it rendering.
*/
2023-02-06 15:00:44 -05:00
class CustomStrikethroughRenderer implements NodeRendererInterface
{
2023-02-06 15:00:44 -05:00
public function render(Node $node, ChildNodeRendererInterface $childRenderer)
{
2023-02-06 15:00:44 -05:00
Strikethrough::assertInstanceOf($node);
2023-02-06 15:00:44 -05:00
return new HtmlElement('s', $node->data->get('attributes'), $childRenderer->renderNodes($node->children()));
}
2021-03-07 17:24:05 -05:00
}