return $driver->tidy( $text );
}
+ /**
+ * Get CSS modules needed if HTML from the current driver is to be displayed.
+ *
+ * This is just a migration tool to allow some changes expected as part of
+ * Tidy replacement (T89331) to be exposed on the client side via user
+ * scripts, without actually replacing tidy. See T49673.
+ *
+ * @return array
+ */
+ public static function getModuleStyles() {
+ $driver = self::singleton();
+ if ( $driver && $driver instanceof MediaWiki\Tidy\RaggettBase ) {
+ return array( 'mediawiki.raggett' );
+ } else {
+ return array();
+ }
+ }
+
/**
* Check HTML for errors, used if $wgValidateAllHtml = true.
*
if ( MWTidy::isEnabled() && $this->mOptions->getTidy() ) {
$text = MWTidy::tidy( $text );
+ $this->mOutput->addModuleStyles( MWTidy::getModuleStyles() );
} else {
# attempt to sanitize at least some nesting problems
# (bug #2702 and quite a few others)
// 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}>)!', '<html-$1$2$3', $wrappedtext );
+ // Preserve empty li elements (T49673) by abusing Tidy's datafld hack
+ // The whitespace class is as in TY_(InitMap)
+ $wrappedtext = preg_replace( "!<li>([ \r\n\t\f]*)</li>!",
+ '<li datafld="" class="mw-empty-li">\1</li>', $wrappedtext );
+
// Wrap the whole thing in a doctype and body for Tidy.
$wrappedtext = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"' .
' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>' .
// Revert <html-{link,meta}> back to <{link,meta}>
$text = preg_replace( '!<html-(link|meta)([^>]*?)(/{0,1}>)!', '<$1$2$3', $text );
+ // Remove datafld
+ $text = str_replace( '<li datafld=""', '<li', $text );
+
// Restore the contents of placeholder tokens
$text = $this->mTokens->replace( $text );
'scripts' => 'resources/src/mediawiki/mediawiki.experiments.js',
'targets' => array( 'desktop', 'mobile' ),
),
+ 'mediawiki.raggett' => array(
+ 'styles' => 'resources/src/mediawiki/mediawiki.raggett.css'
+ ),
/* MediaWiki Action */
--- /dev/null
+.mw-empty-li {
+ display: none;
+}
<ref name="b"><span id="Z">foo</span>bar</ref>
</references>
!! end
+
+!! test
+Empty LI (T49673)
+!! wikitext
+* a
+*
+*
+* b
+!! html/php+tidy
+<ul>
+<li>a</li>
+<li class="mw-empty-li"></li>
+<li class="mw-empty-li"></li>
+<li>b</li>
+</ul>
+!! end