$blank = false;
}
}
- if ( $this->isA( 'mw:p-wrap' ) ) {
+ if ( $this->isHtmlNamed( 'mw:p-wrap' ) ) {
$this->localName = 'p';
} elseif ( $blank ) {
// Add 'mw-empty-elt' class so elements can be hidden via CSS
}
}
+ /**
+ * Determine if this element is an HTML element with the specified name
+ * @param string $tagName
+ * @return bool
+ */
+ public function isHtmlNamed( $tagName ) {
+ return $this->namespaceURI === BalanceSets::HTML_NAMESPACE
+ && $this->localName === $tagName;
+ }
+
/**
* Determine if $this represents an element in the HTML namespace.
*
public function insertElement( $elt ) {
Assert::parameterType( 'MediaWiki\Tidy\BalanceElement', $elt, '$elt' );
if (
- $this->currentNode->isA( 'mw:p-wrap' ) &&
+ $this->currentNode->isHtmlNamed( 'mw:p-wrap' ) &&
!$elt->isA( BalanceSets::$tidyInlineSet )
) {
// Tidy compatibility.
/**
* Generate implied end tags.
- * @param BalanceElement|array|string|null $butnot
+ * @param string $butnot
* @param bool $thorough True if we should generate end tags thoroughly.
* @see https://html.spec.whatwg.org/multipage/syntax.html#generate-implied-end-tags
*/
BalanceSets::$thoroughImpliedEndTagsSet :
BalanceSets::$impliedEndTagsSet;
while ( $this->length() > 0 ) {
- if ( $butnot !== null && $this->currentNode->isA( $butnot ) ) {
+ if ( $butnot !== null && $this->currentNode->isHtmlNamed( $butnot ) ) {
break;
}
if ( !$this->currentNode->isA( $endTagSet ) ) {
} else {
$this->currentNode = null;
}
- if ( !$elt->isA( 'mw:p-wrap' ) ) {
+ if ( !$elt->isHtmlNamed( 'mw:p-wrap' ) ) {
$elt->flatten( $this->tidyCompat );
}
}
}
} else {
// We're fostering an element; do we need to merge p-wrappers?
- if ( $elt->isA( 'mw:p-wrap' ) ) {
+ if ( $elt->isHtmlNamed( 'mw:p-wrap' ) ) {
$idx = $before ?
array_search( $before, $parent->children, true ) :
count( $parent->children );
$after = $idx > 0 ? $parent->children[$idx - 1] : '';
if (
$after instanceof BalanceElement &&
- $after->isA( 'mw:p-wrap' )
+ $after->isHtmlNamed( 'mw:p-wrap' )
) {
return $after; // Re-use existing p-wrapper.
}
// elements, then pop the current node off the stack of open
// elements and abort these steps.
if (
- $this->currentNode->isA( $tag ) &&
+ $this->currentNode->isHtmlNamed( $tag ) &&
!$afe->isInList( $this->currentNode )
) {
$this->pop();
$stacklen = $this->stack->length();
for ( $j = $i + 1; $j < $stacklen-1; $j++ ) {
$ancestor = $this->stack->node( $stacklen-$j-1 );
- if ( $ancestor->isA( 'template' ) ) {
+ if ( $ancestor->isHtmlNamed( 'template' ) ) {
break;
}
- if ( $ancestor->isA( 'table' ) ) {
+ if ( $ancestor->isHtmlNamed( 'table' ) ) {
$this->switchMode( 'inSelectInTableMode' );
return;
}
case 'li':
# OMITTED: frameset_ok
foreach ( $this->stack as $node ) {
- if ( $node->isA( 'li' ) ) {
+ if ( $node->isHtmlNamed( 'li' ) ) {
$this->inBodyMode( 'endtag', 'li' );
break;
}
case 'dt':
# OMITTED: frameset_ok
foreach ( $this->stack as $node ) {
- if ( $node->isA( 'dd' ) ) {
+ if ( $node->isHtmlNamed( 'dd' ) ) {
$this->inBodyMode( 'endtag', 'dd' );
break;
}
- if ( $node->isA( 'dt' ) ) {
+ if ( $node->isHtmlNamed( 'dt' ) ) {
$this->inBodyMode( 'endtag', 'dt' );
break;
}
case 'optgroup':
case 'option':
- if ( $this->stack->currentNode->isA( 'option' ) ) {
+ if ( $this->stack->currentNode->isHtmlNamed( 'option' ) ) {
$this->inBodyMode( 'endtag', 'option' );
}
$this->afe->reconstruct( $this->stack );
// Any other end tag goes here
foreach ( $this->stack as $i => $node ) {
- if ( $node->isA( $value ) ) {
+ if ( $node->isHtmlNamed( $value ) ) {
$this->stack->generateImpliedEndTags( $value );
$this->stack->popTo( $i ); # including $i
break;
} elseif ( $token === 'endtag' ) {
switch ( $value ) {
case 'colgroup':
- if ( !$this->stack->currentNode->isA( 'colgroup' ) ) {
+ if ( !$this->stack->currentNode->isHtmlNamed( 'colgroup' ) ) {
return true; // Ignore the token.
}
$this->stack->pop();
}
// Anything else
- if ( !$this->stack->currentNode->isA( 'colgroup' ) ) {
+ if ( !$this->stack->currentNode->isHtmlNamed( 'colgroup' ) ) {
return true; // Ignore the token.
}
$this->inColumnGroupMode( 'endtag', 'colgroup' );