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 removeInvalidChildren(LoggerInterface $logger) |
19
|
|
|
{ |
20
|
|
|
// Children can be "td", "th", and script supporting elements. |
21
|
3 |
|
foreach ($this->children as $child) { |
22
|
3 |
|
if ($child->getType() == Token::COMMENT) { |
23
|
1 |
|
continue; |
24
|
|
|
} |
25
|
|
|
|
26
|
2 |
|
if ($child->getType() !== Token::ELEMENT) { |
27
|
1 |
|
$logger->debug('Removing ' . $child . '. Only elements allowed as children of "tr" element.'); |
28
|
1 |
|
$this->removeChild($child); |
29
|
|
|
|
30
|
1 |
|
continue; |
31
|
|
|
} |
32
|
|
|
|
33
|
2 |
|
if ($child->getName() == 'td' || |
34
|
2 |
|
$child->getName() == 'th' || |
35
|
2 |
|
$child instanceof ScriptSupporting) { |
36
|
2 |
|
continue; |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
$logger->debug('Removing ' . $child . '. Only "td", "th", and script supporting elements allowed as children of "tr" element.'); |
40
|
1 |
|
$this->removeChild($child); |
41
|
3 |
|
} |
42
|
3 |
|
} |
43
|
|
|
|
44
|
3 |
|
protected function removeInvalidSelf(LoggerInterface $logger) |
45
|
|
|
{ |
46
|
|
|
// "table" must be parent. |
47
|
3 |
|
$parent = $this->getParent(); |
48
|
3 |
|
if ($parent !== null && |
49
|
3 |
|
$parent->getName() != 'thead' && |
50
|
3 |
|
$parent->getName() != 'tbody' && |
51
|
3 |
|
$parent->getName() != 'tfoot' && |
52
|
3 |
|
$parent->getName() != 'table') { |
53
|
1 |
|
$logger->debug($this . ' must be a child of the "thead", "tbody", "tfoot", or "table" elements.'); |
54
|
|
|
|
55
|
1 |
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
return false; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|