X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InCaption.php diff --git a/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InCaption.php b/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InCaption.php new file mode 100644 index 00000000..da2a11ad --- /dev/null +++ b/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InCaption.php @@ -0,0 +1,104 @@ +dispatcher->inBody->characters( $text, $start, $length, + $sourceStart, $sourceLength ); + } + + public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { + $builder = $this->builder; + $stack = $builder->stack; + switch ( $name ) { + case 'caption': + case 'col': + case 'colgroup': + case 'tbody': + case 'td': + case 'tfoot': + case 'th': + case 'thead': + case 'tr': + $builder->error( "start tag <$name> not allowed in caption", $sourceStart ); + if ( !$stack->isInTableScope( 'caption' ) ) { + // Ignore + return; + } + $builder->popAllUpToName( 'caption', $sourceStart, 0 ); + $builder->afe->clearToMarker(); + $this->dispatcher->switchMode( Dispatcher::IN_TABLE ) + ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); + break; + + default: + $this->dispatcher->inBody->startTag( $name, $attrs, $selfClose, + $sourceStart, $sourceLength ); + } + } + + public function endTag( $name, $sourceStart, $sourceLength ) { + $dispatcher = $this->dispatcher; + $builder = $this->builder; + $stack = $builder->stack; + + switch ( $name ) { + case 'caption': + if ( !$stack->isInTableScope( 'caption' ) ) { + $builder->error( " matches a start tag which is not in scope, ignoring", + $sourceStart ); + return; + } + + $builder->generateImpliedEndTags( null, $sourceStart ); + if ( $stack->current->htmlName !== 'caption' ) { + $builder->error( " found but another element is open", $sourceStart ); + } + $builder->popAllUpToName( 'caption', $sourceStart, $sourceLength ); + $builder->afe->clearToMarker(); + $dispatcher->switchMode( Dispatcher::IN_TABLE ); + break; + + case 'table': + if ( !$stack->isInTableScope( 'caption' ) ) { + $builder->error( ' found in caption, but there is no ' . + 'caption in scope, ignoring', $sourceStart ); + return; + } + $builder->generateImpliedEndTags( false, $sourceStart ); + if ( $stack->current->htmlName !== 'caption' ) { + $builder->error( ' found in caption, closing caption', $sourceStart ); + } + $builder->popAllUpToName( 'caption', $sourceStart, 0 ); + $builder->afe->clearToMarker(); + $dispatcher->switchMode( Dispatcher::IN_TABLE ) + ->endTag( $name, $sourceStart, $sourceLength ); + break; + + case 'body': + case 'col': + case 'colgroup': + case 'html': + case 'tbody': + case 'td': + case 'tfoot': + case 'th': + case 'thead': + case 'tr': + $this->builder->error( "end tag ignored in caption mode", $sourceStart ); + break; + + default: + $this->dispatcher->inBody->endTag( $name, $sourceStart, $sourceLength ); + } + } + + public function endDocument( $pos ) { + $this->dispatcher->inBody->endDocument( $pos ); + } +}