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 <[email protected]> |
9
|
|
|
* |
10
|
|
|
* Original code based on the CommonMark JS reference parser (http://bitly.com/commonmark-js) |
11
|
|
|
* - (c) John MacFarlane |
12
|
|
|
* |
13
|
|
|
* For the full copyright and license information, please view the LICENSE |
14
|
|
|
* file that was distributed with this source code. |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace League\CommonMark\Extension\SmartPunct; |
18
|
|
|
|
19
|
|
|
use League\CommonMark\Delimiter\DelimiterInterface; |
20
|
|
|
use League\CommonMark\Delimiter\Processor\DelimiterProcessorInterface; |
21
|
|
|
use League\CommonMark\Node\Inline\AbstractStringContainer; |
22
|
|
|
|
23
|
|
|
final class QuoteProcessor implements DelimiterProcessorInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
* |
28
|
|
|
* @psalm-readonly |
29
|
|
|
*/ |
30
|
|
|
private $normalizedCharacter; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
* |
35
|
|
|
* @psalm-readonly |
36
|
|
|
*/ |
37
|
|
|
private $openerCharacter; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string |
41
|
|
|
* |
42
|
|
|
* @psalm-readonly |
43
|
|
|
*/ |
44
|
|
|
private $closerCharacter; |
45
|
|
|
|
46
|
57 |
|
private function __construct(string $char, string $opener, string $closer) |
47
|
|
|
{ |
48
|
57 |
|
$this->normalizedCharacter = $char; |
49
|
57 |
|
$this->openerCharacter = $opener; |
50
|
57 |
|
$this->closerCharacter = $closer; |
51
|
57 |
|
} |
52
|
|
|
|
53
|
57 |
|
public function getOpeningCharacter(): string |
54
|
|
|
{ |
55
|
57 |
|
return $this->normalizedCharacter; |
56
|
|
|
} |
57
|
|
|
|
58
|
57 |
|
public function getClosingCharacter(): string |
59
|
|
|
{ |
60
|
57 |
|
return $this->normalizedCharacter; |
61
|
|
|
} |
62
|
|
|
|
63
|
6 |
|
public function getMinLength(): int |
64
|
|
|
{ |
65
|
6 |
|
return 1; |
66
|
|
|
} |
67
|
|
|
|
68
|
36 |
|
public function getDelimiterUse(DelimiterInterface $opener, DelimiterInterface $closer): int |
69
|
|
|
{ |
70
|
36 |
|
return 1; |
71
|
|
|
} |
72
|
|
|
|
73
|
36 |
|
public function process(AbstractStringContainer $opener, AbstractStringContainer $closer, int $delimiterUse): void |
74
|
|
|
{ |
75
|
36 |
|
$opener->insertAfter(new Quote($this->openerCharacter)); |
76
|
36 |
|
$closer->insertBefore(new Quote($this->closerCharacter)); |
77
|
36 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Create a double-quote processor |
81
|
|
|
* |
82
|
|
|
* @return QuoteProcessor |
83
|
|
|
*/ |
84
|
54 |
|
public static function createDoubleQuoteProcessor(string $opener = Quote::DOUBLE_QUOTE_OPENER, string $closer = Quote::DOUBLE_QUOTE_CLOSER): self |
85
|
|
|
{ |
86
|
54 |
|
return new self(Quote::DOUBLE_QUOTE, $opener, $closer); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Create a single-quote processor |
91
|
|
|
* |
92
|
|
|
* @return QuoteProcessor |
93
|
|
|
*/ |
94
|
54 |
|
public static function createSingleQuoteProcessor(string $opener = Quote::SINGLE_QUOTE_OPENER, string $closer = Quote::SINGLE_QUOTE_CLOSER): self |
95
|
|
|
{ |
96
|
54 |
|
return new self(Quote::SINGLE_QUOTE, $opener, $closer); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|