3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
7 * The "in caption" insertion mode
9 class InCaption extends InsertionMode {
10 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
11 $this->dispatcher->inBody->characters( $text, $start, $length,
12 $sourceStart, $sourceLength );
15 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
16 $builder = $this->builder;
17 $stack = $builder->stack;
28 $builder->error( "start tag <$name> not allowed in caption", $sourceStart );
29 if ( !$stack->isInTableScope( 'caption' ) ) {
33 $builder->popAllUpToName( 'caption', $sourceStart, 0 );
34 $builder->afe->clearToMarker();
35 $this->dispatcher->switchMode( Dispatcher::IN_TABLE )
36 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
40 $this->dispatcher->inBody->startTag( $name, $attrs, $selfClose,
41 $sourceStart, $sourceLength );
45 public function endTag( $name, $sourceStart, $sourceLength ) {
46 $dispatcher = $this->dispatcher;
47 $builder = $this->builder;
48 $stack = $builder->stack;
52 if ( !$stack->isInTableScope( 'caption' ) ) {
53 $builder->error( "</caption> matches a start tag which is not in scope, ignoring",
58 $builder->generateImpliedEndTags( null, $sourceStart );
59 if ( $stack->current->htmlName !== 'caption' ) {
60 $builder->error( "</caption> found but another element is open", $sourceStart );
62 $builder->popAllUpToName( 'caption', $sourceStart, $sourceLength );
63 $builder->afe->clearToMarker();
64 $dispatcher->switchMode( Dispatcher::IN_TABLE );
68 if ( !$stack->isInTableScope( 'caption' ) ) {
69 $builder->error( '</table> found in caption, but there is no ' .
70 'caption in scope, ignoring', $sourceStart );
73 $builder->generateImpliedEndTags( false, $sourceStart );
74 if ( $stack->current->htmlName !== 'caption' ) {
75 $builder->error( '</table> found in caption, closing caption', $sourceStart );
77 $builder->popAllUpToName( 'caption', $sourceStart, 0 );
78 $builder->afe->clearToMarker();
79 $dispatcher->switchMode( Dispatcher::IN_TABLE )
80 ->endTag( $name, $sourceStart, $sourceLength );
93 $this->builder->error( "end tag </$name> ignored in caption mode", $sourceStart );
97 $this->dispatcher->inBody->endTag( $name, $sourceStart, $sourceLength );
101 public function endDocument( $pos ) {
102 $this->dispatcher->inBody->endDocument( $pos );