Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <colinodell@gmail.com> and uAfrica.com (http://uafrica.com)
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
 
14
namespace League\CommonMark\Extension\Strikethrough;
15
 
16
use League\CommonMark\Delimiter\DelimiterInterface;
17
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
18
use League\CommonMark\Node\Inline\AbstractStringContainer;
19
 
20
final class StrikethroughDelimiterProcessor implements DelimiterProcessorInterface
21
{
22
    public function getOpeningCharacter(): string
23
    {
24
        return '~';
25
    }
26
 
27
    public function getClosingCharacter(): string
28
    {
29
        return '~';
30
    }
31
 
32
    public function getMinLength(): int
33
    {
991 lars 34
        return 1;
148 lars 35
    }
36
 
37
    public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int
38
    {
991 lars 39
        if ($opener->getLength() > 2 && $closer->getLength() > 2) {
40
            return 0;
41
        }
148 lars 42
 
991 lars 43
        if ($opener->getLength() !== $closer->getLength()) {
44
            return 0;
45
        }
46
 
47
        return \min($opener->getLength(), $closer->getLength());
148 lars 48
    }
49
 
50
    public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void
51
    {
52
        $strikethrough = new Strikethrough(\str_repeat('~', $delimiterUse));
53
 
54
        $tmp = $opener->next();
55
        while ($tmp !== null && $tmp !== $closer) {
56
            $next = $tmp->next();
57
            $strikethrough->appendChild($tmp);
58
            $tmp = $next;
59
        }
60
 
61
        $opener->insertAfter($strikethrough);
62
    }
63
}