2021-06-26 23:23:15 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Entities\Tools\Markdown;
|
2021-01-11 07:01:11 +08:00
|
|
|
|
|
|
|
use League\CommonMark\Extension\Strikethrough\Strikethrough;
|
2023-02-07 04:00:44 +08:00
|
|
|
use League\CommonMark\Node\Node;
|
|
|
|
use League\CommonMark\Renderer\ChildNodeRendererInterface;
|
|
|
|
use League\CommonMark\Renderer\NodeRendererInterface;
|
|
|
|
use League\CommonMark\Util\HtmlElement;
|
2021-01-11 07:01:11 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-07 04:00:44 +08:00
|
|
|
class CustomStrikethroughRenderer implements NodeRendererInterface
|
2021-01-11 07:01:11 +08:00
|
|
|
{
|
2023-02-07 04:00:44 +08:00
|
|
|
public function render(Node $node, ChildNodeRendererInterface $childRenderer)
|
2021-01-11 07:01:11 +08:00
|
|
|
{
|
2023-02-07 04:00:44 +08:00
|
|
|
Strikethrough::assertInstanceOf($node);
|
2021-01-11 07:01:11 +08:00
|
|
|
|
2023-02-07 04:00:44 +08:00
|
|
|
return new HtmlElement('s', $node->data->get('attributes'), $childRenderer->renderNodes($node->children()));
|
2021-01-11 07:01:11 +08:00
|
|
|
}
|
2021-03-08 06:24:05 +08:00
|
|
|
}
|