mTokens = []; $this->mMarkerIndex = 0; // Replace elements with placeholders $wrappedtext = preg_replace_callback( ParserOutput::EDITSECTION_REGEX, [ $this, 'replaceCallback' ], $text ); // ...and markers $wrappedtext = preg_replace_callback( '/\<\\/?mw:toc\>/', [ $this, 'replaceCallback' ], $wrappedtext ); // ... and tags $wrappedtext = preg_replace_callback( '/\/s', [ $this, 'replaceCallback' ], $wrappedtext ); // Modify inline Microdata and elements so they say and so // we can trick Tidy into not stripping them out by including them in tidy's new-empty-tags config $wrappedtext = preg_replace( '!<(link|meta)([^>]*?)(/{0,1}>)!', ' tags, but those aren't empty. $wrappedtext = preg_replace_callback( '!]*)>(.*?)!s', function ( $m ) { return '' . $this->replaceCallback( [ $m[2] ] ) . ''; }, $wrappedtext ); // Preserve empty li elements (T49673) by abusing Tidy's datafld hack // The whitespace class is as in TY_(InitMap) $wrappedtext = preg_replace( "!
  • ([ \r\n\t\f]*)
  • !", '
  • \1
  • ', $wrappedtext ); // Wrap the whole thing in a doctype and body for Tidy. $wrappedtext = '' . 'test' . $wrappedtext . ''; return $wrappedtext; } /** * @param array $m * @return string */ private function replaceCallback( array $m ) { $marker = Parser::MARKER_PREFIX . "-item-{$this->mMarkerIndex}" . Parser::MARKER_SUFFIX; $this->mMarkerIndex++; $this->mTokens[$marker] = $m[0]; return $marker; } /** * @param string $text * @return string */ public function postprocess( $text ) { // Revert back to <{link,meta,style}> $text = preg_replace( '!]*?)(/{0,1}>)!', '<$1$2$3', $text ); $text = preg_replace( '!<(/?)html-(style)([^>]*)>!', '<$1$2$3>', $text ); // Remove datafld $text = str_replace( '
  • mTokens ); return $text; } }