Debian Codegraph @

vendor/wikimedia/remex-html/src/TreeBuilder/InHeadNoscript.php

raw
1 <?php
2
3 namespace Wikimedia\RemexHtml\TreeBuilder;
4
5 use Wikimedia\RemexHtml\Tokenizer\Attributes;
6
7 /**
8 * The "in head noscript" insertion mode
9 */
10 class InHeadNoscript extends InsertionMode {
11 /** @inheritDoc */
12 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
13 $builder = $this->builder;
14 $dispatcher = $this->dispatcher;
15
16 // Insert whitespace
17 [ $part1, $part2 ] = $this->splitInitialMatch( true, "\t\n\f\r ",
18 $text, $start, $length, $sourceStart, $sourceLength );
19 [ $start, $length, $sourceStart, $sourceLength ] = $part1;
20 if ( $length ) {
21 $dispatcher->inHead->characters(
22 $text, $start, $length, $sourceStart, $sourceLength );
23 }
24
25 // Switch mode on non-whitespace
26 [ $start, $length, $sourceStart, $sourceLength ] = $part2;
27 if ( $length ) {
28 $builder->error( "unexpected non-whitespace character in head in noscript, " .
29 "closing noscript", $sourceStart );
30 $builder->pop( $sourceStart, 0 );
31 $dispatcher->switchMode( Dispatcher::IN_HEAD )
32 ->characters( $text, $start, $length, $sourceStart, $sourceLength );
33 }
34 }
35
36 /** @inheritDoc */
37 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
38 $builder = $this->builder;
39 $dispatcher = $this->dispatcher;
40
41 switch ( $name ) {
42 case 'html':
43 $dispatcher->inBody->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
44 break;
45
46 case 'basefont':
47 case 'bgsound':
48 case 'link':
49 case 'meta':
50 case 'noframes':
51 case 'style':
52 $dispatcher->inHead->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
53 break;
54
55 case 'head':
56 case 'noscript':
57 $builder->error( "unexpected <$name> in head in noscript, ignoring", $sourceStart );
58 return;
59
60 default:
61 $builder->error( "unexpected <$name> in head in noscript, closing noscript",
62 $sourceStart );
63 $builder->pop( $sourceStart, 0 );
64 $dispatcher->switchMode( Dispatcher::IN_HEAD )
65 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
66 }
67 }
68
69 /** @inheritDoc */
70 public function endTag( $name, $sourceStart, $sourceLength ) {
71 $builder = $this->builder;
72 $dispatcher = $this->dispatcher;
73
74 switch ( $name ) {
75 case 'noscript':
76 $builder->pop( $sourceStart, $sourceLength );
77 $dispatcher->switchMode( Dispatcher::IN_HEAD );
78 break;
79
80 case 'br':
81 $builder->error( "unexpected </br> in head in noscript, closing noscript",
82 $sourceStart );
83 $builder->pop( $sourceStart, 0 );
84 $dispatcher->switchMode( Dispatcher::IN_HEAD )
85 ->endTag( $name, $sourceStart, $sourceLength );
86 break;
87
88 default:
89 $builder->error( "unexpected </$name> in head in noscript, ignoring",
90 $sourceStart );
91 return;
92 }
93 }
94
95 /** @inheritDoc */
96 public function endDocument( $pos ) {
97 $this->builder->error( "unexpected end-of-file in head in noscript", $pos );
98 $this->builder->pop( $pos, 0 );
99 $this->dispatcher->switchMode( Dispatcher::IN_HEAD )
100 ->endDocument( $pos );
101 }
102 }