1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Libraries\Markdown\CustomContainerInline;
7
8use League\CommonMark\Delimiter\DelimiterInterface;
9use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface;
10use League\CommonMark\Node\Inline\AbstractStringContainer;
11
12class Parser implements DelimiterProcessorInterface
13{
14 public function getOpeningCharacter(): string
15 {
16 return ':';
17 }
18
19 public function getClosingCharacter(): string
20 {
21 return ':';
22 }
23
24 public function getMinLength(): int
25 {
26 return 2;
27 }
28
29 public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int
30 {
31 if ($opener->getLength() >= 2 && $closer->getLength() >= 2) {
32 return 2;
33 }
34
35 return 0;
36 }
37
38 public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void
39 {
40 $inline = new Element();
41
42 $tmp = $opener->next();
43 while ($tmp !== null && $tmp !== $closer) {
44 $next = $tmp->next();
45 $inline->appendChild($tmp);
46 $tmp = $next;
47 }
48
49 $opener->insertAfter($inline);
50 }
51}