3 namespace RemexHtml\TreeBuilder;
4 use RemexHtml\Tokenizer\Attributes;
7 * The "in template" insertion mode
9 class InTemplate extends InsertionMode {
10 public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
11 $this->dispatcher->inBody->characters(
12 $text, $start, $length, $sourceStart, $sourceLength );
15 public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
16 $dispatcher = $this->dispatcher;
29 $dispatcher->inHead->startTag(
30 $name, $attrs, $selfClose, $sourceStart, $sourceLength );
38 $mode = Dispatcher::IN_TABLE;
42 $mode = Dispatcher::IN_COLUMN_GROUP;
46 $mode = Dispatcher::IN_TABLE_BODY;
51 $mode = Dispatcher::IN_ROW;
55 $mode = Dispatcher::IN_BODY;
59 $dispatcher->templateModeStack->pop();
60 $dispatcher->templateModeStack->push( $mode );
61 $dispatcher->switchMode( $mode )
62 ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
65 public function endTag( $name, $sourceStart, $sourceLength ) {
66 $dispatcher = $this->dispatcher;
70 $dispatcher->inHead->endTag( $name, $sourceStart, $sourceLength );
74 $this->builder->error( "unexpected </$name> in template, ignoring", $sourceStart );
79 public function endDocument( $pos ) {
80 $builder = $this->builder;
81 $stack = $builder->stack;
82 $dispatcher = $this->dispatcher;
84 if ( !$stack->hasTemplate() ) {
85 $builder->stopParsing( $pos );
89 $builder->error( "unexpected end of file in template", $pos );
90 $builder->popAllUpToName( 'template', $pos, 0 );
91 $builder->afe->clearToMarker();
92 $dispatcher->templateModeStack->pop();
94 ->endDocument( $pos );