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

25 lines
860 B
PHP
Raw Normal View History

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