3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
5 use RemexHtml\Tokenizer\PlainAttributes;
8 * The "after head" insertion mode
10 class AfterHead extends InsertionMode {
11 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
12 $builder = $this->builder;
13 $dispatcher = $this->dispatcher;
16 list( $part1, $part2 ) = $this->splitInitialMatch(
17 true, "\t\n\f\r ", $text, $start, $length, $sourceStart, $sourceLength );
18 list( $start, $length, $sourceStart, $sourceLength ) = $part1;
20 $builder->insertCharacters( $text, $start, $length,
21 $sourceStart, $sourceLength );
24 // Switch mode on non-whitespace
25 list( $start, $length, $sourceStart, $sourceLength ) = $part2;
27 $builder->insertElement( 'body', new PlainAttributes, false, $sourceStart, 0 );
28 $dispatcher->switchMode( Dispatcher::IN_BODY )
29 ->characters( $text, $start, $length, $sourceStart, $sourceLength );
33 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
34 $builder = $this->builder;
35 $stack = $builder->stack;
36 $dispatcher = $this->dispatcher;
40 $dispatcher->inBody->startTag( $name, $attrs, $selfClose,
41 $sourceStart, $sourceLength );
45 $builder->insertElement( $name, $attrs, false, $sourceStart, $sourceLength );
46 $dispatcher->switchMode( Dispatcher::IN_FRAMESET );
59 $builder->error( "unexpected <$name> after </head>, accepting", $sourceStart );
60 $stack->push( $builder->headElement );
61 $dispatcher->inHead->startTag(
62 $name, $attrs, $selfClose, $sourceStart, $sourceLength );
63 $stack->remove( $builder->headElement );
67 $builder->error( "unexpected <head> after </head>, ignoring", $sourceStart );
71 $builder->insertElement( 'body', new PlainAttributes, false, $sourceStart, 0 );
72 $dispatcher->switchMode( Dispatcher::IN_BODY )
73 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
77 public function endTag( $name, $sourceStart, $sourceLength ) {
78 $builder = $this->builder;
79 $dispatcher = $this->dispatcher;
83 $dispatcher->inHead->endTag( $name, $sourceStart, $sourceLength );
89 $builder->insertElement( 'body', new PlainAttributes, false, $sourceStart, 0 );
90 $dispatcher->switchMode( Dispatcher::IN_BODY )
91 ->endTag( $name, $sourceStart, $sourceLength );
95 $builder->error( "unexpected </$name> after head, ignoring", $sourceStart );
100 public function endDocument( $pos ) {
101 $this->builder->insertElement( 'body', new PlainAttributes, false, $pos, 0 );
102 $this->dispatcher->switchMode( Dispatcher::IN_BODY )
103 ->endDocument( $pos );