1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package s9e\TextFormatter |
5
|
|
|
* @copyright Copyright (c) 2010-2016 The s9e Authors |
6
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License |
7
|
|
|
*/ |
8
|
|
|
namespace s9e\TextFormatter\Plugins\FancyPants; |
9
|
|
|
|
10
|
|
|
use s9e\TextFormatter\Plugins\ConfiguratorBase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This plugin combines some of the functionalities found in SmartyPants and Textile |
14
|
|
|
* |
15
|
|
|
* @link http://daringfireball.net/projects/smartypants/ |
16
|
|
|
* @link http://textile.thresholdstate.com/ |
17
|
|
|
*/ |
18
|
|
|
class Configurator extends ConfiguratorBase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string Name of attribute used to for the replacement |
22
|
|
|
*/ |
23
|
|
|
protected $attrName = 'char'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string[] List of passes that have been explicitly disabled |
27
|
|
|
*/ |
28
|
|
|
protected $disabledPasses = []; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string Name of the tag used to mark the text to replace |
32
|
|
|
*/ |
33
|
|
|
protected $tagName = 'FP'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Plugin's setup |
37
|
|
|
* |
38
|
|
|
* Will initialize create the plugin's tag if it does not exist |
39
|
|
|
*/ |
40
|
10 |
|
protected function setUp() |
41
|
|
|
{ |
42
|
10 |
|
if (isset($this->configurator->tags[$this->tagName])) |
43
|
10 |
|
{ |
44
|
1 |
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Create tag |
48
|
9 |
|
$tag = $this->configurator->tags->add($this->tagName); |
49
|
|
|
|
50
|
|
|
// Create attribute |
51
|
9 |
|
$tag->attributes->add($this->attrName); |
52
|
|
|
|
53
|
|
|
// Create a template that replaces its content with the replacement char |
54
|
9 |
|
$tag->template |
55
|
9 |
|
= '<xsl:value-of select="@' . htmlspecialchars($this->attrName) . '"/>'; |
56
|
9 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Disable a given pass |
60
|
|
|
* |
61
|
|
|
* @param string $passName |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
2 |
|
public function disablePass($passName) |
65
|
|
|
{ |
66
|
2 |
|
$this->disabledPasses[] = $passName; |
67
|
2 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Enable a given pass |
71
|
|
|
* |
72
|
|
|
* @param string $passName |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
1 |
|
public function enablePass($passName) |
76
|
|
|
{ |
77
|
1 |
|
foreach (array_keys($this->disabledPasses, $passName, true) as $k) |
78
|
|
|
{ |
79
|
1 |
|
unset($this->disabledPasses[$k]); |
80
|
1 |
|
} |
81
|
1 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
5 |
|
public function asConfig() |
87
|
|
|
{ |
88
|
|
|
$config = [ |
89
|
5 |
|
'attrName' => $this->attrName, |
90
|
5 |
|
'tagName' => $this->tagName |
91
|
5 |
|
]; |
92
|
5 |
|
foreach ($this->disabledPasses as $passName) |
93
|
|
|
{ |
94
|
1 |
|
$config['disable' . $passName] = true; |
95
|
5 |
|
} |
96
|
|
|
|
97
|
5 |
|
return $config; |
98
|
|
|
} |
99
|
|
|
} |