| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wikimedia\RemexHtml\TreeBuilder; |
| 4 |
|
| 5 |
use Wikimedia\RemexHtml\Tokenizer\Attributes; |
| 6 |
|
| 7 |
/** |
| 8 |
* The "after after body" insertion mode |
| 9 |
*/ |
| 10 |
class AfterAfterBody extends InsertionMode { |
| 11 |
/** @inheritDoc */ |
| 12 |
public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
| 13 |
[ $part1, $part2 ] = $this->splitInitialMatch( true, "\t\n\f\r ", |
| 14 |
$text, $start, $length, $sourceStart, $sourceLength ); |
| 15 |
[ $start, $length, $sourceStart, $sourceLength ] = $part1; |
| 16 |
if ( $length ) { |
| 17 |
$this->builder->insertCharacters( $text, $start, $length, $sourceStart, $sourceLength ); |
| 18 |
} |
| 19 |
|
| 20 |
[ $start, $length, $sourceStart, $sourceLength ] = $part2; |
| 21 |
if ( !$length ) { |
| 22 |
return; |
| 23 |
} |
| 24 |
$this->builder->error( "unexpected non-whitespace characters after after body", |
| 25 |
$sourceStart ); |
| 26 |
$this->dispatcher->switchMode( Dispatcher::IN_BODY ) |
| 27 |
->characters( $text, $start, $length, $sourceStart, $sourceLength ); |
| 28 |
} |
| 29 |
|
| 30 |
/** @inheritDoc */ |
| 31 |
public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
| 32 |
$builder = $this->builder; |
| 33 |
$dispatcher = $this->dispatcher; |
| 34 |
|
| 35 |
switch ( $name ) { |
| 36 |
case 'html': |
| 37 |
$dispatcher->inBody->startTag( |
| 38 |
$name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 39 |
break; |
| 40 |
|
| 41 |
default: |
| 42 |
$builder->error( "unexpected start tag after after body", $sourceStart ); |
| 43 |
$dispatcher->switchMode( Dispatcher::IN_BODY ) |
| 44 |
->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/** @inheritDoc */ |
| 49 |
public function endTag( $name, $sourceStart, $sourceLength ) { |
| 50 |
$this->builder->error( "unexpected end tag after after body", $sourceStart ); |
| 51 |
$this->dispatcher->switchMode( Dispatcher::IN_BODY ) |
| 52 |
->endTag( $name, $sourceStart, $sourceLength ); |
| 53 |
} |
| 54 |
|
| 55 |
/** @inheritDoc */ |
| 56 |
public function endDocument( $pos ) { |
| 57 |
$this->builder->stopParsing( $pos ); |
| 58 |
} |
| 59 |
|
| 60 |
/** @inheritDoc */ |
| 61 |
public function comment( $text, $sourceStart, $sourceLength ) { |
| 62 |
$this->builder->comment( [ TreeBuilder::ROOT, null ], $text, $sourceStart, $sourceLength ); |
| 63 |
} |
| 64 |
} |