1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File containing the {@see Mailcode_Traits_Formatting_HTMLHighlighting} trait. |
4
|
|
|
* |
5
|
|
|
* @package Mailcode |
6
|
|
|
* @subpackage Parser |
7
|
|
|
* @see Mailcode_Traits_Formatting_HTMLHighlighting |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace Mailcode; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Trait for HTML Highlighting formatters. This is a |
16
|
|
|
* good solution to share this functionality between |
17
|
|
|
* different types (like the MarkVariables and HTMLHighlighting |
18
|
|
|
* formatters, since they extend different classes). |
19
|
|
|
* |
20
|
|
|
* @package Mailcode |
21
|
|
|
* @subpackage Parser |
22
|
|
|
* @author Sebastian Mordziol <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
trait Mailcode_Traits_Formatting_HTMLHighlighting |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string[] |
28
|
|
|
*/ |
29
|
|
|
private $excludeTags = array( |
30
|
|
|
'style', // NOTE: style tags are excluded natively on the parser level. |
31
|
|
|
'script' |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Adds an HTML tag name to the list of tags within which |
36
|
|
|
* commands may not be highlighted. |
37
|
|
|
* |
38
|
|
|
* @param string $tagName Case insensitive. |
39
|
|
|
* @return Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting |
40
|
|
|
*/ |
41
|
|
|
public function excludeTag(string $tagName) : Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting |
42
|
|
|
{ |
43
|
|
|
$tagName = strtolower($tagName); |
44
|
|
|
|
45
|
|
|
if(!in_array($tagName, $this->excludeTags)) |
46
|
|
|
{ |
47
|
|
|
$this->excludeTags[] = $tagName; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return $this; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Adds several exluded tag names at once. |
55
|
|
|
* |
56
|
|
|
* @param string[] $tagNames |
57
|
|
|
* @return Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting |
58
|
|
|
*/ |
59
|
|
|
public function excludeTags(array $tagNames) : Mailcode_Parser_Safeguard_Formatter_Type_HTMLHighlighting |
60
|
|
|
{ |
61
|
|
|
foreach($tagNames as $tagName) |
62
|
|
|
{ |
63
|
|
|
$this->excludeTag((string)$tagName); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this; |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Whether the specified tag name is in the exlusion list. |
71
|
|
|
* |
72
|
|
|
* @param string $tagName |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
|
|
public function isTagExcluded(string $tagName) : bool |
76
|
|
|
{ |
77
|
|
|
$tagName = strtolower($tagName); |
78
|
|
|
|
79
|
|
|
return in_array($tagName, $this->excludeTags); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getReplaceString(Mailcode_Parser_Safeguard_Formatter_Location $location): string |
83
|
|
|
{ |
84
|
|
|
return $location->getPlaceholder()->getHighlightedText(); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|