Merge "Hide TOC with CSS instead of JavaScript"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 11 Jul 2018 20:36:22 +0000 (20:36 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 11 Jul 2018 20:36:22 +0000 (20:36 +0000)
1  2 
includes/Linker.php
includes/api/ApiHelp.php
includes/skins/Skin.php
resources/Resources.php
tests/parser/parserTests.txt

diff --combined includes/Linker.php
@@@ -38,6 -38,29 +38,6 @@@ class Linker 
        const TOOL_LINKS_NOBLOCK = 1;
        const TOOL_LINKS_EMAIL = 2;
  
 -      /**
 -       * Return the CSS colour of a known link
 -       *
 -       * @deprecated since 1.28, use LinkRenderer::getLinkClasses() instead
 -       *
 -       * @since 1.16.3
 -       * @param LinkTarget $t
 -       * @param int $threshold User defined threshold
 -       * @return string CSS class
 -       */
 -      public static function getLinkColour( LinkTarget $t, $threshold ) {
 -              wfDeprecated( __METHOD__, '1.28' );
 -              $services = MediaWikiServices::getInstance();
 -              $linkRenderer = $services->getLinkRenderer();
 -              if ( $threshold !== $linkRenderer->getStubThreshold() ) {
 -                      // Need to create a new instance with the right stub threshold...
 -                      $linkRenderer = $services->getLinkRendererFactory()->create();
 -                      $linkRenderer->setStubThreshold( $threshold );
 -              }
 -
 -              return $linkRenderer->getLinkClasses( $t );
 -      }
 -
        /**
         * This function returns an HTML link to the given target.  It serves a few
         * purposes:
                $res = null;
                $dummy = new DummyLinker;
                if ( !Hooks::run( 'ImageBeforeProduceHTML', [ &$dummy, &$title,
 -                      &$file, &$frameParams, &$handlerParams, &$time, &$res ] ) ) {
 +                      &$file, &$frameParams, &$handlerParams, &$time, &$res,
 +                      $parser, &$query, &$widthOption
 +              ] ) ) {
                        return $res;
                }
  
                }
  
                // Clean up parameters
 -              $page = isset( $handlerParams['page'] ) ? $handlerParams['page'] : false;
 +              $page = $handlerParams['page'] ?? false;
                if ( !isset( $frameParams['align'] ) ) {
                        $frameParams['align'] = '';
                }
                        $params = [
                                'alt' => $frameParams['alt'],
                                'title' => $frameParams['title'],
 -                              'valign' => isset( $frameParams['valign'] ) ? $frameParams['valign'] : false,
 +                              'valign' => $frameParams['valign'] ?? false,
                                'img-class' => $frameParams['class'] ];
                        if ( isset( $frameParams['border'] ) ) {
                                $params['img-class'] .= ( $params['img-class'] !== '' ? ' ' : '' ) . 'thumbborder';
         * @param string $manualthumb
         * @return string
         */
 -      public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
 +      public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt = '',
                $align = 'right', $params = [], $framed = false, $manualthumb = ""
        ) {
                $frameParams = [
        ) {
                $exists = $file && $file->exists();
  
 -              $page = isset( $handlerParams['page'] ) ? $handlerParams['page'] : false;
 +              $page = $handlerParams['page'] ?? false;
                if ( !isset( $frameParams['align'] ) ) {
                        $frameParams['align'] = 'right';
                }
                        $key = strtolower( $name );
                }
  
 -              return self::linkKnown( SpecialPage::getTitleFor( $name ), wfMessage( $key )->text() );
 +              return self::linkKnown( SpecialPage::getTitleFor( $name ), wfMessage( $key )->escaped() );
        }
  
        /**
         *   red if the user has no edits?
         * @param int $flags Customisation flags (e.g. Linker::TOOL_LINKS_NOBLOCK
         *   and Linker::TOOL_LINKS_EMAIL).
 -       * @param int $edits User edit count (optional, for performance)
 +       * @param int|null $edits User edit count (optional, for performance)
         * @return string HTML fragment
         */
        public static function userToolLinks(
         * @since 1.16.3
         * @param int $userId User identifier
         * @param string $userText User name or IP address
 -       * @param int $edits User edit count (optional, for performance)
 +       * @param int|null $edits User edit count (optional, for performance)
         * @return string
         */
        public static function userToolLinksRedContribs( $userId, $userText, $edits = null ) {
         * @todo FIXME: Doesn't handle sub-links as in image thumb texts like the main parser
         *
         * @param string $comment Text to format links in. WARNING! Since the output of this
 -       *      function is html, $comment must be sanitized for use as html. You probably want
 -       *      to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling
 -       *      this function.
 +       *      function is html, $comment must be sanitized for use as html. You probably want
 +       *      to pass $comment through Sanitizer::escapeHtmlAllowEntities() before calling
 +       *      this function.
         * @param Title|null $title An optional title object used to links to sections
         * @param bool $local Whether section links should refer to local page
         * @param string|null $wikiId Id of the wiki to link to (if not the local wiki),
                $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
  
                return '<div id="toc" class="toc">'
+                       . Html::element( 'input', [
+                               'type' => 'checkbox',
+                               'id' => 'toctogglecheckbox',
+                               'class' => 'toctogglecheckbox',
+                               'style' => 'display:none',
+                       ] )
                        . Html::openElement( 'div', [
                                'class' => 'toctitle',
                                'lang' => $lang->getHtmlCode(),
                                'dir' => $lang->getDir(),
                        ] )
-                       . '<h2>' . $title . "</h2></div>\n"
+                       . "<h2>$title</h2>"
+                       . '<span class="toctogglespan">'
+                       . Html::label( '', 'toctogglecheckbox', [
+                               'class' => 'toctogglelabel',
+                       ] )
+                       . '</span>'
+                       . "</div>\n"
                        . $toc
                        . "</ul>\n</div>\n";
        }
         * @since 1.16.3. $context added in 1.20. $options added in 1.21
         *
         * @param Revision $rev
 -       * @param IContextSource $context Context to use or null for the main context.
 +       * @param IContextSource|null $context Context to use or null for the main context.
         * @param array $options
         * @return string
         */
diff --combined includes/api/ApiHelp.php
@@@ -104,6 -104,7 +104,7 @@@ class ApiHelp extends ApiBase 
                ] );
                if ( !empty( $options['toc'] ) ) {
                        $out->addModules( 'mediawiki.toc' );
+                       $out->addModuleStyles( 'mediawiki.toc.styles' );
                }
                $out->setPageTitle( $context->msg( 'api-help-title' ) );
  
                }
                $out->addHTML( $html );
  
 -              $helptitle = isset( $options['helptitle'] ) ? $options['helptitle'] : null;
 +              $helptitle = $options['helptitle'] ?? null;
                $html = self::fixHelpLinks( $out->getHTML(), $helptitle, $haveModules );
                $out->clearHTML();
                $out->addHTML( $html );
                                                }
                                        }
  
 +                                      // Templated?
 +                                      if ( !empty( $settings[ApiBase::PARAM_TEMPLATE_VARS] ) ) {
 +                                              $vars = [];
 +                                              $msg = 'api-help-param-templated-var-first';
 +                                              foreach ( $settings[ApiBase::PARAM_TEMPLATE_VARS] as $k => $v ) {
 +                                                      $vars[] = $context->msg( $msg, $k, $module->encodeParamName( $v ) );
 +                                                      $msg = 'api-help-param-templated-var';
 +                                              }
 +                                              $info[] = $context->msg( 'api-help-param-templated' )
 +                                                      ->numParams( count( $vars ) )
 +                                                      ->params( Message::listParam( $vars ) )
 +                                                      ->parse();
 +                                      }
 +
                                        // Type documentation
                                        if ( !isset( $settings[ApiBase::PARAM_TYPE] ) ) {
 -                                              $dflt = isset( $settings[ApiBase::PARAM_DFLT] )
 -                                                      ? $settings[ApiBase::PARAM_DFLT]
 -                                                      : null;
 +                                              $dflt = $settings[ApiBase::PARAM_DFLT] ?? null;
                                                if ( is_bool( $dflt ) ) {
                                                        $settings[ApiBase::PARAM_TYPE] = 'boolean';
                                                } elseif ( is_string( $dflt ) || is_null( $dflt ) ) {
  
                                                if ( is_array( $type ) ) {
                                                        $count = count( $type );
 -                                                      $deprecatedValues = isset( $settings[ApiBase::PARAM_DEPRECATED_VALUES] )
 -                                                              ? $settings[ApiBase::PARAM_DEPRECATED_VALUES]
 -                                                              : [];
 -                                                      $links = isset( $settings[ApiBase::PARAM_VALUE_LINKS] )
 -                                                              ? $settings[ApiBase::PARAM_VALUE_LINKS]
 -                                                              : [];
 +                                                      $deprecatedValues = $settings[ApiBase::PARAM_DEPRECATED_VALUES] ?? [];
 +                                                      $links = $settings[ApiBase::PARAM_VALUE_LINKS] ?? [];
                                                        $values = array_map( function ( $v ) use ( $links, $deprecatedValues ) {
                                                                $attr = [];
                                                                if ( $v !== '' ) {
                                                                $info[] = implode( ' ', $extra );
                                                        }
  
 -                                                      $allowAll = isset( $settings[ApiBase::PARAM_ALL] )
 -                                                              ? $settings[ApiBase::PARAM_ALL]
 -                                                              : false;
 +                                                      $allowAll = $settings[ApiBase::PARAM_ALL] ?? false;
                                                        if ( $allowAll || $settings[ApiBase::PARAM_TYPE] === 'namespace' ) {
                                                                if ( $settings[ApiBase::PARAM_TYPE] === 'namespace' ) {
                                                                        $allSpecifier = ApiBase::ALL_DEFAULT_STRING;
                                        }
  
                                        // Add default
 -                                      $default = isset( $settings[ApiBase::PARAM_DFLT] )
 -                                              ? $settings[ApiBase::PARAM_DFLT]
 -                                              : null;
 +                                      $default = $settings[ApiBase::PARAM_DFLT] ?? null;
                                        if ( $default === '' ) {
                                                $info[] = $context->msg( 'api-help-param-default-empty' )
                                                        ->parse();
diff --combined includes/skins/Skin.php
@@@ -21,8 -21,6 +21,8 @@@
   */
  
  use MediaWiki\MediaWikiServices;
 +use Wikimedia\WrappedString;
 +use Wikimedia\WrappedStringList;
  
  /**
   * @defgroup Skins Skins
@@@ -212,9 -210,15 +212,9 @@@ abstract class Skin extends ContextSour
                        'syndicate' => [],
                ];
  
 -              // Support for high-density display images if enabled
 -              if ( $config->get( 'ResponsiveImages' ) ) {
 -                      $modules['core'][] = 'mediawiki.hidpi';
 -              }
 -
                // Preload jquery.tablesorter for mediawiki.page.ready
                if ( strpos( $out->getHTML(), 'sortable' ) !== false ) {
                        $modules['content'][] = 'jquery.tablesorter';
 -                      $modules['styles']['content'][] = 'jquery.tablesorter.styles';
                }
  
                // Preload jquery.makeCollapsible for mediawiki.page.ready
  
                if ( $out->isTOCEnabled() ) {
                        $modules['content'][] = 'mediawiki.toc';
+                       $modules['styles']['content'][] = 'mediawiki.toc.styles';
                }
  
                // Add various resources if required
  
        /**
         * Outputs the HTML generated by other functions.
 -       * @param OutputPage $out
 +       * @param OutputPage|null $out
         */
        abstract function outputPage( OutputPage $out = null );
  
        /**
         * @param array $data
 -       * @return string
 +       * @param string|null $nonce OutputPage::getCSPNonce()
 +       * @return string|WrappedString HTML
         */
 -      static function makeVariablesScript( $data ) {
 +      static function makeVariablesScript( $data, $nonce = null ) {
                if ( $data ) {
                        return ResourceLoader::makeInlineScript(
 -                              ResourceLoader::makeConfigSetScript( $data )
 +                              ResourceLoader::makeConfigSetScript( $data ),
 +                              $nonce
                        );
                } else {
                        return '';
        /**
         * This gets called shortly before the "</body>" tag.
         *
 -       * @return string HTML-wrapped JS code to be put before "</body>"
 +       * @return string|WrappedStringList HTML containing scripts to put before `</body>`
         */
        function bottomScripts() {
                // TODO and the suckage continues. This function is really just a wrapper around
                // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
                // up at some point
 -              $bottomScriptText = $this->getOutput()->getBottomScripts();
 -              Hooks::run( 'SkinAfterBottomScripts', [ $this, &$bottomScriptText ] );
 -
 -              return $bottomScriptText;
 +              $chunks = [ $this->getOutput()->getBottomScripts() ];
 +
 +              // Keep the hook appendage separate to preserve WrappedString objects.
 +              // This enables BaseTemplate::getTrail() to merge them where possible.
 +              $extraHtml = '';
 +              Hooks::run( 'SkinAfterBottomScripts', [ $this, &$extraHtml ] );
 +              if ( $extraHtml !== '' ) {
 +                      $chunks[] = $extraHtml;
 +              }
 +              return WrappedString::join( "\n", $chunks );
        }
  
        /**
        }
  
        /**
 -       * @param OutputPage $out Defaults to $this->getOutput() if left as null
 +       * @param OutputPage|null $out Defaults to $this->getOutput() if left as null
         * @return string
         */
        function subPageSubtitle( $out = null ) {
                if ( is_string( $icon ) ) {
                        $html = $icon;
                } else { // Assuming array
 -                      $url = isset( $icon["url"] ) ? $icon["url"] : null;
 +                      $url = $icon["url"] ?? null;
                        unset( $icon["url"] );
                        if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
                                // do this the lazy way, just pass icon data as an attribute array
        }
  
        /**
 -       * Return a fully resolved style path url to images or styles stored in the current skins's folder.
 -       * This method returns a url resolved using the configured skin style path
 -       * and includes the style version inside of the url.
 +       * Return a fully resolved style path URL to images or styles stored in the
 +       * current skin's folder. This method returns a URL resolved using the
 +       * configured skin style path.
         *
         * Requires $stylename to be set, otherwise throws MWException.
         *
         * @param string $name The name or path of a skin resource file
 -       * @return string The fully resolved style path url including styleversion
 +       * @return string The fully resolved style path URL
         * @throws MWException
         */
        function getSkinStylePath( $name ) {
 -              global $wgStylePath, $wgStyleVersion;
 +              global $wgStylePath;
  
                if ( $this->stylename === null ) {
                        $class = static::class;
                        throw new MWException( "$class::\$stylename must be set to use getSkinStylePath()" );
                }
  
 -              return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
 +              return "$wgStylePath/{$this->stylename}/$name";
        }
  
        /* these are used extensively in SkinTemplate, but also some other places */
  
                if ( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
                        $uTalkTitle = $user->getTalkPage();
 -                      $lastSeenRev = isset( $newtalks[0]['rev'] ) ? $newtalks[0]['rev'] : null;
 +                      $lastSeenRev = $newtalks[0]['rev'] ?? null;
                        $nofAuthors = 0;
                        if ( $lastSeenRev !== null ) {
                                $plural = true; // Default if we have a last seen revision: if unknown, use plural
        }
  
        /**
 -       * Create a section edit link.  This supersedes editSectionLink() and
 -       * editSectionLinkForOther().
 +       * Create a section edit link.
         *
         * @param Title $nt The title being linked to (may not be the same as
         *   the current page, if the section is included from a template)
         * @param string $section The designation of the section being pointed to,
         *   to be included in the link, like "&section=$section"
 -       * @param string $tooltip The tooltip to use for the link: will be escaped
 +       * @param string|null $tooltip The tooltip to use for the link: will be escaped
         *   and wrapped in the 'editsectionhint' message
         * @param string $lang Language code
         * @return string HTML to use for edit link
diff --combined resources/Resources.php
@@@ -58,6 -58,9 +58,6 @@@ return 
        'user.options' => [ 'class' => ResourceLoaderUserOptionsModule::class ],
        'user.tokens' => [ 'class' => ResourceLoaderUserTokensModule::class ],
  
 -      // Scripts for the dynamic language specific data, like grammar forms.
 -      'mediawiki.language.data' => [ 'class' => ResourceLoaderLanguageDataModule::class ],
 -
        /* MediaWiki base skinning modules */
  
        /**
@@@ -81,7 -84,8 +81,7 @@@
         *     The highest level, this stylesheet contains extra common styles for classes like
         *     .firstHeading, #contentSub, et cetera which are not outputted by MediaWiki but are common
         *     to skins like MonoBook, Vector, etc... Essentially this level is for styles that are
 -       *     common to MonoBook clones. And since practically every skin that currently exists within
 -       *     core is a MonoBook clone, all our core skins currently use this level.
 +       *     common to MonoBook clones.
         *
         * These modules are typically loaded by addModuleStyles(), which has absolutely no concept of
         * dependency management. As a result they contain duplicate stylesheet references instead of
  
        'mediawiki.skinning.content.externallinks' => [
                'styles' => [
 -                      'resources/src/mediawiki.skinning/content.externallinks.css' => [ 'media' => 'screen' ],
 +                      'resources/src/mediawiki.skinning/content.externallinks.less' => [ 'media' => 'screen' ],
                ],
        ],
  
        'jquery.expandableField' => [
                'scripts' => 'resources/src/jquery/jquery.expandableField.js',
        ],
 -      'jquery.farbtastic' => [
 -              'scripts' => 'resources/src/jquery/jquery.farbtastic.js',
 -              'styles' => 'resources/src/jquery/jquery.farbtastic.css',
 -              'dependencies' => 'jquery.colorUtil',
 -      ],
 -      'jquery.footHovzer' => [
 -              'scripts' => 'resources/src/jquery/jquery.footHovzer.js',
 -              'styles' => 'resources/src/jquery/jquery.footHovzer.css',
 -      ],
        'jquery.form' => [
                'scripts' => 'resources/lib/jquery/jquery.form.js',
        ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'jquery.hidpi' => [
 +              'deprecated' => 'Use of the srcset polyfill is deprecated since MediaWiki 1.32.0',
                'scripts' => 'resources/src/jquery/jquery.hidpi.js',
                'targets' => [ 'desktop', 'mobile' ],
        ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'jquery.spinner' => [
 -              'scripts' => 'resources/src/jquery/jquery.spinner.js',
 -              'styles' => 'resources/src/jquery/jquery.spinner.css',
 +              'scripts' => 'resources/src/jquery.spinner/spinner.js',
 +              'styles' => 'resources/src/jquery.spinner/spinner.css',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'jquery.jStorage' => [
                'scripts' => 'resources/src/jquery/jquery.tabIndex.js',
        ],
        'jquery.tablesorter' => [
 +              'targets' => [ 'desktop', 'mobile' ],
                'scripts' => 'resources/src/jquery.tablesorter/jquery.tablesorter.js',
                'styles' => 'resources/src/jquery.tablesorter/jquery.tablesorter.less',
                'messages' => [ 'sort-descending', 'sort-ascending' ],
                'dependencies' => [
 -                      'jquery.tablesorter.styles',
                        'mediawiki.RegExp',
                        'mediawiki.language.months',
                ],
        ],
 -      'jquery.tablesorter.styles' => [
 -              'targets' => [ 'desktop', 'mobile' ],
 -              'styles' => [
 -                      'resources/src/jquery/jquery.tablesorter.styles.less',
 -              ],
 -      ],
        'jquery.textSelection' => [
                'scripts' => 'resources/src/jquery/jquery.textSelection.js',
                'dependencies' => 'jquery.client',
                'group' => 'jquery.ui',
        ],
  
 -      /* json2 */
 -      'json' => [
 -              'deprecated' => 'Use of the "json" module is deprecated since MediaWiki 1.29.0',
 -              'targets' => [ 'desktop', 'mobile' ],
 -      ],
 -
        /* Moment.js */
  
        'moment' => [
  
        /* MediaWiki */
  
 -      'mediawiki' => [
 -              'class' => ResourceLoaderRawFileModule::class,
 +      'mediawiki.base' => [
                // Keep in sync with maintenance/jsduck/eg-iframe.html
                'scripts' => [
 -                      'resources/src/mediawiki/mediawiki.js',
 -                      'resources/src/mediawiki/mediawiki.requestIdleCallback.js',
 -                      'resources/src/mediawiki/mediawiki.errorLogger.js',
 +                      'resources/src/mediawiki.base/mediawiki.errorLogger.js',
 +                      'resources/src/mediawiki.base/mediawiki.base.js',
                ],
 -              'debugScripts' => 'resources/src/mediawiki/mediawiki.log.js',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.apihelp' => [
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.api' => [
 -              'scripts' => 'resources/src/mediawiki.api.js',
 +              'scripts' => [
 +                      'resources/src/mediawiki.api/index.js',
 +                      'resources/src/mediawiki.api/category.js',
 +                      'resources/src/mediawiki.api/edit.js',
 +                      'resources/src/mediawiki.api/login.js',
 +                      'resources/src/mediawiki.api/messages.js',
 +                      'resources/src/mediawiki.api/options.js',
 +                      'resources/src/mediawiki.api/parse.js',
 +                      'resources/src/mediawiki.api/rollback.js',
 +                      'resources/src/mediawiki.api/upload.js',
 +                      'resources/src/mediawiki.api/user.js',
 +                      'resources/src/mediawiki.api/watch.js',
 +              ],
                'dependencies' => [
 +                      'mediawiki.Title',
                        'mediawiki.util',
                        'user.tokens',
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.api.category' => [
 -              'scripts' => 'resources/src/mediawiki.api.category.js',
 -              'dependencies' => [
 -                      'mediawiki.api',
 -                      'mediawiki.Title',
 -              ],
 +              'deprecated' => 'Use "mediawiki.api" instead.',
 +              'dependencies' => 'mediawiki.api',
        ],
        'mediawiki.api.edit' => [
 -              'scripts' => 'resources/src/mediawiki.api.edit.js',
 +              'deprecated' => 'Use "mediawiki.api" instead.',
                'dependencies' => [
                        'mediawiki.api',
 -                      'mediawiki.user',
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.api.login' => [
 -              'scripts' => 'resources/src/mediawiki.api.login.js',
 +              'deprecated' => 'Use "mediawiki.api" instead.',
                'dependencies' => 'mediawiki.api',
        ],
        'mediawiki.api.options' => [
 -              'scripts' => 'resources/src/mediawiki.api.options.js',
 +              'deprecated' => 'Use "mediawiki.api" instead.',
                'dependencies' => 'mediawiki.api',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.api.parse' => [
 -              'scripts' => 'resources/src/mediawiki.api.parse.js',
 +              'deprecated' => 'Use "mediawiki.api" instead.',
                'dependencies' => 'mediawiki.api',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.api.upload' => [
 -              'scripts' => 'resources/src/mediawiki.api.upload.js',
 -              'dependencies' => [
 -                      'mediawiki.api',
 -                      'mediawiki.api.edit',
 -              ],
 +              'deprecated' => 'Use "mediawiki.api" instead.',
 +              'dependencies' => 'mediawiki.api',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.api.user' => [
 -              'scripts' => 'resources/src/mediawiki.api.user.js',
 -              'dependencies' => [
 -                      'mediawiki.api',
 -              ],
 +              'deprecated' => 'Use "mediawiki.api" instead.',
 +              'dependencies' => 'mediawiki.api',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.api.watch' => [
 -              'scripts' => 'resources/src/mediawiki.api.watch.js',
 -              'dependencies' => [
 -                      'mediawiki.api',
 -              ],
 +              'deprecated' => 'Use "mediawiki.api" instead.',
 +              'dependencies' => 'mediawiki.api',
        ],
        'mediawiki.api.messages' => [
 -              'scripts' => 'resources/src/mediawiki.api.messages.js',
 -              'dependencies' => [
 -                      'mediawiki.api',
 -              ],
 +              'deprecated' => 'Use "mediawiki.api" instead.',
 +              'dependencies' => 'mediawiki.api',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.api.rollback' => [
 -              'scripts' => 'resources/src/mediawiki.api.rollback.js',
 -              'dependencies' => [
 -                      'mediawiki.api',
 -              ],
 +              'deprecated' => 'Use "mediawiki.api" instead.',
 +              'dependencies' => 'mediawiki.api',
        ],
        'mediawiki.content.json' => [
                'styles' => 'resources/src/mediawiki.content.json.less',
        ],
        'mediawiki.debug' => [
                'scripts' => [
 +                      'resources/src/mediawiki.debug/jquery.footHovzer.js',
                        'resources/src/mediawiki.debug/debug.js',
                ],
                'styles' => [
 +                      'resources/src/mediawiki.debug/jquery.footHovzer.css',
                        'resources/src/mediawiki.debug/debug.less',
                ],
                'dependencies' => [
 -                      'jquery.footHovzer',
                        'oojs-ui-core',
                ],
        ],
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
 -      'mediawiki.hidpi' => [
 -              'scripts' => 'resources/src/mediawiki.hidpi/hidpi.js',
 -              'dependencies' => 'jquery.hidpi',
 -              'skipFunction' => 'resources/src/mediawiki.hidpi/skip.js',
 -              'targets' => [ 'desktop', 'mobile' ],
 -      ],
        'mediawiki.hlist' => [
                'targets' => [ 'desktop', 'mobile' ],
                'styles' => [
                        'resources/src/mediawiki.messagePoster.wikitext/WikitextMessagePoster.js',
                ],
                'dependencies' => [
 -                      'mediawiki.api.edit',
 +                      'mediawiki.api',
                        'mediawiki.messagePoster',
                ],
                'targets' => [ 'desktop', 'mobile' ],
        'mediawiki.Upload' => [
                'scripts' => 'resources/src/mediawiki.Upload.js',
                'dependencies' => [
 -                      'mediawiki.api.upload',
 +                      'mediawiki.api',
                ],
        ],
        'mediawiki.ForeignUpload' => [
                        'mediawiki.widgets.CategoryMultiselectWidget',
                        'mediawiki.widgets.DateInputWidget',
                        'mediawiki.jqueryMsg',
 -                      'mediawiki.api.messages',
 +                      'mediawiki.api',
                        'moment',
                        'mediawiki.libs.jpegmeta',
                ],
                'messages' => [ 'showtoc', 'hidetoc' ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
+       'mediawiki.toc.styles' => [
+               'class' => ResourceLoaderLessVarFileModule::class,
+               'lessMessages' => [ 'hidetoc', 'showtoc' ],
+               'styles' => [
+                       'resources/src/mediawiki.toc.styles/common.css',
+                       'resources/src/mediawiki.toc.styles/screen.less'
+                               => [ 'media' => 'screen' ],
+                       'resources/src/mediawiki.toc.styles/print.css'
+                               => [ 'media' => 'print' ],
+               ],
+               'targets' => [ 'desktop', 'mobile' ],
+       ],
        'mediawiki.Uri' => [
                'scripts' => 'resources/src/mediawiki.Uri/Uri.js',
                'templates' => [
                'scripts' => 'resources/src/mediawiki.user.js',
                'dependencies' => [
                        'mediawiki.api',
 -                      'mediawiki.api.user',
                        'mediawiki.storage',
                        'user.options',
                        'user.tokens',
        /* MediaWiki Language */
  
        'mediawiki.language' => [
 +              'class' => ResourceLoaderLanguageDataModule::class,
                'scripts' => [
 +                      'resources/src/mediawiki.language/mediawiki.language.init.js',
                        'resources/src/mediawiki.language/mediawiki.language.js',
                        'resources/src/mediawiki.language/mediawiki.language.numbers.js',
                        'resources/src/mediawiki.language/mediawiki.language.fallback.js',
                        'sl' => 'resources/src/mediawiki.language/languages/sl.js',
                ],
                'dependencies' => [
 -                      'mediawiki.language.data',
                        'mediawiki.cldr',
                ],
 -              'targets' => [ 'desktop', 'mobile' ],
                'messages' => [
                        'and',
                        'comma-separator',
                'targets' => [ 'desktop', 'mobile' ],
        ],
  
 -      'mediawiki.language.init' => [
 -              'scripts' => 'resources/src/mediawiki.language/mediawiki.language.init.js',
 -              'targets' => [ 'desktop', 'mobile' ],
 -      ],
 -
        'mediawiki.jqueryMsg' => [
                // Add data for mediawiki.jqueryMsg, such as allowed tags
                'class' => ResourceLoaderJqueryMsgModule::class,
        ],
  
        'mediawiki.language.months' => [
 +              'targets' => [ 'desktop', 'mobile' ],
                'scripts' => 'resources/src/mediawiki.language/mediawiki.language.months.js',
                'dependencies' => 'mediawiki.language',
                'messages' => array_merge(
                'dependencies' => [
                        'jquery.accessKeyLabel',
                        'jquery.checkboxShiftClick',
 -                      'jquery.mw-jump',
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.page.watch.ajax' => [
                'scripts' => 'resources/src/mediawiki.page.watch.ajax.js',
                'dependencies' => [
 -                      'mediawiki.api.watch',
 +                      'mediawiki.api',
                        'mediawiki.notify',
                        'mediawiki.util',
                        'mediawiki.Title',
        'mediawiki.page.rollback' => [
                'scripts' => 'resources/src/mediawiki.page.rollback.js',
                'dependencies' => [
 -                      'mediawiki.api.rollback',
 +                      'mediawiki.api',
                        'mediawiki.notify',
                        'mediawiki.util',
                        'jquery.spinner',
                        'mediawiki.String',
                        'oojs',
                        'mediawiki.api',
 -                      'mediawiki.api.options',
                        'mediawiki.jqueryMsg',
                        'mediawiki.Uri',
                        'mediawiki.user',
                        'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.SaveFiltersPopupButtonWidget.js',
                        'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FormWrapperWidget.js',
                        'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.FilterItemHighlightButton.js',
 +                      'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.HighlightPopupWidget.js',
                        'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.HighlightColorPickerWidget.js',
                        'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.LiveUpdateButtonWidget.js',
                        'resources/src/mediawiki.rcfilters/ui/mw.rcfilters.ui.MarkSeenButtonWidget.js',
                'messages' => [
                        'rcfilters-tag-remove',
                        'rcfilters-activefilters',
 +                      'rcfilters-activefilters-hide',
 +                      'rcfilters-activefilters-show',
 +                      'rcfilters-activefilters-hide-tooltip',
 +                      'rcfilters-activefilters-show-tooltip',
                        'rcfilters-advancedfilters',
                        'rcfilters-group-results-by-page',
                        'rcfilters-limit-title',
        ],
        'mediawiki.special' => [
                'styles' => [
 -                      'resources/src/mediawiki.special/mediawiki.special.css',
 -                      'resources/src/mediawiki.special/mediawiki.special.userrights.css',
 +                      'resources/src/mediawiki.special/special.css',
 +                      'resources/src/mediawiki.special/apisandbox.css',
 +                      'resources/src/mediawiki.special/comparepages.less',
 +                      'resources/src/mediawiki.special/edittags.css',
 +                      'resources/src/mediawiki.special/movePage.css',
 +                      'resources/src/mediawiki.special/pagesWithProp.css',
 +                      'resources/src/mediawiki.special/upload.css',
 +                      'resources/src/mediawiki.special/userrights.css',
 +                      'resources/src/mediawiki.special/watchlist.css',
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
 -      'mediawiki.special.apisandbox.styles' => [
 -              'targets' => [ 'desktop', 'mobile' ],
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.apisandbox.top.css',
 -      ],
        'mediawiki.special.apisandbox' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.apisandbox.css',
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.apisandbox.js',
 +              'styles' => 'resources/src/mediawiki.special.apisandbox/apisandbox.css',
 +              'scripts' => 'resources/src/mediawiki.special.apisandbox/apisandbox.js',
                'targets' => [ 'desktop', 'mobile' ],
                'dependencies' => [
                        'mediawiki.api',
                        'apisandbox-dynamic-parameters-add-label',
                        'apisandbox-dynamic-parameters-add-placeholder',
                        'apisandbox-dynamic-error-exists',
 +                      'apisandbox-templated-parameter-reason',
                        'apisandbox-deprecated-parameters',
                        'apisandbox-no-parameters',
                        'api-help-param-limit',
                        'apisandbox-multivalue-all-values',
                        'api-format-prettyprint-status',
                        'blanknamespace',
 +                      'comma-separator',
 +                      'word-separator',
 +                      'and'
                ],
        ],
        'mediawiki.special.block' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.block.js',
 +              'scripts' => 'resources/src/mediawiki.special.block.js',
                'dependencies' => [
                        'oojs-ui-core',
                        'oojs-ui.styles.icons-editing-core',
                ],
        ],
        'mediawiki.special.changecredentials.js' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.changecredentials.js',
 +              'scripts' => 'resources/src/mediawiki.special.changecredentials.js',
                'dependencies' => [
                        'mediawiki.api',
                        'mediawiki.htmlform.ooui'
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.special.changeslist' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.changeslist.css',
 +              'styles' => 'resources/src/mediawiki.special.changeslist.css',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.special.changeslist.enhanced' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.changeslist.enhanced.css',
 +              'styles' => 'resources/src/mediawiki.special.changeslist.enhanced.css',
        ],
        'mediawiki.special.changeslist.legend' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.changeslist.legend.css',
 +              'styles' => 'resources/src/mediawiki.special.changeslist.legend.css',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.special.changeslist.legend.js' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.changeslist.legend.js',
 +              'scripts' => 'resources/src/mediawiki.special.changeslist.legend.js',
                'dependencies' => [
                        'jquery.makeCollapsible',
                        'mediawiki.cookie',
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
 -      'mediawiki.special.changeslist.visitedstatus' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.changeslist.visitedstatus.js',
 -      ],
 -      'mediawiki.special.comparepages.styles' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.comparepages.styles.less',
 -      ],
        'mediawiki.special.contributions' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.contributions.js',
 +              'scripts' => 'resources/src/mediawiki.special.contributions.js',
                'dependencies' => [
                        'mediawiki.widgets.DateInputWidget',
                        'mediawiki.jqueryMsg',
                ]
        ],
        'mediawiki.special.edittags' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.edittags.js',
 +              'scripts' => 'resources/src/mediawiki.special.edittags.js',
                'dependencies' => [
                        'jquery.chosen',
                        'jquery.lengthLimit',
                        'tags-edit-chosen-no-results',
                ],
        ],
 -      'mediawiki.special.edittags.styles' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.edittags.css',
 -      ],
        'mediawiki.special.import' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.import.js',
 +              'scripts' => 'resources/src/mediawiki.special.import.js',
        ],
        'mediawiki.special.movePage' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.movePage.js',
 +              'scripts' => 'resources/src/mediawiki.special.movePage.js',
                'dependencies' => [
                        'mediawiki.widgets.visibleLengthLimit',
                        'mediawiki.widgets',
                ],
        ],
 -      'mediawiki.special.movePage.styles' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.movePage.css',
 -      ],
        'mediawiki.special.pageLanguage' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.pageLanguage.js',
 +              'scripts' => 'resources/src/mediawiki.special.pageLanguage.js',
                'dependencies' => [
                        'oojs-ui-core',
                ],
        ],
 -      'mediawiki.special.pagesWithProp' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.pagesWithProp.css',
 -      ],
        'mediawiki.special.preferences' => [
                'targets' => [ 'desktop', 'mobile' ],
                'scripts' => [
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.confirmClose.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.convertmessagebox.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.tabs.legacy.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.timezone.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js',
 +                      'resources/src/mediawiki.special.preferences/confirmClose.js',
 +                      'resources/src/mediawiki.special.preferences/convertmessagebox.js',
 +                      'resources/src/mediawiki.special.preferences/tabs.legacy.js',
 +                      'resources/src/mediawiki.special.preferences/timezone.js',
 +                      'resources/src/mediawiki.special.preferences/personalEmail.js',
                ],
                'messages' => [
                        'prefs-tabs-navigation-hint',
        ],
        'mediawiki.special.preferences.styles' => [
                'targets' => [ 'desktop', 'mobile' ],
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.preferences.styles.legacy.css',
 +              // legacy
 +              'styles' => 'resources/src/mediawiki.special.preferences.styles.css',
        ],
        'mediawiki.special.preferences.ooui' => [
                'targets' => [ 'desktop', 'mobile' ],
                'scripts' => [
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.confirmClose.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.convertmessagebox.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.editfont.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.tabs.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.timezone.js',
 -                      'resources/src/mediawiki.special/mediawiki.special.preferences.personalEmail.js',
 +                      // FIXME: This uses files already belonging to another module
 +                      'resources/src/mediawiki.special.preferences/confirmClose.js',
 +                      'resources/src/mediawiki.special.preferences/convertmessagebox.js',
 +                      'resources/src/mediawiki.special.preferences.ooui/editfont.js',
 +                      'resources/src/mediawiki.special.preferences.ooui/tabs.js',
 +                      'resources/src/mediawiki.special.preferences/timezone.js',
 +                      'resources/src/mediawiki.special.preferences/personalEmail.js',
                ],
                'messages' => [
                        'prefs-tabs-navigation-hint',
        ],
        'mediawiki.special.preferences.styles.ooui' => [
                'targets' => [ 'desktop', 'mobile' ],
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.preferences.styles.css',
 +              'styles' => 'resources/src/mediawiki.special.preferences.styles.ooui.less',
        ],
        'mediawiki.special.recentchanges' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.recentchanges.js',
 +              'scripts' => 'resources/src/mediawiki.special.recentchanges.js',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.special.revisionDelete' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.revisionDelete.js',
 +              'scripts' => 'resources/src/mediawiki.special.revisionDelete.js',
                'messages' => [
                        // @todo Load this message in content language
                        'colon-separator',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.special.search' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.search.js',
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.search.css',
 +              'scripts' => 'resources/src/mediawiki.special.search/search.js',
 +              'styles' => 'resources/src/mediawiki.special.search/search.css',
                'dependencies' => 'mediawiki.widgets.SearchInputWidget',
                'messages' => [
                        'powersearch-togglelabel',
                ],
        ],
        'mediawiki.special.search.commonsInterwikiWidget' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.search.commonsInterwikiWidget.js',
 +              'scripts' => 'resources/src/mediawiki.special.search.commonsInterwikiWidget.js',
                'dependencies' => [
                        'mediawiki.api',
                        'mediawiki.Uri',
                ],
        ],
        'mediawiki.special.search.interwikiwidget.styles' => [
 -              'styles' => 'resources/src/mediawiki.special/'
 -                      . 'mediawiki.special.search.interwikiwidget.styles.less',
 +              'styles' => 'resources/src/mediawiki.special.search.interwikiwidget.styles.less',
                'targets' => [ 'desktop', 'mobile' ]
        ],
        'mediawiki.special.search.styles' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.search.styles.css',
 +              'styles' => 'resources/src/mediawiki.special.search.styles.css',
                'targets' => [ 'desktop', 'mobile' ],
        ],
        'mediawiki.special.undelete' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.undelete.js',
 +              'scripts' => 'resources/src/mediawiki.special.undelete.js',
                'dependencies' => [
                        'mediawiki.widgets.visibleLengthLimit',
                        'mediawiki.widgets',
                ],
        ],
        'mediawiki.special.unwatchedPages' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.unwatchedPages.js',
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.unwatchedPages.css',
 +              'scripts' => 'resources/src/mediawiki.special.unwatchedPages/unwatchedPages.js',
 +              'styles' => 'resources/src/mediawiki.special.unwatchedPages/unwatchedPages.css',
                'messages' => [
                        'addedwatchtext-short',
                        'removedwatchtext-short',
                ],
                'dependencies' => [
                        'mediawiki.api',
 -                      'mediawiki.api.watch',
                        'mediawiki.notify',
                        'mediawiki.Title',
                        'mediawiki.util',
        ],
        'mediawiki.special.upload' => [
                'templates' => [
 -                      'thumbnail.html' => 'resources/src/mediawiki.special/templates/thumbnail.html',
 +                      'thumbnail.html' => 'resources/src/mediawiki.special.upload/templates/thumbnail.html',
                ],
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.upload.js',
 +              'scripts' => 'resources/src/mediawiki.special.upload/upload.js',
                'messages' => [
                        'widthheight',
                        'size-bytes',
                        'prefs-editing',
                ],
                'dependencies' => [
 -                      'mediawiki.special.upload.styles',
 +                      'mediawiki.special',
                        'jquery.spinner',
                        'mediawiki.jqueryMsg',
                        'mediawiki.api',
 -                      'mediawiki.api.parse',
                        'mediawiki.libs.jpegmeta',
                        'mediawiki.Title',
                        'mediawiki.util',
                        'user.options',
                ],
        ],
 -      'mediawiki.special.upload.styles' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.upload.styles.css',
 -      ],
        'mediawiki.special.userlogin.common.styles' => [
                'targets' => [ 'desktop', 'mobile' ],
                'skinStyles' => [
 -                      'default' => 'resources/src/mediawiki.special/mediawiki.special.userlogin.common.css',
 +                      'default' => 'resources/src/mediawiki.special.userlogin.common.styles/userlogin.css',
                ],
        ],
        'mediawiki.special.userlogin.login.styles' => [
                'styles' => [
 -                      'resources/src/mediawiki.special/mediawiki.special.userlogin.login.css',
 +                      'resources/src/mediawiki.special.userlogin.login.styles/login.css',
                ],
        ],
        'mediawiki.special.userlogin.signup.js' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.userlogin.signup.js',
 +              'scripts' => 'resources/src/mediawiki.special.userlogin.signup.js',
                'messages' => [
                        'createacct-emailrequired',
                        'noname',
        ],
        'mediawiki.special.userlogin.signup.styles' => [
                'styles' => [
 -                      'resources/src/mediawiki.special/mediawiki.special.userlogin.signup.css',
 +                      'resources/src/mediawiki.special.userlogin.signup.styles/signup.css',
                ],
        ],
        'mediawiki.special.userrights' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.userrights.js',
 +              'scripts' => 'resources/src/mediawiki.special.userrights.js',
                'dependencies' => [
                        'mediawiki.notification.convertmessagebox',
                        'jquery.lengthLimit',
                ],
        ],
        'mediawiki.special.watchlist' => [
 -              'scripts' => 'resources/src/mediawiki.special/mediawiki.special.watchlist.js',
 +              'scripts' => [
 +                      'resources/src/mediawiki.special.watchlist/watchlist.js',
 +                      'resources/src/mediawiki.special.watchlist/visitedstatus.js',
 +              ],
                'messages' => [
                        'addedwatchtext',
                        'addedwatchtext-talk',
                        'watchlist-unwatch-undo',
                ],
                'dependencies' => [
 -                      'mediawiki.api.watch',
 +                      'mediawiki.api',
                        'mediawiki.jqueryMsg',
                        'mediawiki.Title',
                        'mediawiki.util',
                        'user.options',
                ],
        ],
 -      'mediawiki.special.watchlist.styles' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.watchlist.css',
 -      ],
        'mediawiki.special.version' => [
 -              'styles' => 'resources/src/mediawiki.special/mediawiki.special.version.css',
 +              'styles' => 'resources/src/mediawiki.special.version.css',
        ],
  
        /* MediaWiki Installer */
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
 -      'mediawiki.widgets.visibleByteLimit' => [
 -              'dependencies' => 'mediawiki.widgets.visibleLengthLimit',
 -              'deprecated' => 'Use "mediawiki.widgets.visibleLengthLimit" instead.',
 -              'targets' => [ 'desktop', 'mobile' ]
 -      ],
        'mediawiki.widgets.visibleLengthLimit' => [
                'scripts' => [
                        'resources/src/mediawiki.widgets.visibleLengthLimit/mediawiki.widgets.visibleLengthLimit.js'
        ],
        'mediawiki.widgets.CategoryMultiselectWidget' => [
                'scripts' => [
 -                      'resources/src/mediawiki.widgets/mw.widgets.CategoryCapsuleItemWidget.js',
 +                      'resources/src/mediawiki.widgets/mw.widgets.CategoryTagItemWidget.js',
                        'resources/src/mediawiki.widgets/mw.widgets.CategoryMultiselectWidget.js',
                ],
                'dependencies' => [
                ],
        ],
  
 -      /* es5-shim */
 -      'es5-shim' => [
 -              'deprecated' => 'Use of the "es5-shim" module is deprecated since MediaWiki 1.29.0',
 -              'targets' => [ 'desktop', 'mobile' ],
 -      ],
 -
 -      /* dom-level2-shim */
 -      'dom-level2-shim' => [
 -              'deprecated' => 'Use of the "dom-level2-shim" module is deprecated since MediaWiki 1.29.0',
 -              'targets' => [ 'desktop', 'mobile' ],
 -      ],
 -
        /**
         * html5shiv
         *
        'oojs-ui-widgets' => [
                'class' => ResourceLoaderOOUIFileModule::class,
                'scripts' => 'resources/lib/oojs-ui/oojs-ui-widgets.js',
 -              'themeStyles' => 'widgets',
                'dependencies' => [
                        'oojs-ui-core',
 +                      'oojs-ui-widgets.styles',
                        'oojs-ui.styles.icons-interactions',
                        'oojs-ui.styles.icons-content',
                        'oojs-ui.styles.icons-editing-advanced',
                ],
                'targets' => [ 'desktop', 'mobile' ],
        ],
 +      // You should never directly load this module. The CSS classes it defines are not a public API,
 +      // they depend on the internal structure of OOUI widgets, which can change at any time. If you
 +      // find that you need to load this module, you're probably doing something wrong or very hacky.
 +      'oojs-ui-widgets.styles' => [
 +              'class' => ResourceLoaderOOUIFileModule::class,
 +              'themeStyles' => 'widgets',
 +              'targets' => [ 'desktop', 'mobile' ],
 +      ],
        // Toolbar and tools module.
        'oojs-ui-toolbars' => [
                'class' => ResourceLoaderOOUIFileModule::class,
@@@ -62,12 -62,6 +62,12 @@@ Template:Fo
  FOO
  !!endarticle
  
 +!! article
 +Template:redirect to foo
 +!! text
 +#REDIRECT [[Template:Foo]]
 +!! endarticle
 +
  !! article
  Template:Blank
  !! text
@@@ -115,14 -109,6 +115,14 @@@ Template:ech
  {{{1}}}
  !! endarticle
  
 +!! article
 +Template:echo3
 +!! text
 +{{{1}}}
 +{{{1}}}
 +{{{1}}}
 +!! endarticle
 +
  // For Serbian; localize Template namespace
  !! article
  Шаблон:Echo
@@@ -142,12 -128,6 +142,12 @@@ Template:echo_with_di
  <div>{{{1}}}</div>
  !! endarticle
  
 +!! article
 +Template:echo with depth
 +!! text
 +{{echo|{{{1}}}}}
 +!! endarticle
 +
  !! article
  Template:blank_param
  !! text
@@@ -257,7 -237,7 +257,7 @@@ Weirdo titles
  !!article
  Template:Bullet
  !!text
 -* Bar
 +*Bar
  !!endarticle
  
  !!article
@@@ -327,31 -307,23 +327,31 @@@ This is a simple paragraph
  !! test
  Paragraphs with extra newline spacing
  !! wikitext
 -foo
 +a
  
 -bar
 +b (+2 nls)
  
  
 -baz
 +c (+3 nls)
 +
  
  
 +d (+4 nls)
  
 -booz
 +
 +
 +
 +e (+5 nls)
  !! html
 -<p>foo
 -</p><p>bar
 +<p>a
 +</p><p>b (+2 nls)
  </p><p><br />
 -baz
 +c (+3 nls)
 +</p><p><br />
 +</p><p>d (+4 nls)
  </p><p><br />
 -</p><p>booz
 +</p><p><br />
 +e (+5 nls)
  </p>
  !! end
  
@@@ -523,6 -495,7 +523,6 @@@ Extra newlines followed by headin
  a
  
  
 -
  =b=
  [[a]]
  
  !! end
  
  !! test
 -Extra newlines between heading and content are swallowed
 +Extra newlines between heading and content are swallowed (Parsoid does not)
  !! wikitext
  =b=
  
  
  
  [[a]]
 -!! html
 +!! html/php+tidy
  <h1><span class="mw-headline" id="b">b</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: b">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
  <p><a href="/index.php?title=A&amp;action=edit&amp;redlink=1" class="new" title="A (page does not exist)">a</a>
  </p>
 +!! html/parsoid
 +<h1 id="b">b</h1>
 +<p>
 +<br></p>
 +
 +<p><a rel="mw:WikiLink" href="./A" title="A">a</a></p>
 +!! end
 +
 +!! test
 +Extra new lines before and after lists are preserved
 +!! wikitext
 +a
 +
 +
 +*b
 +
 +
 +c
 +!! html/php+tidy
 +<p>a
 +</p><p><br />
 +</p>
 +<ul><li>b</li></ul>
 +<p><br />
 +c
 +</p>
 +!! html/parsoid
 +<p>a</p>
 +<p>
 +<br></p>
 +<ul><li>b</li></ul>
 +<p>
 +<br>
 +c</p>
  !! end
  
 +# Parsoid regression test
 +!!test
 +Multiple newlines after tables are converted to p-br-p tags
 +!!options
 +parsoid=wt2html,wt2wt
 +!!wikitext
 +{|
 +|x
 +|}
 +
 +
 +
 +
 +=b=
 +!!html/php+tidy
 +<table>
 +<tbody><tr>
 +<td>x
 +</td></tr></tbody></table>
 +<p><br />
 +</p><p><br />
 +</p>
 +<h1><span class="mw-headline" id="b">b</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: b">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
 +!!html/parsoid
 +<table>
 +<tbody>
 +<tr>
 +<td>x</td>
 +</tr>
 +</tbody>
 +</table>
 +<p><br/></p>
 +<p><br/></p>
 +<h1 id="b">b</h1>
 +!!end
 +
  !! test
  Heading with line break in nowiki
  !! options
  </p>
  !! end
  
 +!! test
 +post-expand include size being exceeded
 +!! options
 +maxincludesize=20
 +!! wikitext
 +{{echo3|1234567890}}
 +!! html
 +<p><a href="/wiki/Template:Echo3" title="Template:Echo3">Template:Echo3</a><!-- WARNING: template omitted, post-expand include size too large -->
 +</p>
 +!! end
 +
 +!! test
 +max template depth being reached
 +!! options
 +maxtemplatedepth=1
 +!! wikitext
 +{{echo with depth|too deep!}}
 +!! html
 +<p><span class="error">Template recursion depth limit exceeded (1)</span>
 +</p>
 +!! end
 +
 +!! test
 +multiple templates that are redirects
 +!! wikitext
 +{{redirect to foo}}
 +{{redirect to foo}}
 +!! html
 +<p>FOO
 +FOO
 +</p>
 +!! end
 +
  !! test
  Multiple comments should still parse as SOL-transparent
  !! options
  <link rel="mw:PageProp/Category" href="./Category:Ho" />
  !! end
  
 +!! test
 +Paragraph wrapping following unclosed table
 +!! options
 +parsoid=wt2html,html2html
 +!! wikitext
 +{|
 +|-
 +
 +{|
 +| x
 +|}
 +
 +a
 +
 +b
 +
 +c
 +!! html/php+tidy
 +<table>
 +
 +
 +</table><table>
 +<tbody><tr>
 +<td>x
 +</td></tr></tbody></table>
 +<p>a
 +</p><p>b
 +</p><p>c
 +</p>
 +!! html/parsoid
 +<table data-parsoid='{"autoInsertedEnd":true}'>
 +<tbody><tr class="mw-empty-elt" data-parsoid='{"startTagSrc":"|-"}'></tr>
 +
 +</tbody></table><table>
 +<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td>x</td></tr>
 +</tbody></table>
 +
 +<p>a</p>
 +
 +<p>b</p>
 +
 +<p>c</p>
 +!! end
 +
 +!! test
 +Paragraph wrapping suppressed in html p
 +!! options
 +parsoid=wt2html,html2html
 +!! wikitext
 +<p>
 +
 +
 +hi
 +
 +
 +
 +</p>
 +!! html/php+tidy
 +<p>
 +
 +
 +hi
 +
 +
 +
 +</p>
 +!! html/parsoid
 +<p data-parsoid='{"stx":"html"}'>
 +
 +
 +hi
 +
 +
 +
 +</p>
 +!! end
 +
  ###
  ### Preformatted text
  ###
@@@ -2849,9 -2642,12 +2849,9 @@@ parsoid=wt2htm
  <pre>x</pre>
  &lt;pre <table></table>
  !! html/parsoid
 -<pre about="#mwt1" typeof="mw:Transclusion mw:Extension/pre" data-parsoid='{"a":{"&lt;pre":null},"sa":{"&lt;pre":""},"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;pre &lt;pre>x&lt;/pre>"}},"i":0}}]}'>x</pre>
 -
 +<pre typeof="mw:Transclusion mw:Extension/pre" about="#mwt2" data-parsoid='{"stx":"html","a":{"&lt;pre":null},"sa":{"&lt;pre":""},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;pre &lt;pre>x&lt;/pre>"}},"i":0}}]}'>x</pre>
  
 -<p>&lt;pre </p>
 -
 -<table></table>
 +<span data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>&lt;pre </span><table data-parsoid='{"stx":"html"}'></table>
  !! end
  
  !! test
  
  !! end
  
 +!! test
 +2h. Indent pre in tables
 +!! options
 +parsoid=wt2html,html2html
 +!! wikitext
 +{|
 + !
 + foo
 + !
 + bar
 + |-
 + |
 + baz
 + {{!}}
 + bam
 + |}
 +!! html/php
 +<table>
 +<tr>
 +<th>
 +<pre>foo
 +</pre>
 +</th>
 +<th>
 +<pre>bar
 +</pre>
 +</th></tr>
 +<tr>
 +<td>
 +<pre>baz
 +</pre>
 +</td>
 +<td>
 +<pre>bam
 +</pre>
 +</td></tr></table>
 +
 +!! html/parsoid
 +<table>
 + <tbody><tr><th>
 +<pre>foo</pre>
 +</th><th>
 +<pre>bar</pre>
 +</th></tr><tr>
 + <td>
 +<pre>baz</pre>
 +</td><td data-parsoid='{"startTagSrc":"{{!}}"}'>
 +<pre>bam</pre>
 +</td></tr></tbody></table>
 +!! end
 +
  !!test
  3a. Indent-Pre and block tags (single-line html)
  !! wikitext
  </pre>
  !! end
  
 -!!test
 +!! test
  3b. Indent-Pre and block tags (multi-line html)
  !! wikitext
   a <span>foo</span>
 - b <div> foo </div>
 -!! html
 +<!-- comment --> b <div> foo </div>
 +!! html/php
  <pre>a <span>foo</span>
  </pre>
   b <div> foo </div>
  
  !! html/parsoid
  <pre>a <span data-parsoid='{"stx":"html"}'>foo</span></pre>
 - b <div data-parsoid='{"stx":"html"}'> foo </div>
 +<!-- comment --> <p>b </p><div data-parsoid='{"stx":"html"}'> foo </div>
  !! html/php+tidy
  <pre>a <span>foo</span>
  </pre><p>
   b </p><div> foo </div>
 -!!end
 +!! end
  
  !!test
  3c. Indent-Pre and block tags (pre-content on separate line)
@@@ -4004,7 -3749,7 +4004,7 @@@ Definition list with bracketed URL lin
  !! test
  Definition list with wikilink containing colon
  !! wikitext
 -; [[Help:FAQ]]:The least-read page on Wikipedia
 +;[[Help:FAQ]]:The least-read page on Wikipedia
  !! html
  <dl><dt><a href="/index.php?title=Help:FAQ&amp;action=edit&amp;redlink=1" class="new" title="Help:FAQ (page does not exist)">Help:FAQ</a></dt>
  <dd>The least-read page on Wikipedia</dd></dl>
  !! test
  Definition list with news link containing colon
  !! wikitext
 -;news:alt.wikipedia.roxThis isn't even a real newsgroup!
 +;news:alt.wikipedia.rox :This isn't even a real newsgroup!
  !! html/php
 -<dl><dt><a rel="nofollow" class="external free" href="news:alt.wikipedia.rox">news:alt.wikipedia.rox</a></dt>
 +<dl><dt><a rel="nofollow" class="external free" href="news:alt.wikipedia.rox">news:alt.wikipedia.rox</a>&#160;</dt>
  <dd>This isn't even a real newsgroup!</dd></dl>
  
  !! html/parsoid
 -<dl><dt>  <a rel="mw:ExtLink" class="external free" href="news:alt.wikipedia.rox" data-parsoid='{"stx":"url"}'>news:alt.wikipedia.rox</a></dt><dd data-parsoid='{"stx":"row"}'>This isn't even a real newsgroup!</dd></dl>
 +<dl><dt><a rel="mw:ExtLink" class="external free" href="news:alt.wikipedia.rox" data-parsoid='{"stx":"url"}'>news:alt.wikipedia.rox</a></dt><dd data-parsoid='{"stx":"row"}'>This isn't even a real newsgroup!</dd></dl>
  !! end
  
  !! test
  Malformed definition list with colon
  !! wikitext
 -;  news:alt.wikipedia.rox -- don't crash or enter an infinite loop
 +;news:alt.wikipedia.rox -- don't crash or enter an infinite loop
  !! html
  <dl><dt><a rel="nofollow" class="external free" href="news:alt.wikipedia.rox">news:alt.wikipedia.rox</a> -- don't crash or enter an infinite loop</dt></dl>
  
@@@ -4259,8 -4004,6 +4259,8 @@@ should be left alone</p
  
  !! test
  Definition Lists: Hacky use to indent tables, with comment before table
 +!!options
 +parsoid=wt2html
  !! wikitext
  ::<!-- foo -->{|
  |foo
  !! test
  Definition Lists: Hacky use to indent tables (WS-insensitive)
  !! wikitext
 -: {|
 +:{|
  |a
  |} 
  !! html/php
  </td></tr></table></dd></dl>
  
  !! html/parsoid
 -<dl><dd> <table>
 +<dl><dd><table>
  <tbody><tr><td>a</td></tr>
 -</tbody></table> </dd></dl>
 +</tbody></table></dd></dl>
  !! end
  
  ## The PHP parser treats : items (dd) without a corresponding ; item (dt)
@@@ -5224,7 -4967,7 +5224,7 @@@ URL in text: [http://example.com http:/
  <p>URL in text: <a rel="nofollow" class="external text" href="http://example.com">http://example.com</a>
  </p>
  !! html/parsoid
 -<p>URL in text: <a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a></p>
 +<p>URL in text: <a rel="mw:ExtLink" class="external text" href="http://example.com">http://example.com</a></p>
  !! end
  
  !! test
@@@ -5867,7 -5610,7 +5867,7 @@@ Examples from RFC 2732, section 2
  !! html/parsoid
  <p><a rel="mw:ExtLink" class="external free" href="http://[2404:130:0:1000::187:2]/index.php">http://[2404:130:0:1000::187:2]/index.php</a></p>
  
 -<p>Examples from <a href="https://tools.ietf.org/html/rfc2373" rel="mw:ExtLink" class="external text">RFC 2373</a>, section 2.2:</p>
 +<p>Examples from <a href="https://tools.ietf.org/html/rfc2373" rel="mw:ExtLink" class="external mw-magiclink">RFC 2373</a>, section 2.2:</p>
  <ul><li><a rel="mw:ExtLink" class="external free" href="http://[1080::8:800:200C:417A]/unicast">http://[1080::8:800:200C:417A]/unicast</a></li>
  <li><a rel="mw:ExtLink" class="external free" href="http://[FF01::101]/multicast">http://[FF01::101]/multicast</a></li>
  <li><a rel="mw:ExtLink" class="external free" href="http://[::1]/loopback">http://[::1]/loopback</a></li>
  <li><a rel="mw:ExtLink" class="external free" href="http://[::13.1.68.3]/ipv4compat">http://[::13.1.68.3]/ipv4compat</a></li>
  <li><a rel="mw:ExtLink" class="external free" href="http://[::FFFF:129.144.52.38]/ipv4compat">http://[::FFFF:129.144.52.38]/ipv4compat</a></li></ul>
  
 -<p>Examples from <a href="https://tools.ietf.org/html/rfc2732" rel="mw:ExtLink" class="external text">RFC 2732</a>, section 2:</p>
 +<p>Examples from <a href="https://tools.ietf.org/html/rfc2732" rel="mw:ExtLink" class="external mw-magiclink">RFC 2732</a>, section 2:</p>
  <ul><li><a rel="mw:ExtLink" class="external free" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html">http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html</a></li>
  <li><a rel="mw:ExtLink" class="external free" href="http://[1080:0:0:0:8:800:200C:417A]/index.html">http://[1080:0:0:0:8:800:200C:417A]/index.html</a></li>
  <li><a rel="mw:ExtLink" class="external free" href="http://[3ffe:2a00:100:7031::1]">http://[3ffe:2a00:100:7031::1]</a></li>
@@@ -5931,7 -5674,7 +5931,7 @@@ Examples from RFC 2732, section 2
  !! html/parsoid
  <p><a rel="mw:ExtLink" class="external text" href="http://[2404:130:0:1000::187:2]/index.php">test</a></p>
  
 -<p>Examples from <a href="https://tools.ietf.org/html/rfc2373" rel="mw:ExtLink" class="external text">RFC 2373</a>, section 2.2:</p>
 +<p>Examples from <a href="https://tools.ietf.org/html/rfc2373" rel="mw:ExtLink" class="external mw-magiclink">RFC 2373</a>, section 2.2:</p>
  <ul><li><a rel="mw:ExtLink" class="external text" href="http://[1080::8:800:200C:417A]">unicast</a></li>
  <li><a rel="mw:ExtLink" class="external text" href="http://[FF01::101]">multicast</a></li>
  <li><a rel="mw:ExtLink" class="external text" href="http://[::1]/">loopback</a></li>
  <li><a rel="mw:ExtLink" class="external text" href="http://[::13.1.68.3]">ipv4compat</a></li>
  <li><a rel="mw:ExtLink" class="external text" href="http://[::FFFF:129.144.52.38]">ipv4compat</a></li></ul>
  
 -<p>Examples from <a href="https://tools.ietf.org/html/rfc2732" rel="mw:ExtLink" class="external text">RFC 2732</a>, section 2:</p>
 +<p>Examples from <a href="https://tools.ietf.org/html/rfc2732" rel="mw:ExtLink" class="external mw-magiclink">RFC 2732</a>, section 2:</p>
  <ul><li><a rel="mw:ExtLink" class="external text" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html">1</a></li>
  <li><a rel="mw:ExtLink" class="external text" href="http://[1080:0:0:0:8:800:200C:417A]/index.html">2</a></li>
  <li><a rel="mw:ExtLink" class="external text" href="http://[3ffe:2a00:100:7031::1]">3</a></li>
@@@ -6289,7 -6032,7 +6289,7 @@@ A table with nothing but a captio
  A table with caption with default-spaced attributes and a table row
  !! wikitext
  {|
 -|+ style="color: red;" | caption1
 +|+ style="color: red;" |caption1
  |-
  |foo
  |}
@@@ -6573,8 -6316,8 +6573,8 @@@ Accept "!!" in table data of mixed wiki
  Accept empty attributes in td/th cells (td/th cells starting with leading ||)
  !! wikitext
  {|
 -!| h1
 -|| a
 +!|h1
 +||a
  |}
  !! html
  <table>
@@@ -6719,9 -6462,9 +6719,9 @@@ Invalid attributes in table cell (T3830
  Table cell attributes: Pipes protected by nowikis should be treated as a plain character
  !! wikitext
  {|
 -| title="foo" |bar
 -| title="foo<nowiki>|</nowiki>" |bar
 -| title="foo<nowiki>|</nowiki>" bar
 +|title="foo" |bar
 +|title="foo<nowiki>|</nowiki>" |bar
 +|title="foo<nowiki>|</nowiki>" bar
  |}
  !! html/php
  <table>
@@@ -6793,7 -6536,7 +6793,7 @@@ Element attributes with double ! shoul
  !! html/php
  <table>
  <tr>
 -<td><div style="color: red !important;" data-contrived="put this here &#124;&#124;">hi</div>
 +<td><div style="color: red&#32;!important;" data-contrived="put this here &#124;&#124;">hi</div>
  </td></tr></table>
  
  !! html/parsoid
@@@ -6814,7 -6557,7 +6814,7 @@@ parsoid=wt2htm
  !! html/php
  <table>
  <tr>
 -<td>style="color: red !important;" data-contrived="put this here</td>
 +<td>style="color: red&#160;!important;" data-contrived="put this here</td>
  <td>foo
  </td></tr></table>
  
@@@ -6903,8 -6646,8 +6903,8 @@@ parsoid=
  |}
  !! wikitext/edited
  {| <span>boo</span> style='border:1px solid black'
 -|  <span>boo</span> style='color:blue'  |abc
 -|<span>boo</span> style='color:blue'|xyz
 +|  <span>boo</span> style='color:blue'  | abc
 +|<span>boo</span> style='color:blue'| xyz
  |}
  !! end
  
  Table cell with a single comment
  !! wikitext
  {|
 -| <!-- c1 -->
 +|<!-- c1 -->
  |a
  |}
  !! html
  a
  <table></table>
  !! html/parsoid
 -<p data-parsoid='{"fostered":true,"autoInsertedEnd":true}'>a</p><table>
 -<tbody><tr data-parsoid='{"startTagSrc":"|-","autoInsertedEnd":true}'>
 -
 -</tr></tbody></table>
 +<span data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>
 +a
 +</span><table>
 +<tbody><tr class="mw-empty-elt" data-parsoid='{"startTagSrc":"|-"}'></tr></tbody></table>
  !! end
  
  !! test
@@@ -7415,6 -7158,18 +7415,6 @@@ parsoid=html2w
  '''quux'''
  !! end
  
 -!! test
 -Parsoid: newline inducing block nodes don't suppress <nowiki>
 -!! options
 -parsoid=html2wt
 -!! html/parsoid
 - a<h1>foo</h1>
 -!! wikitext
 -<nowiki> </nowiki>a
 -
 -= foo =
 -!! end
 -
  !! test
  Parsoid: Row-syntax table headings followed by comment & table cells
  !! options
@@@ -7436,8 -7191,8 +7436,8 @@@ parsoid=wt2html,wt2w
  
  !! html/parsoid
  <table>
 -<tbody><tr><th> foo </th><th> bar
 -<!-- foo -->  </th><td> baz </td><td> quux</td></tr>
 +<tbody><tr><th>foo</th><th>bar
 +<!-- foo --></th><td> baz </td><td>quux</td></tr>
  </tbody></table>
  !! end
  
@@@ -7482,29 -7237,13 +7482,29 @@@ parsoid=wt2htm
  </tbody></table>
  !! end
  
 -# T137406: Whitespace in the HTML
  !! test
 -1. Generate correct wikitext for tables with thead/tbody/tfoot
 +Table with missing opening <tr> tag
  !! options
 -parsoid=html2wt
 -!! html/parsoid
 -<table>
 +parsoid=wt2html,wt2wt
 +!! wikitext
 +<table>
 +<td>foo</td>
 +</tr>
 +</table>
 +!! html+tidy
 +<table>
 +<tbody><tr><td>foo</td>
 +</tr>
 +</tbody></table>
 +!! end
 +
 +# T137406: Whitespace in the HTML
 +!! test
 +1. Generate correct wikitext for tables with thead/tbody/tfoot
 +!! options
 +parsoid=html2wt
 +!! html/parsoid
 +<table>
  <caption>Test</caption>
  <thead>
  <tr>
@@@ -7585,6 -7324,97 +7585,6 @@@ parsoid=html2w
  |}
  !! end
  
 -!! test
 -Testing serialization after deletion in references
 -!! options
 -parsoid={
 -  "modes": ["wt2wt"],
 -  "changes": [
 -    ["#x", "remove"]
 -  ]
 -}
 -!! wikitext
 -hi <ref><div id="x">ho</div></ref>
 -
 -<references />
 -!! wikitext/edited
 -hi <ref></ref>
 -
 -<references />
 -!! end
 -
 -!!test
 -Testing serialization after deletion of table cells
 -!!options
 -parsoid={
 -  "modes": ["wt2wt", "selser"],
 -  "changes": [
 -    ["#x", "remove"]
 -  ]
 -}
 -!!wikitext
 -{|
 -!h1 !!h2 !!h3
 -| id="x" |c1 {{!}}{{!}}{{!}}c2 |||c3
 -|}
 -!! wikitext/edited
 -{|
 -!h1 !!h2 !!h3
 -|c2 |||c3
 -|}
 -!!end
 -
 -!! test
 -Testing selser after addition of new row before first row (T125419)
 -!! options
 -parsoid={
 -  "modes": ["wt2wt", "selser"],
 -  "changes": [
 -    [ "tr", "before", "<tr><td>X</td></tr>" ]
 -  ]
 -}
 -!! wikitext
 -{|
 -|a
 -|}
 -!! wikitext/edited
 -{|
 -|X
 -|-
 -|a
 -|}
 -!! end
 -
 -!! test
 -Serialize new table rows in a HTML table using HTML tags
 -!! options
 -parsoid={
 -  "modes": ["wt2wt", "selser"],
 -  "changes": [
 -    [ "tr", "before", "<tr><td>X</td></tr>" ]
 -  ]
 -}
 -!! wikitext
 -<table><tr><td>a</td></tr></table>
 -!! wikitext/edited
 -<table><tr><td>X</td></tr><tr><td>a</td></tr></table>
 -!! end
 -
 -!! test
 -Serialize new table cells in a HTML row using HTML tags
 -!! options
 -parsoid={
 -  "modes": ["wt2wt", "selser"],
 -  "changes": [
 -    [ "td", "before", "<td>X</td>" ]
 -  ]
 -}
 -!! wikitext
 -<table><tr><td>a</td></tr></table>
 -!! wikitext/edited
 -<table><tr><td>X</td><td>a</td></tr></table>
 -!! end
 -
  !! test
  Wikitext tables can be nested inside HTML tables
  !! options
@@@ -7607,6 -7437,56 +7607,6 @@@ parsoid=html2w
  </table>
  !! end
  
 -!! test
 -Serialize wikitext list items as HTML list items when embedded in a HTML list
 -!! options
 -parsoid=html2wt
 -!! html
 -<ul data-parsoid='{"stx": "html"}'>
 -<li data-parsoid='{}'>a</li>
 -<li>b</li>
 -</ul>
 -!! wikitext
 -<ul>
 -<li>a</li>
 -<li>b</li>
 -</ul>
 -!! end
 -
 -# SSS FIXME: Is this actually a good thing given the
 -# odd nested list output that is generated by MW?
 -# <ul><li>foo<ul>..</ul></li></ul> instead of
 -# <ul><li>foo</li><ul>..</ul></ul>
 -!! test
 -Wikitext lists can be nested inside HTML lists
 -!! options
 -parsoid=html2wt
 -!! html
 -<ul data-parsoid='{"stx": "html"}'>
 -<li data-parsoid='{"stx": "html"}'>a
 -<ul><li>b</li></ul>
 -</li>
 -</ul>
 -
 -<ul data-parsoid='{"stx": "html"}'>
 -<li>x
 -<ul><li>y</li></ul>
 -</li>
 -</ul>
 -!! wikitext
 -<ul>
 -<li>a
 -* b
 -</li>
 -</ul>
 -
 -<ul>
 -<li>x
 -* y
 -</li>
 -</ul>
 -!! end
 -
  ###
  ### Internal links
  ###
@@@ -9117,14 -8997,6 +9117,14 @@@ parsoid=wt2html,wt2w
  <p><a rel="mw:WikiLink" href="./Constructor:foo" title="Constructor:foo" data-parsoid='{"stx":"simple","a":{"href":"./Constructor:foo"},"sa":{"href":"constructor:foo"}}'>constructor:foo</a></p>
  !! end
  
 +!! test
 +Template parameter named "constructor"
 +!! wikitext
 +{{echo|  constructor =  |hi}}
 +!! html/parsoid
 +<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"constructor","named":true,"spc":["  "," ","","  "]},{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi"},"constructor":{"wt":""}},"i":0}}]}'>hi</p>
 +!! end
 +
  !! article
  ko:
  !! text
@@@ -9845,16 -9717,6 +9845,16 @@@ parsoi
  
  !! end
  
 +!! test
 +Nested lists 10 (list and span siblings: wt2wt regression)
 +!! wikitext
 +*a <span>x</span>
 +**b <span>y</span>
 +!! html/parsoid
 +<ul><li>a <span>x</span>
 +<ul><li>b <span>y</span></li></ul></li></ul>
 +!! end
 +
  !! test
  2. Lists with start-of-line-transparent tokens before bullets: Template close
  !! wikitext
@@@ -10058,7 -9920,7 +10058,7 @@@ parsoi
  !! test
  Parsoid: Test of whitespace serialization with Templated bullets
  !! options
 -parsoid
 +parsoid=wt2html
  !! wikitext
  * {{bullet}}
  !! html/parsoid
@@@ -10178,6 -10040,22 +10178,6 @@@ parsoid=wt2html,wt2wt,html2htm
  </ul>
  !!end
  
 -!! test
 -Table with missing opening <tr> tag
 -!! options
 -parsoid=wt2html,wt2wt
 -!! wikitext
 -<table>
 -<td>foo</td>
 -</tr>
 -</table>
 -!! html+tidy
 -<table>
 -<tbody><tr><td>foo</td>
 -</tr>
 -</tbody></table>
 -!! end
 -
  ###
  ### Magic Words
  ###
@@@ -11031,7 -10909,7 +11031,7 @@@ RFC 82
  <p><a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc822">RFC 822</a>
  </p>
  !! html/parsoid
 -<p><a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external text">RFC 822</a></p>
 +<p><a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external mw-magiclink">RFC 822</a></p>
  !! end
  
  !! test
@@@ -11042,7 -10920,7 +11042,7 @@@ This is RFC 822 but thisRFC 822 is not 
  <p>This is <a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc822">RFC 822</a> but thisRFC 822 is not RFC 822linked.
  </p>
  !! html/parsoid
 -<p>This is <a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external text">RFC 822</a> but thisRFC 822 is not RFC 822linked.</p>
 +<p>This is <a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external mw-magiclink">RFC 822</a> but thisRFC 822 is not RFC 822linked.</p>
  !! end
  
  !! test
  822
  </p>
  !! html/parsoid
 -<p><a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external text">RFC <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 822</a>
 +<p><a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external mw-magiclink">RFC <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 822</a>
  RFC
  822</p>
  !! end
@@@ -11115,7 -10993,7 +11115,7 @@@ PMID 123
  <p><a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a>
  </p>
  !! html/parsoid
 -<p><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external text">PMID 1234</a></p>
 +<p><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external mw-magiclink">PMID 1234</a></p>
  !! end
  
  !! test
@@@ -11126,7 -11004,7 +11126,7 @@@ This is PMID 1234 but thisPMID 1234 is 
  <p>This is <a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a> but thisPMID 1234 is not PMID 1234linked.
  </p>
  !! html/parsoid
 -<p>This is <a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external text">PMID 1234</a> but thisPMID 1234 is not PMID 1234linked.</p>
 +<p>This is <a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external mw-magiclink">PMID 1234</a> but thisPMID 1234 is not PMID 1234linked.</p>
  !! end
  
  !! test
  1234
  </p>
  !! html/parsoid
 -<p><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external text">PMID <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 1234</a>
 +<p><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external mw-magiclink">PMID <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 1234</a>
  PMID
  1234</p>
  !! end
@@@ -11626,17 -11504,6 +11626,17 @@@ Template from main namespac
  </p>
  !! end
  
 +!! test
 +Template from non-includable namespace
 +!! options
 +wgNonincludableNamespaces=10
 +!! wikitext
 +{{echo|uh oh!}}
 +!! html
 +<p><a href="/wiki/Template:Echo" title="Template:Echo">Template:Echo</a>
 +</p>
 +!! end
 +
  !! article
  Template:table
  !! text
@@@ -12863,22 -12730,16 +12863,22 @@@ Templates: Block Tags: 2. Back-to-back 
  
  !!end
  
 -# This is an edge case relating to paragraph wrapping.
 -!!test
 +## This is an edge case relating to paragraph wrapping.
 +## Note that Parsoid fails to match Remex because it's using the closing tag
 +## as a heuristic to determine if it's in a block, rather than SAX based events.
 +!! test
  Templates: Correctly encapsulate templates producing </p> tag without a corresponding <p> tag
  !! wikitext
  {{echo|a
  b</p>}}
 +!! html/php+tidy
 +<p>a
 +</p><p>
 +b</p><p class="mw-empty-elt"></p>
  !! html/parsoid
 -<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\nb&lt;/p>"}},"i":0}}]}'>a
 -b</p>
 -!!end
 +<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\nb&lt;/p>"}},"i":0}}]}'>a</p><span about="#mwt1">
 +</span><span about="#mwt1">b</span><p about="#mwt1" data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p>
 +!! end
  
  !!test
  Templates: Links: 1. Simple example
@@@ -13059,24 -12920,6 +13059,24 @@@ Templates: Support for templates genera
  </tbody></table>
  !!end
  
 +!! article
 +Template:attribute_from_template
 +!! text
 +class="123"
 +!! endarticle
 +
 +!! test
 +Table cell with attribute before expanded attribute
 +!! wikitext
 +{|
 +| align="center" {{attribute_from_template}} |456
 +|}
 +!! html/parsoid
 +<table>
 +<tbody><tr><td align="center" class="123" about="#mwt2" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"class","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[]],\"dsr\":[20,47,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"attribute_from_template\",\"href\":\"./Template:Attribute_from_template\"},\"params\":{},\"i\":0}}]}&apos;>class=\"123\"&lt;/span>"},{"html":""}]]}'>456</td></tr>
 +</tbody></table>
 +!! end
 +
  !! test
  1. Entities and nowikis inside templated attributes should be handled correctly
  !! wikitext
@@@ -13247,13 -13090,13 +13247,13 @@@ parsoid=wt2html,wt2w
  <link rel="mw:PageProp/Category" href="./Category:Bar1"><link rel="mw:PageProp/Category" href="./Category:Bar2"><table><tbody><tr><td>foo</td></tr></tbody></table>
  !!end
  
 -!!test
 +!! test
  Templates: Wiki Tables: 1a. Fostering of entire template content
  !! wikitext
  {|
  {{echo|a}}
  |}
 -!! html
 +!! html/php
  <table>
  a
  <tr><td></td></tr></table>
  a
  <table><tbody><tr><td></td></tr></tbody></table>
  !! html/parsoid
 -<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a"}},"i":0}},"\n|}"]}'>a</p><table about="#mwt2">
 +<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a"}},"i":0}},"\n|}"]}'>a</span><table about="#mwt2">
  
  </table>
  !! end
  </table>
  !! end
  
 -!!test
 +!! test
  Templates: Wiki Tables: 2. Fostering of partial template content
  !! wikitext
  {|
  {{echo|a
  <div>b</div>}}
  |}
 -!! html
 +!! html/php
  <table>
  a
  <div>b</div>
  <div>b</div><table>
  <tbody><tr><td></td></tr></tbody></table>
  !! html/parsoid
 -<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n&lt;div>b&lt;/div>"}},"i":0}},"\n|}"]}'>a</p><div about="#mwt2">b</div><table about="#mwt2">
 +<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n&lt;div>b&lt;/div>"}},"i":0}},"\n|}"]}'>a</span><div about="#mwt2">b</div><table about="#mwt2">
  
  
  </table>
@@@ -13564,19 -13407,6 +13564,19 @@@ Parser Functions: 2. Nested use (only o
  </p>
  !!end
  
 +## Note that the templates inside the references are not wrapped
 +!! test
 +Template nested in extension tag in template
 +!! wikitext
 +{{echo|hi<ref>[[ho|{{echo|hi}}]]</ref>}}
 +{{echo|hi<ref>[http://test.com?q={{echo|ho}}]</ref>}}
 +<references />
 +!! html/parsoid
 +<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;ref>[[ho|{{echo|hi}}]]&lt;/ref>"}},"i":0}}]}'>hi</span><sup about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="./Main_Page#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup>
 +<span about="#mwt7" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;ref>[http://test.com?q={{echo|ho}}]&lt;/ref>"}},"i":0}}]}'>hi</span><sup about="#mwt7" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{}}'><a href="./Main_Page#cite_note-2" style="counter-reset: mw-Ref 2;"><span class="mw-reflink-text">[2]</span></a></sup></p>
 +<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt10" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"><a rel="mw:WikiLink" href="./Ho" title="Ho" data-parsoid='{"stx":"piped","a":{"href":"./Ho"},"sa":{"href":"ho"}}'>hi</a></span></li><li about="#cite_note-2" id="cite_note-2"><a href="./Main_Page#cite_ref-2" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-2" class="mw-reference-text"><a typeof="mw:ExpandedAttrs" about="#mwt11" rel="mw:ExtLink" class="external autonumber" href="http://test.com?q=ho" data-mw='{"attribs":[[{"txt":"href"},{"html":"http://test.com?q=ho"}]]}'></a></span></li></ol>
 +!! end
 +
  ###
  ### Pre-save transform tests
  ###
@@@ -14922,25 -14752,6 +14922,25 @@@ Image with nested tables in captio
  </figcaption></figure>
  !! end
  
 +!! test
 +Image with heading and horizontal rule in caption
 +!! wikitext
 +[[File:Foobar.jpg|thumb|
 +===Testing===
 +123
 +--------------
 +]]
 +!! html/php
 +<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><h3><span class="mw-headline" id="Testing">Testing</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Testing">edit</a><span class="mw-editsection-bracket">]</span></span></h3> 123 <hr /></div></div></div>
 +
 +!! html/parsoid
 +<figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"caption","ak":"\n=== Testing ===\n123\n--------------\n"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{"href":"File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>
 +<h3 id="Testing">Testing</h3>
 +123
 +<hr data-parsoid='{"extra_dashes":10}'/>
 +</figcaption></figure>
 +!! end
 +
  ###################
  # Conflicting image format options.
  # First option specified should 'win'.
@@@ -15252,7 -15063,7 +15252,7 @@@ T3887: A RFC with a thumbnai
  <div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This is <a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc12354">RFC 12354</a></div></div></div>
  
  !! html/parsoid
 -<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>This is <a href="https://tools.ietf.org/html/rfc12354" rel="mw:ExtLink" class="external text">RFC 12354</a></figcaption></figure>
 +<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>This is <a href="https://tools.ietf.org/html/rfc12354" rel="mw:ExtLink" class="external mw-magiclink">RFC 12354</a></figcaption></figure>
  !! end
  
  !! test
@@@ -15589,7 -15400,8 +15589,7 @@@ Parsoid-specific image handling - simpl
  !! end
  
  !! test
 -Parsoid-specific image handling - simple image with size, middle alignment,
 -non-standard namespace alias
 +Parsoid-specific image handling - simple image with size, middle alignment, non-standard namespace alias
  !! options
  parsoid=wt2wt,wt2html,html2html
  !! wikitext
  !! end
  
  !! test
 -Parsoid-specific image handling - simple image with size and middle alignment
 -(existing content)
 +Parsoid-specific image handling - simple image with size and middle alignment (existing content)
  !! wikitext
  [[File:Foobar.jpg|50px|middle]]
  !! html/parsoid
  !! end
  
  !! test
 -Parsoid-specific image handling - simple image with size and middle alignment
 -and non-standard namespace name
 +Parsoid-specific image handling - simple image with size and middle alignment and non-standard namespace name
  !! options
  parsoid=wt2html,wt2wt,html2html
  !! wikitext
@@@ -15634,46 -15448,41 +15634,46 @@@ Parsoid-specific image handling - simpl
  
  !! test
  Parsoid-specific image handling - thumbnail with halign, valign, and caption
 +!! options
 +parsoid=wt2html,html2html
  !! wikitext
  [[File:Foobar.jpg|left|baseline|thumb|caption content]]
  !! html/parsoid
 -<figure class="mw-default-size mw-halign-left mw-valign-baseline" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption content</figcaption></figure>
 +<figure class="mw-default-size mw-halign-left" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption content</figcaption></figure>
  !! end
  
  !! test
 -Parsoid-specific image handling - thumbnail with halign, valign, and caption
 -(existing content)
 +Parsoid-specific image handling - thumbnail with halign, valign, and caption (existing content)
 +!! options
 +parsoid=wt2html,html2html
  !! wikitext
  [[File:Foobar.jpg|thumb|left|baseline|caption content]]
  !! html/parsoid
 -<figure class="mw-default-size mw-halign-left mw-valign-baseline" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"left","ak":"left"},{"ck":"baseline","ak":"baseline"},{"ck":"caption","ak":"caption content"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>caption content</figcaption></figure>
 +<figure class="mw-default-size mw-halign-left" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"left","ak":"left"},{"ck":"baseline","ak":"baseline"},{"ck":"caption","ak":"caption content"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>caption content</figcaption></figure>
  !! end
  
  !! test
  Parsoid-specific image handling - thumbnail with specific size, halign, valign, and caption
 +!! options
 +parsoid=wt2html,html2html
  !! wikitext
  [[Image:Foobar.jpg|right|middle|thumb|50x50px|caption]]
  !! html/parsoid
 -<figure class="mw-halign-right mw-valign-middle" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a><figcaption>caption</figcaption></figure>
 +<figure class="mw-halign-right" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a><figcaption>caption</figcaption></figure>
  !! end
  
  !! test
 -Parsoid-specific image handling - thumbnail with specific size, halign,
 -valign, and caption (existing content)
 +Parsoid-specific image handling - thumbnail with specific size, halign, valign, and caption (existing content)
 +!! options
 +parsoid=wt2html,html2html
  !! wikitext
  [[File:Foobar.jpg|thumb|50x50px|right|middle|caption]]
  !! html/parsoid
 -<figure class="mw-halign-right mw-valign-middle" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"width","ak":"50x50px"},{"ck":"right","ak":"right"},{"ck":"middle","ak":"middle"},{"ck":"caption","ak":"caption"}],"size":"50x50"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"6","width":"50"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>caption</figcaption></figure>
 +<figure class="mw-halign-right" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"width","ak":"50x50px"},{"ck":"right","ak":"right"},{"ck":"middle","ak":"middle"},{"ck":"caption","ak":"caption"}],"size":"50x50"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"6","width":"50"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>caption</figcaption></figure>
  !! end
  
  !! test
 -Parsoid-specific image handling - framed image with specific size and caption
 -(size is ignored)
 +Parsoid-specific image handling - framed image with specific size and caption (size is ignored)
  !! options
  parsoid=wt2html,wt2wt,html2html
  !! wikitext
  !! end
  
  !! test
 -Parsoid-specific image handling - framed image with specific size, halign, valign, and caption
 -(size is ignored)
 +Parsoid-specific image handling - framed image with specific size, halign, valign, and caption (size is ignored)
  !! options
 -parsoid=wt2html,wt2wt,html2html
 +parsoid=wt2html,html2html
  !! wikitext
  [[File:Foobar.jpg|left|baseline|frame|500x50px|caption]]
  !! html/parsoid
 -<figure class="mw-halign-left mw-valign-baseline" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>caption</figcaption></figure>
 +<figure class="mw-halign-left" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>caption</figcaption></figure>
  !! end
  
  !! test
@@@ -16232,49 -16042,33 +16232,49 @@@ parsoid=wt2htm
  !! test
  3. Categories and newlines: newline suppression for last list item should RT properly
  !! wikitext
 -* a
 -* b 
 +*a
 +*b
     
  [[Category:Foo]]
     
  [[Category:Bar]]
  [[Category:Baz]]
 +
 +:c
 +
 +[[Category:C]]
 +
 +;d
 +
 +[[Category:D]]
  !! html/parsoid
 -<ul><li> a</li>
 -<li> b</li></ul> 
 +<ul><li>a</li>
 +<li>b</li></ul>
     
 -<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/>
 +<link rel="mw:PageProp/Category" href="./Category:Foo"/>
     
 -<link rel="mw:PageProp/Category" href="./Category:Bar" data-parsoid='{"stx":"simple","a":{"href":"./Category:Bar"},"sa":{"href":"Category:Bar"}}'/>
 -<link rel="mw:PageProp/Category" href="./Category:Baz" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:Baz"}}'/>
 +<link rel="mw:PageProp/Category" href="./Category:Bar"/>
 +<link rel="mw:PageProp/Category" href="./Category:Baz"/>
 +
 +<dl><dd>c</dd></dl>
 +
 +<link rel="mw:PageProp/Category" href="./Category:C"/>
 +
 +<dl><dt>d</dt></dl>
 +
 +<link rel="mw:PageProp/Category" href="./Category:D"/>
  !! end
  
  !! test
  4. Categories and newlines: newline suppression for last list item should RT properly
  !! wikitext
 -* a
 -**** b
 +*a
 +****b
  
  [[Category:Foo]]
  !! html/parsoid
 -<ul><li> a
 -<ul><li><ul><li><ul><li> b</li></ul></li></ul></li></ul></li></ul>
 +<ul><li>a
 +<ul><li><ul><li><ul><li>b</li></ul></li></ul></li></ul></li></ul>
  
  <link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/>
  !! end
  !! options
  parsoid=wt2html
  !! wikitext
 -* a
 -** b
 +*a
 +**b
  [[Category:Foo]]
 -* c
 -** d
 +*c
 +**d
  [[Category:Foo]]
  !! html/parsoid
 -<ul><li> a
 -<ul><li> b
 +<ul><li>a
 +<ul><li>b
  <link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul></li>
 -<li> c
 -<ul><li> d</li></ul></li></ul>
 +<li>c
 +<ul><li>d</li></ul></li></ul>
  <link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/>
  !! end
  
  !! options
  parsoid=wt2html
  !! wikitext
 -* a [[Category:Foo]]
 +*a [[Category:Foo]]
  !! html/parsoid
 -<ul><li>a <link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul>
 +<ul><li>a<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul>
  !! end
  
  # This test also demonstrates because of newline+category tunneling
  !! test
  7. Categories and newlines: migrateTrailingCategories dom pass should leave template content alone
  !! wikitext
 -* {{echo|a
 +*{{echo|a
  [[Category:Foo]]}}
  !! html/parsoid
 -<ul><li> <span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n[[Category:Foo]]"}},"i":0}}]}'>a
 +<ul><li><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n[[Category:Foo]]"}},"i":0}}]}'>a
  </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul>
  !! end
  
  !! test
  8. Categories and newlines: migrateTrailingCategories dom pass should not get tripped by intervening templates
  !! wikitext
 -* a
 +*a
  
  {{echo|[[Category:Foo]]
  [[Category:Bar]]}}
  [[Category:Baz]]
  !! html/parsoid
 -<ul><li> a</li></ul>
 +<ul><li>a</li></ul>
  
  <link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Category:Foo]]\n[[Category:Bar]]"}},"i":0}}]}'/><span about="#mwt1">
  </span><link rel="mw:PageProp/Category" href="./Category:Bar" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Bar"},"sa":{"href":"Category:Bar"}}'/>
  !! end
  
  !! test
 -9. Categories and newlines: should behave properly with linkprefix (T87753)
 +Categories and newlines: migrateTrailingCategories dom pass should not get tripped by comments and whitespace
 +!! wikitext
 +*a
 +
 +[[Category:Bar]]<!--boo1--> <!--boo2-->
 +[[Category:Baz]]<!--boo3--> <!--boo4-->
 +!! html/parsoid
 +<ul><li>a</li></ul>
 +
 +<link rel="mw:PageProp/Category" href="./Category:Bar"/><!--boo1--> <!--boo2-->
 +<link rel="mw:PageProp/Category" href="./Category:Baz"/><!--boo3--> <!--boo4-->
 +!! end
 +
 +!! test
 +Categories and newlines: should behave properly with linkprefix (T87753)
  !! options
  language=ar
  !! wikitext
@@@ -16378,7 -16158,7 +16378,7 @@@ foo bar</p
  !! end
  
  !! test
 -10. No regressions on internal links following category (T174639)
 +No regressions on internal links following category (T174639)
  !! options
  parsoid=wt2html,html2html
  !! wikitext
@@@ -16610,7 -16390,7 +16610,7 @@@ Section headings with TO
  Some text
  ===Another headline===
  !! html
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Headline_1"><span class="tocnumber">1</span> <span class="toctext">Headline 1</span></a>
  <ul>
@@@ -16653,7 -16433,7 +16653,7 @@@ __FORCETOC_
  ==Headline 2==
  ==Headline==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Headline_2"><span class="tocnumber">1</span> <span class="toctext">Headline 2</span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#Headline"><span class="tocnumber">2</span> <span class="toctext">Headline</span></a></li>
@@@ -16687,7 -16467,7 +16687,7 @@@ parsoid=wt2htm
  =========Level 9 Heading=========
  ==========Level 10 Heading==========
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Level_1_Heading"><span class="tocnumber">1</span> <span class="toctext">Level 1 Heading</span></a>
  <ul>
@@@ -16751,7 -16531,7 +16751,7 @@@ TOC regression (T11764
  ==title 2==
  ===title 2.1===
  !! html
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
  <ul>
@@@ -16786,7 -16566,7 +16786,7 @@@ TOC for heading containing <span id="..
  __FORCETOC__
  ==<span id="old-anchor"></span>New title==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#New_title"><span class="tocnumber">1</span> <span class="toctext">New title</span></a></li>
  </ul>
@@@ -16808,7 -16588,7 +16808,7 @@@ wgMaxTocLevel=
  ==title 2==
  ===title 2.1===
  !! html
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
  <ul>
@@@ -16844,7 -16624,7 +16844,7 @@@ wgMaxTocLevel=
  ====Section 1.1.1.1====
  ==Section 2==
  !! html
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Section_1"><span class="tocnumber">1</span> <span class="toctext">Section 1</span></a>
  <ul>
@@@ -16937,7 -16717,7 +16937,7 @@@ __TOC_
  ===title 1.1===
  ==title 2==
  !! html
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
  <ul>
@@@ -17013,7 -16793,7 +17013,7 @@@ section 
  !! html/php
  <p>The tooltips shall not show entities to the user (ie. be double escaped)
  </p>
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#text_.3E_text"><span class="tocnumber">1</span> <span class="toctext">text &gt; text</span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#text_.3C_text"><span class="tocnumber">2</span> <span class="toctext">text &lt; text</span></a></li>
@@@ -17089,7 -16869,7 +17089,7 @@@ section 
  !! html/php
  <p>Id should not contain + for spaces
  </p>
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Space_between_Text"><span class="tocnumber">1</span> <span class="toctext">Space between Text</span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#Space-Entity_between_Text"><span class="tocnumber">2</span> <span class="toctext">Space-Entity&#32;between&#32;Text</span></a></li>
@@@ -17165,7 -16945,7 +17165,7 @@@ parsoid=wt2html,wt2wt,html2htm
  =''italic'' heading==
  ==''italic'' heading=
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#foo.3D"><span class="tocnumber">1</span> <span class="toctext">foo=</span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#.3Dfoo"><span class="tocnumber">2</span> <span class="toctext">=foo</span></a></li>
@@@ -17200,7 -16980,7 +17200,7 @@@ HTML headers vs TOC (T25393
  ==Header 2.2==
  __NOEDITSECTION__
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1"><a href="#Header_1"><span class="tocnumber">1</span> <span class="toctext">Header 1</span></a>
  <ul>
@@@ -18841,7 -18621,7 +18841,7 @@@ Punctuation: CSS !important (T13874
  !! wikitext
  <div style="width:50% !important">important</div>
  !! html
 -<div style="width:50% !important">important</div>
 +<div style="width:50%&#32;!important">important</div>
  
  !!end
  
@@@ -18850,7 -18630,7 +18850,7 @@@ Punctuation: CSS ! important (T13874; w
  !! wikitext
  <div style="width:50% ! important">important</div>
  !! html
 -<div style="width:50% ! important">important</div>
 +<div style="width:50%&#32;! important">important</div>
  
  !!end
  
@@@ -19126,7 -18906,7 +19126,7 @@@ Fuzz testing: Parser1
  http://__TOC__
  !! html/php
  <h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- http://<div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ http://<div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#onmouseover.3D"><span class="tocnumber">1</span> <span class="toctext">onmouseover=</span></a></li>
  </ul>
  
  !! html/php+tidy
  <h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2><p>
- http://</p><div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ http://</p><div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#onmouseover.3D"><span class="tocnumber">1</span> <span class="toctext">onmouseover=</span></a></li>
  </ul>
@@@ -21166,25 -20946,6 +21166,25 @@@ File:Foobar.jp
  </ul>
  !! end
  
 +!! test
 +Serialize gallery image captions on a line
 +!! options
 +parsoid={
 +  "modes": ["html2wt"],
 +  "nativeGallery": true
 +}
 +!! html/parsoid
 +<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px;"><figure-inline typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></figure-inline></div><div class="gallerytext"><p>hi</p><p>ho</p></div></li>
 +<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px;"><figure-inline typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></figure-inline></div><div class="gallerytext">hi<br />ho</div></li>
 +</ul>
 +!! wikitext
 +<gallery>
 +File:Foobar.jpg| hi  ho 
 +File:Foobar.jpg|hi<br />ho
 +</gallery>
 +!! end
 +
  !! test
  HTML Hex character encoding (spells the word "JavaScript")
  !! options
@@@ -21344,22 -21105,18 +21344,22 @@@ T24905: <abbr> followed by ISBN followe
  Double RFC
  !! wikitext
  RFC RFC 1234
 -!! html
 +!! html/php
  <p>RFC <a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc1234">RFC 1234</a>
  </p>
 +!! html/parsoid
 +<p>RFC <a href="https://tools.ietf.org/html/rfc1234" rel="mw:ExtLink" class="external mw-magiclink">RFC 1234</a></p>
  !! end
  
  !! test
  Double RFC with a wiki link
  !! wikitext
  RFC [[RFC 1234]]
 -!! html
 +!! html/php
  <p>RFC <a href="/index.php?title=RFC_1234&amp;action=edit&amp;redlink=1" class="new" title="RFC 1234 (page does not exist)">RFC 1234</a>
  </p>
 +!! html/parsoid
 +<p>RFC <a rel="mw:WikiLink" href="./RFC_1234" title="RFC 1234">RFC 1234</a></p>
  !! end
  
  !! test
@@@ -21370,7 -21127,7 +21370,7 @@@ RFC   983&#x20;98
  <p><a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc983">RFC 983</a>&#x20;987
  </p>
  !! html/parsoid
 -<p><a href="https://tools.ietf.org/html/rfc983" rel="mw:ExtLink" class="external text" data-parsoid='{"stx":"magiclink"}'>RFC   983</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#x20;","srcContent":" "}'> </span>987</p>
 +<p><a href="https://tools.ietf.org/html/rfc983" rel="mw:ExtLink" class="external mw-magiclink" data-parsoid='{"stx":"magiclink"}'>RFC   983</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#x20;","srcContent":" "}'> </span>987</p>
  !! end
  
  !! test
@@@ -21615,9 -21372,9 +21615,9 @@@ parsoid=wt2htm
  !! test
  Definition list code coverage
  !! wikitext
 -;title   : def
 -;title : def
 -;title: def
 +;title   :def
 +;title :def
 +;title:def
  !! html/php
  <dl><dt>title  &#160;</dt>
  <dd>def</dd>
  <dd>def</dd></dl>
  
  !! html/parsoid
 -<dl><dt>title  <span typeof="mw:Placeholder"> </span></dt><dd> def</dd>
 -<dt>title<span typeof="mw:Placeholder"> </span></dt><dd> def</dd>
 -<dt>title</dt><dd> def</dd></dl>
 +<dl><dt>title  <span typeof="mw:Placeholder"> </span></dt><dd>def</dd>
 +<dt>title<span typeof="mw:Placeholder"> </span></dt><dd>def</dd>
 +<dt>title</dt><dd>def</dd></dl>
  !! end
  
  !! test
@@@ -21707,7 -21464,7 +21707,7 @@@ Out-of-order TOC heading level
  =====5=====
  ==2==
  !! html
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#2"><span class="tocnumber">1</span> <span class="toctext">2</span></a>
  <ul>
@@@ -22182,11 -21939,11 +22182,11 @@@ conversion
  
  ==Latinski==
  !! html/php
 -<h2><span id="-.7BNaslov.7D-"></span><span class="mw-headline" id="-{Naslov}-">Naslov</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Уреди одељак „Naslov“">уреди</a><span class="mw-editsection-bracket">]</span></span></h2>
 +<h2><span id="-.7BNaslov.7D-"></span><span class="mw-headline" id="-{Naslov}-">Naslov</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Уредите одељак „Naslov“">уреди</a><span class="mw-editsection-bracket">]</span></span></h2>
  <p>Ноте тхат евен ан унпротецтед хеадлине ИД ис нот аффецтед бy лангуаге
  цонверсион:
  </p>
 -<h2><span class="mw-headline" id="Latinski">Латински</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Уреди одељак „Латински“">уреди</a><span class="mw-editsection-bracket">]</span></span></h2>
 +<h2><span class="mw-headline" id="Latinski">Латински</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Уредите одељак „Латински“">уреди</a><span class="mw-editsection-bracket">]</span></span></h2>
  
  !! html/parsoid
  <h2 id="-{Naslov}-"><span id="-.7BNaslov.7D-" typeof="mw:FallbackId"></span><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"Naslov"}}'></span></h2>
@@@ -22877,8 -22634,8 +22877,8 @@@ gopher://www.google.co
  !! html/parsoid
  <p><a rel="mw:ExtLink" class="external free" href="http://www.google.com">http://www.google.com</a>
  <a rel="mw:ExtLink" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
 -<a rel="mw:ExtLink" class="external free" href="http://www.google.com">http://www.google.com</a>
 -<a rel="mw:ExtLink" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
 +<a rel="mw:ExtLink" class="external text" href="http://www.google.com">http://www.google.com</a>
 +<a rel="mw:ExtLink" class="external text" href="gopher://www.google.com">gopher://www.google.com</a>
  <a rel="mw:ExtLink" class="external text" href="https://www.google.com">irc://www.google.com</a>
  <a rel="mw:ExtLink" class="external text" href="ftp://www.google.com">www.google.com/ftp://dir</a>
  <a rel="mw:ExtLink" class="external text" href="//www.google.com">www.google.com</a></p>
@@@ -22954,7 -22711,7 +22954,7 @@@ language=s
  !! wikitext
  [[Датотека:Foobar.jpg|thumb|-{R|caption:}-]]
  !! html/php
 -<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:Foobar.jpg" class="internal" title="Повећај"></a></div>caption:</div></div></div>
 +<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:Foobar.jpg" class="internal" title="Повећајте"></a></div>caption:</div></div></div>
  
  !! html/parsoid
  <figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"}]}'><a href="./Датотека:Foobar.jpg"><img resource="./Датотека:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"caption:"}}' data-parsoid='{"fl":["R"]}'></span></figcaption></figure>
@@@ -23498,12 -23255,7 +23498,12 @@@ Line tw
  
  !! end
  
 -# FIXME: Why does/should the blockquote+div combo suppress p-wrapping here?
 +## This is a corner case interaction between the paragraph wrapping in the
 +## php parser's BlockLevelPass and Remex.  `doBlockLevels` has a notion of
 +## some tags which close paragraphs (and thus prevent wrapping on their line),
 +## of which "div" is one, but do p-wrapping inside them.  These are referred
 +## to as "never suppressing".  Remex, for its part, doesn't traverse into
 +## "div"s to p-wrap.  Hence, we only get this partial wrapping.
  !! test
  Paragraphs inside blockquotes/divs (no extra line breaks)
  !! wikitext
@@@ -24138,10 -23890,10 +24138,10 @@@ Play a bit with r67090 and T515
  <div style="width:50%&#160;!important">&nbsp;</div>
  <div style="border : solid;">&nbsp;</div>
  !! html/php
 -<div style="width:50% !important">&#160;</div>
 +<div style="width:50%&#32;!important">&#160;</div>
  <div style="width:50% !important">&#160;</div>
  <div style="width:50% !important">&#160;</div>
 -<div style="border&#160;: solid;">&#160;</div>
 +<div style="border&#32;: solid;">&#160;</div>
  
  !! html/parsoid
  <div style="width:50% !important" data-parsoid='{"stx":"html"}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
  
  !! end
  
 +!! test
 +T5158: Test for French spaces in attributes
 +!! wikitext
 +<br style=" clear : both ; " />
 +!! html/php
 +<p><br style="clear&#32;: both&#32;;" />
 +</p>
 +!! end
 +
  !! test
  HTML5 data attributes
  !! wikitext
@@@ -24354,7 -24097,7 +24354,7 @@@ title=[[Main Page]
  __TOC__
  ==''Lost'' episodes==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Lost_episodes"><span class="tocnumber">1</span> <span class="toctext"><i>Lost</i> episodes</span></a></li>
  </ul>
@@@ -24375,7 -24118,7 +24375,7 @@@ title=[[Main Page]
  __TOC__
  =='''should be bold''' then normal text==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#should_be_bold_then_normal_text"><span class="tocnumber">1</span> <span class="toctext"><b>should be bold</b> then normal text</span></a></li>
  </ul>
@@@ -24396,7 -24139,7 +24396,7 @@@ title=[[Main Page]
  __TOC__
  ==Image [[Image:foobar.jpg]]==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Image"><span class="tocnumber">1</span> <span class="toctext">Image</span></a></li>
  </ul>
@@@ -24417,7 -24160,7 +24417,7 @@@ title=[[Main Page]
  __TOC__
  ==<blockquote>Quote</blockquote>==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Quote"><span class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
  </ul>
  <h2><span class="mw-headline" id="Quote"><blockquote>Quote</blockquote></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Quote">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
  
  !! html/php+tidy
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Quote"><span class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
  </ul>
@@@ -24450,7 -24193,7 +24450,7 @@@ __TOC_
  <small>Hanc marginis exiguitas non caperet.</small>
  QED
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Proof:_2_&lt;_3"><span class="tocnumber">1</span> <span class="toctext">Proof: 2 &lt; 3</span></a></li>
  </ul>
@@@ -24475,7 -24218,7 +24475,7 @@@ __TOC_
  
  ==<i>Foo</i> <blockquote>Bar</blockquote>==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Foo_Bar"><span class="tocnumber">1</span> <span class="toctext"><i>Foo</i> <b>Bar</b></span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#Foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext"><i>Foo</i> Bar</span></a></li>
  <h2><span class="mw-headline" id="Foo_Bar_2"><i>Foo</i> <blockquote>Bar</blockquote></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
  
  !! html/php+tidy
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Foo_Bar"><span class="tocnumber">1</span> <span class="toctext"><i>Foo</i> <b>Bar</b></span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#Foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext"><i>Foo</i> Bar</span></a></li>
@@@ -24514,7 -24257,7 +24514,7 @@@ __TOC_
  
  ==<sup class="a > b">Evilbye</sup>==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Hello"><span class="tocnumber">1</span> <span class="toctext"><sup>Hello</sup></span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#b.22.3EEvilbye"><span class="tocnumber">2</span> <span class="toctext"><sup> b"&gt;Evilbye</sup></span></a></li>
@@@ -24545,7 -24288,7 +24545,7 @@@ __TOC_
  
  ==<span dir="ltr" style="font-style: italic">Attributes after dir on these span tags must be deleted from the TOC</span>==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#C.2B.2B"><span class="tocnumber">1</span> <span class="toctext"><span dir="ltr">C++</span></span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#.D7.96.D7.91.D7.A0.D7.92.21"><span class="tocnumber">2</span> <span class="toctext"><span dir="rtl">זבנג!</span></span></a></li>
@@@ -24576,7 -24319,7 +24576,7 @@@ T74884: bdi element in To
  __TOC__
  ==<bdi>test</bdi>==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#test"><span class="tocnumber">1</span> <span class="toctext"><bdi>test</bdi></span></a></li>
  </ul>
@@@ -24595,7 -24338,7 +24595,7 @@@ T35715: s/strike element in To
  __TOC__
  ==<s>test</s> test <strike>test</strike>==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#test_test_test"><span class="tocnumber">1</span> <span class="toctext"><s>test</s> test <strike>test</strike></span></a></li>
  </ul>
@@@ -24614,7 -24357,7 +24614,7 @@@ Empty <p> tag in TOC, removed by Saniti
  __TOC__
  ==x==
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#x"><span class="tocnumber">1</span> <span class="toctext">x</span></a></li>
  </ul>
  <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:","function":"padright"},"params":{"1":{"wt":"3"},"2":{"wt":"abcde"}},"i":0}}]}'>abc</span></p>
  !! end
  
 +!! test
 +Padleft and padright with non-numerical length (T180403)
 +!! wikitext
 +{{padleft:abcdef|junk}}
 +{{padright:abcdef|junk}}
 +!! html/php
 +<p>abcdef
 +abcdef
 +</p>
 +!! end
 +
  !!test
  Special parser function
  !! wikitext
@@@ -25074,9 -24806,9 +25074,9 @@@ Empty LI and TR nodes should be strippe
  !! test
  Empty LI and TR nodes should not be stripped from top-level content
  !! wikitext
 -* a
 +*a
  *
 -* b
 +*b
  
  {|
  |-
  |}
  !! html/parsoid
  <ul>
 -<li> a</li>
 +<li>a</li>
  <li class='mw-empty-elt'></li>
 -<li> b</li>
 +<li>b</li>
  </ul>
  <table>
  <tbody>
@@@ -26004,65 -25736,6 +26004,65 @@@ parsoid=html2w
  
  !! end
  
 +!! test
 +Tables: 5. Empty table cells should get whitespace to avoid need for nowikis
 +!! options
 +parsoid=html2wt
 +!! html/parsoid
 +<table><tr><td></td><td align="center" data-parsoid='{"stx":"row"}'></td><td data-parsoid='{"stx":"row"}'></td></tr></table>
 +
 +<table><tr><td></td><td align="center"></td><td></td></tr></table>
 +
 +<table><tr><td></td><td align="center" data-parsoid='{"stx":"row", "startTagSrc":"{{!}}{{!}}"}'></td><td data-parsoid='{"stx":"row"}'></td></tr></table>
 +
 +<table><tr><th></th><th align="center" data-parsoid='{"stx":"row"}'></th><th data-parsoid='{"stx":"row"}'></th></tr></table>
 +!! wikitext
 +{|
 +| || align="center" | ||
 +|}
 +
 +{|
 +|
 +| align="center" |
 +|
 +|}
 +
 +{|
 +| {{!}}{{!}} align="center" | ||
 +|}
 +
 +{|
 +! !! align="center" | !!
 +|}
 +!! html/php+tidy
 +<table>
 +<tbody><tr>
 +<td></td>
 +<td align="center"></td>
 +<td>
 +</td></tr></tbody></table>
 +<table>
 +<tbody><tr>
 +<td>
 +</td>
 +<td align="center">
 +</td>
 +<td>
 +</td></tr></tbody></table>
 +<table>
 +<tbody><tr>
 +<td></td>
 +<td align="center"></td>
 +<td>
 +</td></tr></tbody></table>
 +<table>
 +<tbody><tr>
 +<th></th>
 +<th align="center"></th>
 +<th>
 +</th></tr></tbody></table>
 +!! end
 +
  !! test
  T97430: Don't emit empty nowiki pairs around marker meta tags
  !! options
@@@ -26592,6 -26265,8 +26592,6 @@@ bar <span><nowiki>[[foo]]</nowiki></spa
  !!end
  
  #### ----------------------- PRE --------------------------
 -#### 1. Leading whitespace in SOL context should be escaped
 -#### ------------------------------------------------------
  !! test
  1. Leading whitespace in SOL context should be escaped
  !! options
@@@ -26704,7 -26379,7 +26704,7 @@@ parsoid=html2w
   ==foo==
  !! end
  
 -!!test
 +!! test
  T95794: nowiki escaping should account for leading space at start-of-line in an indent-pre block
  !! options
  parsoid=html2wt
   * bar
  !! end
  
 +!! test
 +Whitespace scrubbing in SOL position should account for SOL-sensitive wikitext markup
 +!! options
 +parsoid = {
 +  "modes": ["html2wt"],
 +  "scrubWikitext": true
 +}
 +!! html/parsoid
 +<p> foo</p>
 +<p> %foo</p>
 +<p> *foo</p>
 +<p> #foo</p>
 +<p> =foo=</p>
 +<p><link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid="{}"> *foo</p>
 +<p> <link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid="{}">*foo</p>
 +<p> <!--boo-->*foo</p>
 +<p><!--boo--> *foo</p>
 +<p><!--a--> <!--b--> <!--c--> <!--d--> <!--e--> foo</p>
 +<p><!--a--> <!--b--> <!--c--> <!--d--> <!--e--> *foo</p>
 +!! wikitext
 +foo
 +
 +%foo
 +
 +<nowiki/>*foo
 +
 +<nowiki/>#foo
 +
 +<nowiki/>=foo=
 +
 +[[Category:Foo]]
 +<nowiki/>*foo
 +
 + [[Category:Foo]]
 +<nowiki>*</nowiki>foo
 +
 +<nowiki/><!--boo-->*foo
 +
 +<!--boo--><nowiki/>*foo
 +
 +<!--a--><!--b--><!--c--><!--d--><!--e-->foo
 +
 +<!--a--><nowiki/><!--b--><!--c--><!--d--><!--e-->*foo
 +!! end
 +
  #### --------------- Behavior Switches --------------------
  
  !! test
@@@ -26878,18 -26508,6 +26878,18 @@@ parsoid=html2w
  baz<nowiki></ref></nowiki>
  !! end
  
 +!! test
 +Parsoid: newline inducing block nodes don't suppress <nowiki>
 +!! options
 +parsoid=html2wt
 +!! html/parsoid
 + a<h1>foo</h1>
 +!! wikitext
 +<nowiki> </nowiki>a
 +
 += foo =
 +!! end
 +
  #### --------------- Others ---------------
  !! test
  Escaping nowikis
@@@ -27341,13 -26959,13 +27341,13 @@@ Encapsulate protected attributes from w
  <div typeof="mw:placeholder stuff" data-mw="whoo" data-parsoid="weird" data-parsoid-other="no" about="time" rel="mw:true">foo</div>
  
  {| typeof="mw:placeholder stuff" data-mw="whoo" data-parsoid="weird" data-parsoid-other="no" about="time" rel="mw:true"
 -| ok
 +|ok
  |}
  !! html/parsoid
  <div data-x-typeof="mw:placeholder stuff" data-x-data-mw="whoo" data-x-data-parsoid="weird" data-x-data-parsoid-other="no" data-x-about="time" data-x-rel="mw:true">foo</div>
  
  <table data-x-typeof="mw:placeholder stuff" data-x-data-mw="whoo" data-x-data-parsoid="weird" data-x-data-parsoid-other="no" data-x-about="time" data-x-rel="mw:true">
 -<tbody><tr><td data-parsoid='{"autoInsertedEnd":true}'> ok</td></tr>
 +<tbody><tr><td data-parsoid='{"autoInsertedEnd":true}'>ok</td></tr>
  </tbody></table>
  !!end
  
@@@ -27364,64 -26982,64 +27364,64 @@@ plain text</pre
  plain text
  !!end
  
 -!!test
 +!! test
  1. Ensure fostered text content is wrapped in element nodes
 -!!options
 +!! options
  parsoid=wt2html
  !! wikitext
  <table>hi</table><table>ho</table>
 +!! html/php+tidy
 +hi<table></table>ho<table></table>
  !! html/parsoid
 -<p>hi</p>
 -<table></table>
 -<p>ho</p>
 -<table></table>
 -!!end
 +<span data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>hi</span><table data-parsoid='{"stx":"html"}'></table><span data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>ho</span><table data-parsoid='{"stx":"html"}'></table>
 +!! end
  
 -!!test
 +!! test
  2. Ensure fostered text content is wrapped in element nodes (traps regressions around fostered marker on the element getting lost)
 -!!options
 +!! options
  parsoid=wt2html,wt2wt
  !! wikitext
  <table>
  <tr> || ||
  <td> a
  </table>
 +!! html/php+tidy
 + || ||
 +<table>
 +<tbody><tr><td> a
 +</td></tr></tbody></table>
  !! html/parsoid
 -<p> || ||
 -</p><table>
 -<tbody><tr><td> a</td></tr>
 -</tbody></table>
 -!!end
 +<span data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'> || ||
 +</span><table data-parsoid='{"stx":"html"}'>
 +<tbody><tr data-parsoid='{"stx":"html","autoInsertedEnd":true}'><td data-parsoid='{"stx":"html","autoInsertedEnd":true}'> a
 +</td></tr></tbody></table>
 +!! end
  
 -!!test
 +!! test
  Encapsulation properly handles null DSR information from foster box
 -!!options
 +!! options
  parsoid=wt2html,wt2wt
  !! wikitext
  {{echo|<table>foo<tr><td>bar</td></tr></table>}}
  !! html/parsoid
  <span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;<table>foo<tr><td>bar</td></tr></table>&quot;}},&quot;i&quot;:0}}]}">foo</span><table><tbody><tr><td>bar</td></tr></tbody></table>
 -!!end
 +!! end
  
 -!!test
 +!! test
  1. Encapsulate foster-parented transclusion content
 -!!options
 +!! options
  parsoid=wt2wt,wt2html
  !! wikitext
  <table>{{echo|foo<tr><td>bar</td></tr>}}</table>
 +!! html/php+tidy
 +foo<table><tbody><tr><td>bar</td></tr></tbody></table>
  !! html/parsoid
 -<p typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo<tr><td>bar</td></tr>&quot;}},&quot;i&quot;:0}},&quot;</table>&quot;]}">foo</p><table>
 -<tbody>
 -<tr>
 -<td>bar</td>
 -</tr>
 -</tbody>
 -</table>
 -!!end
 +<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo&lt;tr>&lt;td>bar&lt;/td>&lt;/tr>"}},"i":0}},"&lt;/table>"]}'>foo</span><table about="#mwt2" data-parsoid='{"stx":"html}'><tbody><tr><td>bar</td></tr></tbody></table>
 +!! end
  
 -!!test
 +!! test
  2. Encapsulate foster-parented transclusion content
 -!!options
 +!! options
  parsoid=wt2wt,wt2html
  !! wikitext
  <table><div>{{echo|foo}}</div><tr><td>bar</td></tr></table>
  </tr>
  </tbody>
  </table>
 -!!end
 +!! end
  
 -!!test
 +!! test
  3. Encapsulate foster-parented transclusion content
 -!!options
 +!! options
  parsoid=wt2wt,wt2html
  !! wikitext
  <table><div><p>{{echo|foo</p></div><tr><td>}}bar</td></tr></table>
  </tr>
  </tbody>
  </table>
 -!!end
 +!! end
  
 -!!test
 +!! test
  4. Encapsulate foster-parented transclusion content
 -!!options
 +!! options
  parsoid=wt2wt,wt2html
  !! wikitext
  <table><div><p>{{echo|foo</p></div><tr><td>}}bar</td></tr></table>
  </tr>
  </tbody>
  </table>
 -!!end
 +!! end
  
 -!!test
 +!! test
  5. Encapsulate foster-parented transclusion content
  !!options
  parsoid=wt2wt,wt2html
  !! wikitext
  <table><tr><td><div><p>{{echo|foo</p></div></td>foo}}</tr></table>
 +!! html/php+tidy
 +foo<table><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table>
  !! html/parsoid
 -<p typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><tr><td><div><p>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo</p></div></td>foo&quot;}},&quot;i&quot;:0}},&quot;</tr></table>&quot;]}">foo</p>
 -<table>
 -<tbody>
 -<tr>
 -<td>
 -<div>
 -<p>foo</p>
 -</div>
 -</td>
 -</tr>
 -</tbody>
 -</table>
 -!!end
 +<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;tr>&lt;td>&lt;div>&lt;p>",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo&lt;/p>&lt;/div>&lt;/td>foo"}},"i":0}},"&lt;/tr>&lt;/table>"]}'>foo</span><table about="#mwt2" data-parsoid='{"stx":"html"}'><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table>
 +!! end
  
 -!!test
 +!! test
  6. Encapsulate foster-parented transclusion content
 -!!options
 +!! options
  parsoid=wt2wt,wt2html
  !! wikitext
  <table><tr><td><div><p>{{echo|foo</p></div></td>foo</tr></table>}}<p>ok</p>
 +!! html/php+tidy
 +foo<table><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table><p>ok</p>
  !! html/parsoid
 -<p typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><tr><td><div><p>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo</p></div></td>foo</tr></table>&quot;}},&quot;i&quot;:0}}]}">foo</p>
 -<table>
 -<tbody>
 -<tr>
 -<td>
 -<div>
 -<p>foo</p>
 -</div>
 -</td>
 -</tr>
 -</tbody>
 -</table>
 -<p>ok</p>
 -!!end
 +<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;tr>&lt;td>&lt;div>&lt;p>",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo&lt;/p>&lt;/div>&lt;/td>foo&lt;/tr>&lt;/table>"}},"i":0}}]}'>foo</span><table about="#mwt2" data-parsoid='{"stx":"html"}'><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table><p data-parsoid='{"stx":"html"}'>ok</p>
 +!! end
  
 -!!test
 +!! test
  7. Encapsulate foster-parented transclusion content
  !!options
  parsoid=wt2wt,wt2html
  </tr>
  </tbody>
  </table>
 -!!end
 +!! end
  
  # Note that the wt is broken on purpose: the = should be {{=}} if you
  # don't want it to be a template parameter key.
 -!!test
 +!! test
  8. Encapsulate foster-parented transclusion content
 -!!options
 +!! options
  parsoid=wt2wt,wt2html
  !! wikitext
  {{echo|a
  |-
  |b
  |}
 -!! html/parsoid
 -<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n"}},"i":0}}]}'>a</p>
 -<span> </span>
 -<p typeof="mw:Transclusion" data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"style":{"wt":"&#39;color:red&#39;"}},"i":0}},"\n|-\n|b\n|}"]}'>{{{1}}}</p>
 +!! html/php+tidy
 +<p>a
 +</p>
  <table>
 -<tbody>
 -<tr>
 -<td>b</td>
 -</tr>
 -</tbody>
 -</table>
 -!!end
  
 -!!test
 +<tbody><tr>
 +<td>b
 +</td></tr></tbody></table>
 +!! html/parsoid
 +<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n"}},"i":0}}]}'>a</p><span about="#mwt1">
 +</span><span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"style","named":true}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"style":{"wt":"&apos;color:red&apos;"}},"i":0}},"\n|-\n|b\n|}"]}'>{{{1}}}</span><table about="#mwt3">
 +<tbody><tr>
 +<td>b
 +</td></tr></tbody></table>
 +!! end
 +
 +!! test
  9. Encapsulate foster-parented transclusion content
  !!options
  parsoid=wt2wt,wt2html
  !! wikitext
  <table>{{echo|hi</table>hello}}
 +!! html/php+tidy
 +hi<table></table><p>hello
 +</p>
  !! html/parsoid
 -<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;/table>hello"}},"i":0}}]}' data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"pi":[[{"k":"1"}]]}'>hi</p><table about="#mwt2" data-parsoid='{"stx":"html"}'></table><p about="#mwt2">hello</p>
 -!!end
 +<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;/table>hello"}},"i":0}}]}'>hi</span><table about="#mwt2"></table><p about="#mwt2">hello</p>
 +!! end
  
 -!!test
 +!! test
  Table in fosterable position
  !!options
  parsoid=wt2html
  
  <table>
  </table>
 -!!end
 +!! end
  
  # Parsoid only for T66747
  !! test
@@@ -28219,7 -27850,7 +28219,7 @@@ parsoid=
  
  == hi pal ==
  
 -<!--foo-->  [[Category:A3]]
 +<!--foo-->[[Category:A3]]
  
  == how goes it ==
  
@@@ -28543,7 -28174,7 +28543,7 @@@ parsoid=
  !! html/parsoid
  <a rel="mw:WikiLink" href="./Football"><i>Foot</i></a><a rel="mw:WikiLink" href="./Football"><i>ball</i></a>
  !! wikitext
 -[[Football|''Football'']]
 +''[[Football]]''
  !! end
  
  !! test
@@@ -28559,98 -28190,6 +28559,98 @@@ parsoid=
  [[Football|Foot]][[Football|ball]]
  !! end
  
 +!! test
 +1. Move format tags outside of WikiLink
 +!! options
 +parsoid={
 +  "modes": ["html2wt"],
 +  "scrubWikitext": true
 +}
 +!! html/parsoid
 +<a rel="mw:WikiLink" href="./Football"><i>Football</i></a>
 +<a rel="mw:WikiLink" href="./Football"><i><b>Football</b></i></a>
 +<a rel="mw:WikiLink" href="./Football"><u><i><b>Football</b></i></u></a>
 +!! wikitext
 +''[[Football]]''
 +'''''[[Football]]'''''
 +<u>'''''[[Football]]'''''</u>
 +!! end
 +
 +!! test
 +2. Move format tags outside of WikiLink with mergable A tags
 +!! options
 +parsoid={
 +  "modes": ["html2wt"],
 +  "scrubWikitext": true
 +}
 +!! html/parsoid
 +<a rel="mw:WikiLink" href="./Football"><i><b>Foot</b></i></a><a rel="mw:WikiLink" href="./Football"><i><b>ball</b></i></a>
 +!! wikitext
 +'''''[[Football]]'''''
 +!! end
 +
 +!! test
 +3. Move format tags outside of WikiLink while preserving formats already outside WikiLink
 +!! options
 +parsoid={
 +  "modes": ["html2wt"],
 +  "scrubWikitext": true
 +}
 +!! html/parsoid
 +<font color="red"><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><u><b>Foo</b></u></a></font>
 +!! wikitext
 +<font color="red"><u>'''[[Foo]]'''</u></font>
 +!! end
 +
 +!! test
 +4. Do not move format tags outside of WikiLink which includes attributes color, style and class
 +!! options
 +parsoid={
 +  "modes": ["html2wt"],
 +  "scrubWikitext": true
 +}
 +!! html/parsoid
 +<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><font color="red">Foo</font></a>
 +<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><span style="color: blue; font-size: 46px;">Foo></span></a>
 +<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><span class="Bar">Foo</span></a>
 +!! wikitext
 +[[Foo|<font color="red">Foo</font>]]
 +[[Foo|<span style="color: blue; font-size: 46px;">Foo></span>]]
 +[[Foo|<span class="Bar">Foo</span>]]
 +!! end
 +
 +!! test
 +5. T194083 Regression test: Manual edit test that also enables scrubWikitext to move format tags outside wikilinks
 +!! options
 +parsoid={
 +  "modes": ["selser"],
 +  "scrubWikitext": true,
 +  "changes": [
 +    ["a", "html", "<i>Foo</i>"]
 +  ]
 +}
 +!! wikitext
 +[[Foo]]
 +!! wikitext/edited
 +''[[Foo]]''
 +!! end
 +
 +!! test
 +6. Regression test: Manual edit test to ensure diff markers are not lost
 +!! options
 +parsoid={
 +  "modes": ["selser"],
 +  "scrubWikitext": true,
 +  "changes": [
 +    ["i", "wrap", "<a href='./Foo' rel='mw:WikiLink'></a>"]
 +  ]
 +}
 +!! wikitext
 +''Foo''
 +!! wikitext/edited
 +''[[Foo]]''
 +!! end
 +
  #------------------------------
  # End of tag minimization tests
  #------------------------------
@@@ -28890,8 -28429,8 +28890,8 @@@ Magic links inside image captions (auto
  <div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><a href="/wiki/Special:BookSources/123456789X" class="internal mw-magiclink-isbn">ISBN 123456789x</a></div></div></div>
  !! html/parsoid
  <figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" class="external free" href="http://example.com">http://example.com</a></figcaption></figure>
 -<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="https://tools.ietf.org/html/rfc1234" rel="mw:ExtLink" class="external text">RFC 1234</a></figcaption></figure>
 -<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external text">PMID 1234</a></figcaption></figure>
 +<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="https://tools.ietf.org/html/rfc1234" rel="mw:ExtLink" class="external mw-magiclink">RFC 1234</a></figcaption></figure>
 +<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink" class="external mw-magiclink">PMID 1234</a></figcaption></figure>
  <figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="./Special:BookSources/123456789X" rel="mw:WikiLink">ISBN 123456789x</a></figcaption></figure>
  !! end
  
@@@ -28956,7 -28495,8 +28956,7 @@@ parsoid=html2wt,wt2w
  |<small>-</small>
  |<br />
  -
 -|<br />
 --
 +|<br />-
  |}
  !! html/php+tidy
  <table>
  <p>-
  </p>
  </td>
 -<td><br />
 -<p>-
 -</p>
 +<td><br />-
  </td></tr></tbody></table>
  !! end
  
@@@ -29101,147 -28643,6 +29101,147 @@@ parsoid=html2w
  <div id="hello">ok</div>
  !! end
  
 +!! test
 +Testing serialization after deletion in references
 +!! options
 +parsoid={
 +  "modes": ["wt2wt"],
 +  "changes": [
 +    ["#x", "remove"]
 +  ]
 +}
 +!! wikitext
 +hi <ref><div id="x">ho</div></ref>
 +
 +<references />
 +!! wikitext/edited
 +hi <ref></ref>
 +
 +<references />
 +!! end
 +
 +!!test
 +Testing serialization after deletion of table cells
 +!!options
 +parsoid={
 +  "modes": ["wt2wt", "selser"],
 +  "changes": [
 +    ["#x", "remove"]
 +  ]
 +}
 +!!wikitext
 +{|
 +!h1 !!h2 !!h3
 +| id="x" |c1 {{!}}{{!}}{{!}}c2 |||c3
 +|}
 +!! wikitext/edited
 +{|
 +!h1!!h2!!h3
 +|c2|||c3
 +|}
 +!!end
 +
 +!! test
 +Testing selser after addition of new row before first row (T125419)
 +!! options
 +parsoid={
 +  "modes": ["wt2wt", "selser"],
 +  "changes": [
 +    [ "tr", "before", "<tr><td>X</td></tr>" ]
 +  ]
 +}
 +!! wikitext
 +{|
 +|a
 +|}
 +!! wikitext/edited
 +{|
 +|X
 +|-
 +|a
 +|}
 +!! end
 +
 +!! test
 +Serialize new table rows in a HTML table using HTML tags
 +!! options
 +parsoid={
 +  "modes": ["wt2wt", "selser"],
 +  "changes": [
 +    [ "tr", "before", "<tr><td>X</td></tr>" ]
 +  ]
 +}
 +!! wikitext
 +<table><tr><td>a</td></tr></table>
 +!! wikitext/edited
 +<table><tr><td>X</td></tr><tr><td>a</td></tr></table>
 +!! end
 +
 +!! test
 +Serialize new table cells in a HTML row using HTML tags
 +!! options
 +parsoid={
 +  "modes": ["wt2wt", "selser"],
 +  "changes": [
 +    [ "td", "before", "<td>X</td>" ]
 +  ]
 +}
 +!! wikitext
 +<table><tr><td>a</td></tr></table>
 +!! wikitext/edited
 +<table><tr><td>X</td><td>a</td></tr></table>
 +!! end
 +
 +!! test
 +Serialize wikitext list items as HTML list items when embedded in a HTML list
 +!! options
 +parsoid=html2wt
 +!! html
 +<ul data-parsoid='{"stx": "html"}'>
 +<li data-parsoid='{}'>a</li>
 +<li>b</li>
 +</ul>
 +!! wikitext
 +<ul>
 +<li>a</li>
 +<li>b</li>
 +</ul>
 +!! end
 +
 +# SSS FIXME: Is this actually a good thing given the
 +# odd nested list output that is generated by MW?
 +# <ul><li>foo<ul>..</ul></li></ul> instead of
 +# <ul><li>foo</li><ul>..</ul></ul>
 +!! test
 +Wikitext lists can be nested inside HTML lists
 +!! options
 +parsoid=html2wt
 +!! html
 +<ul data-parsoid='{"stx": "html"}'>
 +<li data-parsoid='{"stx": "html"}'>a
 +<ul><li>b</li></ul>
 +</li>
 +</ul>
 +
 +<ul data-parsoid='{"stx": "html"}'>
 +<li>x
 +<ul><li>y</li></ul>
 +</li>
 +</ul>
 +!! wikitext
 +<ul>
 +<li>a
 +* b
 +</li>
 +</ul>
 +
 +<ul>
 +<li>x
 +* y
 +</li>
 +</ul>
 +!! end
 +
  !! test
  WTS change modes
  !! options
@@@ -29479,7 -28880,7 +29479,7 @@@ parsoid=
  !! html/parsoid
  <h2> <link href="./Category:A2" rel="mw:PageProp/Category" />ok</h2>
  !! wikitext
 - [[Category:A2]]
 +[[Category:A2]]
  
  == ok ==
  !! end
@@@ -29547,7 -28948,7 +29547,7 @@@ parsoid=
  !! html/parsoid
  <h2>foo<br/>bar</h2>
  !! wikitext
 -== foo<br /> bar ==
 +== foo<br />bar ==
  !! end
  
  !! test
@@@ -30536,7 -29937,7 +30536,7 @@@ wgFragmentMode=[ 'html5', 'legacy' 
  [[#啤酒]] [[#%E5%95%A4%E9%85%92]]
  
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
@@@ -30602,7 -30003,7 +30602,7 @@@ wgFragmentMode=[ 'legacy', 'html5' 
  [[#啤酒]] [[#%E5%95%A4%E9%85%92]]
  
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
@@@ -30650,7 -30051,7 +30650,7 @@@ wgFragmentMode=[ 'html5' 
  [[#啤酒]] [[#%E5%95%A4%E9%85%92]]
  
  !! html/php
- <div id="toc" class="toc"><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2></div>
+ <div id="toc" class="toc"><input type="checkbox" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2>Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
  <ul>
  <li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
  <li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
@@@ -31222,16 -30623,10 +31222,16 @@@ headings, and cells. HTML versions of t
  ##########################################################################
  !! test
  Trim whitespace in wikitext headings, list items, table captions, headings, and cells
 +!! options
 +parsoid={
 +      "modes": ["wt2html"],
 +      "preserveIEW": true
 +}
  !! wikitext
  __NOTOC__
  ==    <!--c1-->  <!--c2--> Spaces   <!--c3--> <!--c4-->  ==
 -==            <!--c2-->       <!--c2--> Tabs          <!--c3--><!--c4-->      ==
 +==            <!--c1-->       <!--c2--> Tabs          <!--c3--><!--c4-->      ==
 +== <!--Headings with fallback ids--> Личная жизнь ==
  *     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->
  ; <!--term to define--> term : <!--term's definition--> definition
  {|
  !! html/php+tidy
  <h2><span class="mw-headline" id="Spaces">Spaces</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Spaces">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
  <h2><span class="mw-headline" id="Tabs">Tabs</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Tabs">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
 +<h2><span class="mw-headline" id=".D0.9B.D0.B8.D1.87.D0.BD.D0.B0.D1.8F_.D0.B6.D0.B8.D0.B7.D0.BD.D1.8C">Личная жизнь</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Личная жизнь">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
  <ul><li>List item</li></ul>
  <dl><dt>term&#160;</dt>
  <dd>definition</dd></dl>
  <td>Table Cell 1</td>
  <td>Table Cell 2
  </td></tr></tbody></table> foo</dd></dl>
 +!! html/parsoid
 +<meta property="mw:PageProp/notoc">
 +<h2 id="Spaces"><!--c1--><!--c2-->Spaces<!--c3--><!--c4--></h2>
 +<h2 id="Tabs"><!--c1--><!--c2-->Tabs<!--c3--><!--c4--></h2>
 +<h2 id="Личная_жизнь"><span id=".D0.9B.D0.B8.D1.87.D0.BD.D0.B0.D1.8F_.D0.B6.D0.B8.D0.B7.D0.BD.D1.8C" typeof="mw:FallbackId"></span><!--Headings with fallback ids-->Личная жизнь</h2>
 +<ul><li><!--c1--><!--c2-->List item<!--c3--><!--c4--></li></ul>
 +<dl><dt><!--term to define-->term&nbsp;</dt><dd><!--term's definition-->definition</dd></dl>
 +<table>
 +<caption><!--c1--><!--c2-->Table Caption<!--c3--><!--c4--></caption>
 +<tbody><tr>
 +<th><!--c1--><!--c2-->Table Heading 1<!--c3--><!--c4--></th><th>Table Heading 2<!--c5--></th></tr>
 +<tr>
 +<td><!--c1--><!--c2-->Table Cell 1<!--c3--><!--c4--></td><td>Table Cell 2<!--c5--></td></tr>
 +<tr>
 +<td>class="foo"</td><td><!--c1--><!--c2-->Table Cell 3<!--c3--><!--c4--></td></tr>
 +<tr>
 +<td><!--c1-->testing <a rel="mw:WikiLink" href="./One" title="One">two</a> <!--c2--> | <!--c3--> some content</td></tr>
 +</tbody></table>
 +<dl><dd><table>
 +  <tbody><tr><td><!--c1--><!--c2-->Table Cell 1<!--c3--><!--c4--></td><td>Table Cell 2<!--c5--></td></tr>
 +  </tbody></table><p> foo   </p><!--c1--></dd></dl>
  !! end
  
  # Looks like <caption> is not accepted in HTML
  !! test
  Do not trim whitespace in HTML headings, list items, table captions, headings, and cells
 +!! options
 +parsoid={
 +      "modes": ["wt2html"],
 +      "preserveIEW": true
 +}
  !! wikitext
  __NOTOC__
  <h2>    <!--c1-->   <!--c2--> Heading    <!--c3--> <!--c4-->  </h2>
  <tbody><tr><th>   Table Heading   </th><th></th></tr>
  <tr><td>   Table Cell   </td><th></th></tr>
  </tbody></table>
 +!! html/parsoid
 +<meta property="mw:PageProp/notoc"/>
 +<h2 id="Heading">    <!--c1-->   <!--c2--> Heading    <!--c3--> <!--c4-->  </h2>
 +<ul><li>     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->  </li></ul>
 +<table>
 +<tbody><tr><th> <!--c1--> <!--c2--> Table Heading <!--c3--> <!--c4--> </th><th></th></tr>
 +<tr><td> <!--c1--> <!--c2--> Table Cell <!--c3--> <!--c4--> </td><th></th></tr>
 +</tbody></table>
  !! end
  
  !! test
  Do not trim whitespace in links and quotes
 +!! options
 +parsoid={
 +      "modes": ["wt2html"],
 +      "preserveIEW": true
 +}
  !! wikitext
  foo ''  <!--c1--> italic <!--c2-->   '' and '''  <!--c3-->  bold  <!--c4-->  '''
  [[Foo|  some text  ]]
  <p>foo <i>   italic    </i> and <b>    bold    </b>
  <a href="/wiki/Foo" title="Foo">  some text  </a>
  </p>
 +!! html/parsoid
 +<p>foo <i>  <!--c1--> italic <!--c2-->   </i> and <b>  <!--c3-->  bold  <!--c4-->  </b>
 +<a rel="mw:WikiLink" href="./Foo" title="Foo">  some text  </a></p>
  !! end
  
  !! test