3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
5 use RemexHtml\Tokenizer\PlainAttributes;
8 * The "in table body" insertion mode
10 class InTableBody extends InsertionMode {
11 private static $tableBodyContext = [
19 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
20 $this->dispatcher->inTable->characters( $text, $start, $length,
21 $sourceStart, $sourceLength );
24 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
25 $builder = $this->builder;
26 $stack = $builder->stack;
27 $dispatcher = $this->dispatcher;
31 $builder->clearStackBack( self::$tableBodyContext, $sourceStart );
32 $builder->insertElement( $name, $attrs, false, $sourceStart, $sourceLength );
33 $dispatcher->switchMode( Dispatcher::IN_ROW );
38 $builder->error( "<$name> encountered in table body (not row) mode", $sourceStart );
39 $builder->clearStackBack( self::$tableBodyContext, $sourceStart );
40 $builder->insertElement( 'tr', new PlainAttributes, false, $sourceStart, 0 );
41 $dispatcher->switchMode( Dispatcher::IN_ROW )
42 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
51 if ( !$stack->isInTableScope( 'tbody' )
52 && !$stack->isInTableScope( 'thead' )
53 && !$stack->isInTableScope( 'tfoot' )
55 $builder->error( "<$name> encountered in table body mode " .
56 "when there is no tbody/thead/tfoot in scope", $sourceStart );
59 $builder->clearStackBack( self::$tableBodyContext, $sourceStart );
60 $builder->pop( $sourceStart, 0 );
61 $dispatcher->switchMode( Dispatcher::IN_TABLE )
62 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
66 $dispatcher->inTable->startTag( $name, $attrs, $selfClose,
67 $sourceStart, $sourceLength );
71 public function endTag( $name, $sourceStart, $sourceLength ) {
72 $builder = $this->builder;
73 $stack = $builder->stack;
74 $dispatcher = $this->dispatcher;
80 if ( !$stack->isInTableScope( $name ) ) {
81 $builder->error( "</$name> found but no $name in scope", $sourceStart );
84 $builder->clearStackBack( self::$tableBodyContext, $sourceStart );
85 $builder->pop( $sourceStart, $sourceLength );
86 $dispatcher->switchMode( Dispatcher::IN_TABLE );
97 $builder->error( "</$name> found in table body mode, ignoring", $sourceStart );
101 $dispatcher->inTable->endTag( $name, $sourceStart, $sourceLength );
105 public function endDocument( $pos ) {
106 $this->dispatcher->inTable->endDocument( $pos );