- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInCell.php
More file actions
108 lines (97 loc) · 2.97 KB
/
InCell.php
File metadata and controls
108 lines (97 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace RemexHtml\TreeBuilder;
use RemexHtml\Tokenizer\Attributes;
/**
* The "in cell" insertion mode
*/
class InCell extends InsertionMode {
public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
$this->dispatcher->inBody->characters( $text, $start, $length,
$sourceStart, $sourceLength );
}
public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
switch ( $name ) {
case 'caption':
case 'col':
case 'colgroup':
case 'tbody':
case 'td':
case 'tfoot':
case 'th':
case 'thead':
case 'tr':
if ( !$this->builder->stack->isInTableScope( 'td' )
&& !$this->builder->stack->isInTableScope( 'th' )
) {
$this->builder->error( "<$name> tag should close the cell but none is in scope",
$sourceStart );
return;
}
$this->closeTheCell( $sourceStart )
->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
default:
$this->dispatcher->inBody->startTag(
$name, $attrs, $selfClose, $sourceStart, $sourceLength );
}
}
public function endTag( $name, $sourceStart, $sourceLength ) {
$builder = $this->builder;
$stack = $builder->stack;
$dispatcher = $this->dispatcher;
switch ( $name ) {
case 'td':
case 'th':
if ( !$stack->isInTableScope( $name ) ) {
$builder->error( "</$name> encountered but there is no $name in scope, ignoring",
$sourceStart );
return;
}
$builder->generateImpliedEndTags( null, $sourceStart );
if ( $stack->current->htmlName !== $name ) {
$builder->error( "</$name> encountered when there are tags open " .
"which can't be closed automatically", $sourceStart );
}
$builder->popAllUpToName( $name, $sourceStart, $sourceLength );
$builder->afe->clearToMarker();
$dispatcher->switchMode( Dispatcher::IN_ROW );
break;
case 'body':
case 'caption':
case 'col':
case 'colgroup':
case 'html':
$builder->error( "unexpected </$name> in cell, ignoring", $sourceStart );
return;
case 'table':
case 'tbody':
case 'tfoot':
case 'thead':
case 'tr':
if ( !$stack->isInTableScope( $name ) ) {
$builder->error( "</$name> encountered but there is no $name in scope, ignoring",
$sourceStart );
return;
}
$this->closeTheCell( $sourceStart )
->endTag( $name, $sourceStart, $sourceLength );
break;
default:
$dispatcher->inBody->endTag( $name, $sourceStart, $sourceLength );
}
}
public function endDocument( $pos ) {
$this->dispatcher->inBody->endDocument( $pos );
}
private function closeTheCell( $sourceStart ) {
$tdth = [ 'td' => true, 'th' => true ];
$builder = $this->builder;
$stack = $builder->stack;
$builder->generateImpliedEndTags( false, $sourceStart );
if ( !isset( $tdth[$stack->current->htmlName] ) ) {
$builder->error( "closing the cell but there are tags open " .
"which can't be closed automatically", $sourceStart );
}
$builder->afe->clearToMarker();
return $this->dispatcher->switchMode( Dispatcher::IN_ROW );
}
}