1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Groundskeeper\Tokens\Elements; |
4
|
|
|
|
5
|
|
|
use Groundskeeper\Configuration; |
6
|
|
|
use Groundskeeper\Tokens\ElementTypes\OpenElement; |
7
|
|
|
use Groundskeeper\Tokens\ElementTypes\ScriptSupporting; |
8
|
|
|
use Groundskeeper\Tokens\Token; |
9
|
|
|
use Psr\Log\LoggerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* "tr" element |
13
|
|
|
* |
14
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-tr-element |
15
|
|
|
*/ |
16
|
|
|
class Tr extends OpenElement |
17
|
|
|
{ |
18
|
3 |
|
protected function doClean(LoggerInterface $logger) |
19
|
|
|
{ |
20
|
3 |
|
if ($this->configuration->get('clean-strategy') != Configuration::CLEAN_STRATEGY_LENIENT) { |
21
|
|
|
// "table" must be parent. |
22
|
3 |
|
$parent = $this->getParent(); |
23
|
3 |
|
if ($parent !== null && |
24
|
3 |
|
$parent->getName() != 'thead' && |
25
|
3 |
|
$parent->getName() != 'tbody' && |
26
|
3 |
|
$parent->getName() != 'tfoot' && |
27
|
3 |
|
$parent->getName() != 'table') { |
28
|
1 |
|
$logger->debug('Element "tr" must be a child of the "thead", "tbody", "tfoot", or "table" elements.'); |
29
|
|
|
|
30
|
1 |
|
return false; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// Children can be "td", "th", and script supporting elements. |
34
|
3 |
|
foreach ($this->children as $child) { |
35
|
3 |
|
if ($child->getType() == Token::COMMENT) { |
36
|
1 |
|
continue; |
37
|
|
|
} |
38
|
|
|
|
39
|
2 |
|
if ($child->getType() !== Token::ELEMENT) { |
40
|
1 |
|
$logger->debug('Removing ' . $child . '. Only elements allowed as children of "tr" element.'); |
41
|
1 |
|
$this->removeChild($child); |
42
|
|
|
|
43
|
1 |
|
continue; |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
if ($child->getName() == 'td' || |
47
|
2 |
|
$child->getName() == 'th' || |
48
|
2 |
|
$child instanceof ScriptSupporting) { |
49
|
2 |
|
continue; |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
$logger->debug('Removing ' . $child . '. Only "td", "th", and script supporting elements allowed as children of "tr" element.'); |
53
|
1 |
|
$this->removeChild($child); |
54
|
3 |
|
} |
55
|
3 |
|
} |
56
|
|
|
|
57
|
3 |
|
return true; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|