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