+ // Handle any other start tag here
+ $this->afe->reconstruct( $this->stack );
+ $this->stack->insertHTMLElement( $value, $attribs );
+ return true;
+ } elseif ( $token === 'endtag' ) {
+ switch ( $value ) {
+ // </body>,</html> are unsupported.
+
+ case 'template':
+ return $this->inHeadMode( $token, $value, $attribs, $selfClose );
+
+ case 'address':
+ case 'article':
+ case 'aside':
+ case 'blockquote':
+ case 'button':
+ case 'center':
+ case 'details':
+ case 'dialog':
+ case 'dir':
+ case 'div':
+ case 'dl':
+ case 'fieldset':
+ case 'figcaption':
+ case 'figure':
+ case 'footer':
+ case 'header':
+ case 'hgroup':
+ case 'listing':
+ case 'main':
+ case 'menu':
+ case 'nav':
+ case 'ol':
+ case 'pre':
+ case 'section':
+ case 'summary':
+ case 'ul':
+ // Ignore if there is not a matching open tag
+ if ( !$this->stack->inScope( $value ) ) {
+ return true;
+ }
+ $this->stack->generateImpliedEndTags();
+ $this->stack->popTag( $value );
+ return true;
+
+ case 'form':
+ if ( $this->stack->indexOf( 'template' ) < 0 ) {
+ $openform = $this->formElementPointer;
+ $this->formElementPointer = null;
+ if ( !$openform || !$this->stack->inScope( $openform ) ) {
+ return true;
+ }
+ $this->stack->generateImpliedEndTags();
+ // Don't flatten yet if we're removing a <form> element
+ // out-of-order. (eg. `<form><div></form>`)
+ $flatten = ( $this->stack->currentNode === $openform );
+ $this->stack->removeElement( $openform, $flatten );
+ } else {
+ if ( !$this->stack->inScope( 'form' ) ) {
+ return true;
+ }
+ $this->stack->generateImpliedEndTags();
+ $this->stack->popTag( 'form' );
+ }
+ return true;
+
+ case 'p':
+ if ( !$this->stack->inButtonScope( 'p' ) ) {
+ $this->inBodyMode( 'tag', 'p', [] );
+ return $this->insertToken( $token, $value, $attribs, $selfClose );
+ }
+ $this->stack->generateImpliedEndTags( $value );
+ $this->stack->popTag( $value );
+ return true;
+
+ case 'li':
+ if ( !$this->stack->inListItemScope( $value ) ) {
+ return true; // ignore
+ }
+ $this->stack->generateImpliedEndTags( $value );
+ $this->stack->popTag( $value );
+ return true;
+
+ case 'dd':
+ case 'dt':
+ if ( !$this->stack->inScope( $value ) ) {
+ return true; // ignore
+ }
+ $this->stack->generateImpliedEndTags( $value );
+ $this->stack->popTag( $value );
+ return true;
+
+ case 'h1':
+ case 'h2':
+ case 'h3':
+ case 'h4':
+ case 'h5':
+ case 'h6':
+ if ( !$this->stack->inScope( BalanceSets::$headingSet ) ) {
+ return true; // ignore
+ }
+ $this->stack->generateImpliedEndTags();
+ $this->stack->popTag( BalanceSets::$headingSet );
+ return true;
+
+ case 'sarcasm':
+ // Take a deep breath, then:
+ break;
+
+ case 'a':
+ case 'b':
+ case 'big':
+ case 'code':
+ case 'em':
+ case 'font':
+ case 'i':
+ case 'nobr':
+ case 's':
+ case 'small':
+ case 'strike':
+ case 'strong':
+ case 'tt':
+ case 'u':
+ if ( $this->stack->adoptionAgency( $value, $this->afe ) ) {
+ return true; // If we did something, we're done.
+ }
+ break; // Go to the "any other end tag" case.
+
+ case 'applet':
+ case 'marquee':
+ case 'object':
+ if ( !$this->stack->inScope( $value ) ) {
+ return true; // ignore
+ }
+ $this->stack->generateImpliedEndTags();
+ $this->stack->popTag( $value );
+ $this->afe->clearToMarker();
+ return true;