leilukin-tumbleblog/includes/lib/xenocrat/markdown/inline/StrikeoutTrait.php

54 lines
988 B
PHP
Raw Normal View History

2024-06-20 14:10:42 +00:00
<?php
/**
* @copyright Copyright 2014 Carsten Brandt, 2024 Daniel Pimley
* @license https://github.com/xenocrat/chyrp-markdown/blob/master/LICENSE
* @link https://github.com/xenocrat/chyrp-markdown#readme
*/
namespace xenocrat\markdown\inline;
/**
* Adds strikeout inline elements.
*/
trait StrikeoutTrait
{
protected function parseStrikeMarkers(): array
{
return array('~');
}
/**
* Parses the strikethrough feature.
*
* @marker ~
*/
protected function parseStrike($markdown): array
{
if (
preg_match('/^(~{1,2})(?!~)(.*?[^~\\\\])\1(?!~)/s',
$markdown,
$matches
)
) {
return [
[
'strike',
$this->parseInline($matches[2])
],
strlen($matches[0])
];
}
return [['text', $markdown[0]], 1];
}
protected function renderStrike($block): string
{
return '<del>'
. $this->renderAbsy($block[1])
. '</del>';
}
abstract protected function parseInline($text);
abstract protected function renderAbsy($blocks);
}