diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index f3a83dbe89..06f457236b 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -295,6 +295,24 @@ class ParserOutput extends CacheTime { $text = substr( $text, 0, $endPos - $startLen ) . substr( $text, $endPos - $startLen + $endLen ); } + + # Also unwrap unwanted
tags. + # (T178398) + $start = Html::openElement( 'main' ); + $startLen = strlen( $start ); + $end = Html::closeElement( 'main' ); + $endPos = strrpos( $text, $end ); + $endLen = strlen( $end ); + + if ( substr( $text, 0, $startLen ) === $start && $endPos !== false + // if the closing main is followed by real content, bail out of unwrapping + && preg_match( '/^(?>\s*)*\s*$/s', substr( $text, $endPos + $endLen ) ) + ) { + $text = substr( $text, $startLen ); + $text = substr( $text, 0, $endPos - $startLen ) + . substr( $text, $endPos - $startLen + $endLen ); + } + } if ( $options['enableSectionEditLinks'] ) {