| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\RemexHtml\TreeBuilder; |
| 4 |
|
| 5 |
use Wikimedia\RemexHtml\Tokenizer\Attributes; |
| 6 |
|
| 7 |
/** |
| 8 |
* The "in select in table" insertion mode |
| 9 |
*/ |
| 10 |
class InSelectInTable extends InsertionMode { |
| 11 |
/** @inheritDoc */ |
| 12 |
public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 13 |
$this->dispatcher->inSelect->characters( |
| 14 |
$text, $start, $length, $sourceStart, $sourceLength ); |
| 15 |
} |
| 16 |
|
| 17 |
/** @inheritDoc */ |
| 18 |
public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 19 |
$builder = $this->builder; |
| 20 |
$dispatcher = $this->dispatcher; |
| 21 |
|
| 22 |
switch ( $name ) { |
| 23 |
case 'caption': |
| 24 |
case 'table': |
| 25 |
case 'tbody': |
| 26 |
case 'tfoot': |
| 27 |
case 'thead': |
| 28 |
case 'tr': |
| 29 |
case 'td': |
| 30 |
case 'th': |
| 31 |
$builder->error( "unexpected <$name> in select in table, closing select", |
| 32 |
$sourceStart ); |
| 33 |
$builder->popAllUpToName( 'select', $sourceStart, 0 ); |
| 34 |
$dispatcher->reset() |
| 35 |
->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 36 |
break; |
| 37 |
|
| 38 |
default: |
| 39 |
$dispatcher->inSelect->startTag( |
| 40 |
$name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/** @inheritDoc */ |
| 45 |
public function endTag( $name, $sourceStart, $sourceLength ) { |
| 46 |
$builder = $this->builder; |
| 47 |
$stack = $builder->stack; |
| 48 |
$dispatcher = $this->dispatcher; |
| 49 |
|
| 50 |
switch ( $name ) { |
| 51 |
case 'caption': |
| 52 |
case 'table': |
| 53 |
case 'tbody': |
| 54 |
case 'tfoot': |
| 55 |
case 'thead': |
| 56 |
case 'tr': |
| 57 |
case 'td': |
| 58 |
case 'th': |
| 59 |
if ( !$stack->isInTableScope( $name ) ) { |
| 60 |
$builder->error( "unexpected </$name> in select in table, ignoring", |
| 61 |
$sourceStart ); |
| 62 |
return; |
| 63 |
} |
| 64 |
$builder->error( "unexpected </$name> in select in table, closing select", |
| 65 |
$sourceStart ); |
| 66 |
$builder->popAllUpToName( 'select', $sourceStart, 0 ); |
| 67 |
$dispatcher->reset() |
| 68 |
->endTag( $name, $sourceStart, $sourceLength ); |
| 69 |
break; |
| 70 |
|
| 71 |
default: |
| 72 |
$dispatcher->inSelect->endTag( $name, $sourceStart, $sourceLength ); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
/** @inheritDoc */ |
| 77 |
public function endDocument( $pos ) { |
| 78 |
$this->dispatcher->inSelect->endDocument( $pos ); |
| 79 |
} |
| 80 |
} |