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