3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
7 * The "in head noscript" insertion mode
9 class InHeadNoscript extends InsertionMode {
10 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
11 $builder = $this->builder;
12 $dispatcher = $this->dispatcher;
15 list( $part1, $part2 ) = $this->splitInitialMatch( true, "\t\n\f\r ",
16 $text, $start, $length, $sourceStart, $sourceLength );
17 list( $start, $length, $sourceStart, $sourceLength ) = $part1;
19 $dispatcher->inHead->characters(
20 $text, $start, $length, $sourceStart, $sourceLength );
23 // Switch mode on non-whitespace
24 list( $start, $length, $sourceStart, $sourceLength ) = $part2;
26 $builder->error( "unexpected non-whitespace character in head in noscript, " .
27 "closing noscript", $sourceStart );
28 $builder->pop( $sourceStart, 0 );
29 $dispatcher->switchMode( Dispatcher::IN_HEAD )
30 ->characters( $text, $start, $length, $sourceStart, $sourceLength );
34 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
35 $builder = $this->builder;
36 $dispatcher = $this->dispatcher;
40 $dispatcher->inBody->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
49 $dispatcher->inHead->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
54 $builder->error( "unexpected <$name> in head in noscript, ignoring", $sourceStart );
58 $builder->error( "unexpected <$name> in head in noscript, closing noscript",
60 $builder->pop( $sourceStart, 0 );
61 $dispatcher->switchMode( Dispatcher::IN_HEAD )
62 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
66 public function endTag( $name, $sourceStart, $sourceLength ) {
67 $builder = $this->builder;
68 $dispatcher = $this->dispatcher;
72 $builder->pop( $sourceStart, $sourceLength );
73 $dispatcher->switchMode( Dispatcher::IN_HEAD );
77 $builder->error( "unexpected </br> in head in noscript, closing noscript",
79 $builder->pop( $sourceStart, 0 );
80 $dispatcher->switchMode( Dispatcher::IN_HEAD )
81 ->endTag( $name, $sourceStart, $sourceLength );
85 $builder->error( "unexpected </$name> in head in noscript, ignoring",
91 public function endDocument( $pos ) {
92 $this->builder->error( "unexpected end-of-file in head in noscript", $pos );
93 $this->builder->pop( $pos, 0 );
94 $this->dispatcher->switchMode( Dispatcher::IN_HEAD )
95 ->endDocument( $pos );