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