-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathConfigurator.php
55 lines (47 loc) · 1.2 KB
/
Configurator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* @package s9e\TextFormatter
* @copyright Copyright (c) The s9e authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\TextFormatter\Plugins\Escaper;
use s9e\TextFormatter\Plugins\ConfiguratorBase;
class Configurator extends ConfiguratorBase
{
/**
* {@inheritdoc}
*/
protected $quickMatch = '\\';
/**
* @var string Regexp that matches one backslash followed by the escape character
*/
protected $regexp;
/**
* @var string Name of the tag used by this plugin
*/
protected $tagName = 'ESC';
/**
* Set whether any Unicode character should be escapable, or limit to some ASCII symbols
*
* @param bool $bool Whether any Unicode character should be escapable
* @return void
*/
public function escapeAll($bool = true)
{
$this->regexp = ($bool) ? '/\\\\./su' : '/\\\\[-!#()*+.:<>@[\\\\\\]^_`{|}~]/';
}
/**
* {@inheritdoc}
*/
protected function setUp()
{
// Set the default regexp
$this->escapeAll(false);
// Create the tag
$tag = $this->configurator->tags->add($this->tagName);
$tag->rules->disableAutoLineBreaks();
$tag->rules->ignoreTags();
$tag->rules->preventLineBreaks();
$tag->template = '<xsl:apply-templates/>';
}
}