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\NonParticipating; |
9
|
|
|
use Groundskeeper\Tokens\Token; |
10
|
|
|
use Psr\Log\LoggerInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* "tr" element |
14
|
|
|
* |
15
|
|
|
* https://html.spec.whatwg.org/multipage/semantics.html#the-tr-element |
16
|
|
|
*/ |
17
|
|
|
class Tr extends OpenElement |
18
|
|
|
{ |
19
|
3 |
|
protected function removeInvalidChildren(LoggerInterface $logger) |
20
|
|
|
{ |
21
|
|
|
// Children can be "td", "th", and script supporting elements. |
22
|
3 |
|
foreach ($this->children as $child) { |
23
|
3 |
|
if ($child instanceof NonParticipating || |
24
|
2 |
|
$child instanceof Td || |
25
|
2 |
|
$child instanceof Th || |
26
|
3 |
|
$child instanceof ScriptSupporting) { |
27
|
3 |
|
continue; |
28
|
|
|
} |
29
|
|
|
|
30
|
1 |
|
$logger->debug('Removing ' . $child . '. Only "td", "th", and script supporting elements allowed as children of "tr" element.'); |
31
|
1 |
|
$this->removeChild($child); |
32
|
3 |
|
} |
33
|
3 |
|
} |
34
|
|
|
|
35
|
3 |
|
protected function removeInvalidSelf(LoggerInterface $logger) |
36
|
|
|
{ |
37
|
|
|
// "table" must be parent. |
38
|
3 |
|
$parent = $this->getParent(); |
39
|
3 |
|
if ($parent !== null && |
40
|
3 |
|
!$parent instanceof Thead && |
41
|
3 |
|
!$parent instanceof Tbody && |
42
|
3 |
|
!$parent instanceof Tfoot && |
43
|
3 |
|
!$parent instanceof Table) { |
44
|
1 |
|
$logger->debug('Removing ' . $this . '. Must be a child of the "thead", "tbody", "tfoot", or "table" elements.'); |
45
|
|
|
|
46
|
1 |
|
return true; |
47
|
|
|
} |
48
|
|
|
|
49
|
3 |
|
return false; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|