Sync up with Parsoid parserTests.
[lhc/web/wiklou.git] / tests / parser / parserTests.txt
index 2e1806d..8f83fc6 100644 (file)
@@ -838,15 +838,12 @@ parsoid=wt2html
 !!end
 
 # same html as previous, but wikitext adjusted to match parsoid html2wt
-# skipping wt2html and html2html because it wants to put <i> before <b>
 !! test
 Italics and bold: 5-quote opening sequence: (5,2+3)
-!! options
-parsoid=wt2wt,html2wt
 !! wikitext
 '''''foo'''''
-!! html
-<p><b><i>foo</i></b>
+!! html/*
+<p><i><b>foo</b></i>
 </p>
 !! end
 
@@ -1460,11 +1457,11 @@ Entities inside <nowiki>
 
 !! test
 Entities inside template parameters
-!! options
-parsoid
 !! wikitext
 {{echo|&ndash;}}
-!! html
+!! html/php+tidy
+<p>–</p>
+!! html/parsoid
 <p><span typeof="mw:Transclusion mw:Entity" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&amp;ndash;"}},"i":0}}]}'>&ndash;</span></p>
 !! end
 
@@ -1472,7 +1469,7 @@ parsoid
 Properly escape nowiki when combined with other wiki markup
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>* &lt;/nowiki&gt; tag</p>
 !! wikitext
 <nowiki>*</nowiki> <nowiki>&lt;/nowiki&gt;</nowiki> tag
@@ -1482,7 +1479,7 @@ parsoid=html2wt
 T93824: Put escaped HTML tags inside nowiki
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>&lt;h2&gt;foo&lt;/h2&gt;</p>
 !! wikitext
 <nowiki><h2>foo</h2></nowiki>
@@ -1492,7 +1489,7 @@ parsoid=html2wt
 T71950: 1. Put nowiki as close to cause as possible, even with non-quote escapable chars
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>This text: L'<a rel="mw:WikiLink" href="./Foo">Foo</a>
 This text: L''<a rel="mw:WikiLink" href="./Foo">Foo</a>
 This text: L'''<a rel="mw:WikiLink" href="./Foo">Foo</a>''</p>
@@ -1507,7 +1504,7 @@ This text: L<nowiki>'''</nowiki>[[Foo]]<nowiki>''</nowiki>
 T71950: 2. Put nowiki as close to cause as possible, after ' :'
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>This text : L''<a rel="mw:WikiLink" href="./Foo">Foo</a>
 </p>
 !! wikitext
@@ -1550,7 +1547,7 @@ parsoid=html2wt
 Cases where "!!" needs nowiki protection
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <table>
 <tr><th>this needs protection !! here</th></tr>
 </table>
@@ -1803,7 +1800,11 @@ parsoid=wt2html,wt2wt
 !! wikitext
 <!--c1-->*a
 <!--c2--><!--c3--><!--c4-->*b
-!! html
+!! html/php
+<ul><li>a</li>
+<li>b</li></ul>
+
+!! html/parsoid
 <!--c1--><ul>
 <li>a
 </li>
@@ -2016,7 +2017,7 @@ a [[Category:A1]] [[Category:A2]]
 [[Category:A4]]
 !! html/parsoid
 <p>a</p>
-<link rel="mw:PageProp/Category" href="Category:A1"/> <link rel="mw:PageProp/Category" href="Category:A2"/> <link rel="mw:PageProp/Category" href="Category:A3"/> <link rel="mw:PageProp/Category" href="Category:A4"/>
+<link rel="mw:PageProp/Category" href="./Category:A1"/> <link rel="mw:PageProp/Category" href="./Category:A2"/> <link rel="mw:PageProp/Category" href="./Category:A3"/> <link rel="mw:PageProp/Category" href="./Category:A4"/>
 !! end
 
 !! test
@@ -2026,7 +2027,7 @@ parsoid=wt2html
 !! wikitext
 [[Category:A1]]a
 !! html/parsoid
-<link rel="mw:PageProp/Category" href="Category:A1"/><p>a</p>
+<link rel="mw:PageProp/Category" href="./Category:A1"/><p>a</p>
 !! end
 
 ###
@@ -2056,13 +2057,28 @@ Tabs don't trigger preformatted text
         preformatted text.
  This is preformatted text.
        So is this.
-!! html
+!! html/php
 <p>    This is not
         preformatted text.
 </p>
 <pre>This is preformatted text.
        So is this.
 </pre>
+!! html/parsoid
+<p>    This is not
+        preformatted text.</p>
+<pre>This is preformatted text.
+       So is this.</pre>
+!! end
+
+!! test
+Space before tab needs nowiki pre protection
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>    a</p>
+!! wikitext
+<nowiki> </nowiki>     a
 !! end
 
 !! test
@@ -2343,13 +2359,17 @@ HTML pre followed by indent-pre
 </pre>
 !! end
 
+# Note that tidy removes the empty <p> tags from the start and end.
+# Parsoid does not, by design.
 !!test
 Block tag pre
-!!options
-parsoid
 !! wikitext
 <p><pre>foo</pre></p>
-!! html
+!! html/php+tidy
+<pre>
+foo
+</pre>
+!! html/parsoid
 <p data-parsoid='{"stx":"html","autoInsertedEnd":true}'></p><pre data-parsoid='{"stx":"html"}'>foo</pre><p data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p>
 !!end
 
@@ -2472,6 +2492,19 @@ Templates: Indent-Pre: 1f: Wrapping should be based on expanded content
 </pre>
 !!end
 
+!! test
+Pres with newline attributes
+!! wikitext
+<pre class="one
+two">hi</pre>
+!! html/php
+<pre class="one two">hi</pre>
+
+!! html/parsoid
+<pre class="one
+two" data-parsoid='{"stx":"html"}'>hi</pre>
+!! end
+
 !! test
 Things that look like <pre> tags aren't treated as such
 !! wikitext
@@ -2511,7 +2544,10 @@ Parsoid: handle pre with space after attribute
 parsoid=wt2html
 !! wikitext
 <pre style="width:50%;" >{{echo|foo}}</pre>
-!! html
+!! html/php
+<pre style="width:50%;">{{echo|foo}}</pre>
+
+!! html/parsoid
 <pre style="width:50%;">{{echo|foo}}</pre>
 !! end
 
@@ -2717,32 +2753,32 @@ Templates: Other wikitext in parameter names (bug 67657)
 #--------------------------------------------------------------------
 !! test
 Templates: Parsoid parameter escaping test 1
-!! options
-parsoid
 !! wikitext
 {{echo|[foo]|{{echo|[bar]}}}}
-!! html
+!! html/php+tidy
+<p>[foo]</p>
+!! html/parsoid
 <p about="#mwt1" typeof="mw:Transclusion"
 data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[foo]"},"2":{"wt":"{{echo|[bar]}}"}},"i":0}}]}'>[foo]</p>
 !! end
 
 !! test
 Parsoid: Pipes in external links in template parameter
-!! options
-parsoid
 !! wikitext
 {{echo|[{{echo|http://example.com}} link]}}
-!! html
+!! html/php+tidy
+<p><a rel="nofollow" class="external text" href="http://example.com">link</a></p>
+!! html/parsoid
 <p><a rel="mw:ExtLink" href="http://example.com" about="#mwt31" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[{{echo|http://example.com}} link]"}},"i":0}}]}'>link</a></p>
 !! end
 
 !! test
 Parsoid: pipe in transclusion parameter
-!! options
-parsoid
 !! wikitext
 {{echo|http://foo.com/a&#124;b}}
-!! html
+!! html/php+tidy
+<p><a rel="nofollow" class="external free" href="http://foo.com/a%7Cb">http://foo.com/a%7Cb</a></p>
+!! html/parsoid
 <p><a rel="mw:ExtLink" href="http://foo.com/a|b" about="#mwt1"
 typeof="mw:Transclusion"
 data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"http://foo.com/a&amp;#124;b"}},"i":0}}]}'>http://foo.com/a|b</a></p>
@@ -2754,7 +2790,9 @@ Parsoid: Pipe in external link target and content in template parameter
 parsoid=html2wt,wt2wt
 !! wikitext
 {{echo|[http://foo.com/a&#124;b a&#124;b]}}
-!! html
+!! html/php+tidy
+<p><a rel="nofollow" class="external text" href="http://foo.com/a%7Cb">a|b</a></p>
+!! html/parsoid
 <p><a rel="mw:ExtLink" href="http://foo.com/a|b" about="#mwt1"
 typeof="mw:Transclusion"
 data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},
@@ -2779,7 +2817,9 @@ parsoid=html2wt,wt2wt
 {{echo|foo<nowiki>|</nowiki>bar}}
 {{echo|<nowiki>&lt;div&gt;</nowiki>}}
 {{echo|<nowiki></nowiki>}}
-!! html
+!! html/php+tidy
+<p>foo|bar &lt;div&gt;</p>
+!! html/parsoid
 <p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo<nowiki>|</nowiki>bar"}},"i":0}}]}'}'>foo</span><span typeof="mw:Nowiki" about="#mwt1">|</span><span about="#mwt1">bar</span>
 <span typeof="mw:Transclusion mw:Nowiki" about="#mwt2" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<nowiki>&amp;lt;div&amp;gt;</nowiki>"}},"i":0}}]}'><span typeof="mw:Entity">&lt;</span>div<span typeof="mw:Entity">&gt;</span></span>
 <span typeof="mw:Transclusion mw:Nowiki" about="#mwt3" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<nowiki></nowiki>"}},"i":0}}]}'></span>
@@ -2793,18 +2833,20 @@ Templates: '=' char in nested transclusions should not trigger nowiki escapes or
 parsoid=html2wt,wt2wt
 !! wikitext
 {{echo|{{echo|1=bar}}}}
-!! html
+!! html/php+tidy
+<p>bar</p>
+!! html/parsoid
 <p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{echo|1=bar}}"}},"i":0}}]}'>bar</p>
 !! end
 
 ## Bug 56733
 !! test
 Templates parameters with special tokenizing behavior dont get modified because of arg escaping
-!! options
-parsoid
 !! wikitext
 {{echo|a : b}}
-!! html
+!! html/php+tidy
+<p>a&#160;: b</p>
+!! html/parsoid
 <p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a : b"}},"i":0}}]}'>a<span typeof="mw:DisplaySpace mw:Placeholder" data-parsoid='{"isDisplayHack":true}'> </span>: b</p>
 !! end
 
@@ -2813,9 +2855,8 @@ parsoid
 Templates: Preserve blank parameter names
 !! wikitext
 {{echo|=foo}}
-!! html/php
-<p>{{{1}}}
-</p>
+!! html/php+tidy
+<p>{{{1}}}</p>
 !! html/parsoid
 <p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"":{"wt":"foo"}},"i":0}}]}'>{{{1}}}</p>
 !! end
@@ -2824,10 +2865,8 @@ Templates: Preserve blank parameter names
 Templates: Preserve blank parameter names in other positions
 !! wikitext
 {{blank_param|bar|=foo}}
-!! html/php
-<p>bar
-foo
-</p>
+!! html/php+tidy
+<p>bar foo</p>
 !! html/parsoid
 <p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]},{"k":"","named":true,"spc":["","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"blank_param","href":"./Template:Blank_param"},"params":{"1":{"wt":"bar"},"":{"wt":"foo"}},"i":0}}]}'>bar
 foo</p>
@@ -3283,6 +3322,7 @@ parsoid=wt2html,wt2wt
 !! wikitext
  [[Category:foo]] <!-- No pre-wrapping -->
 {{echo| [[Category:foo]]}} <!-- No pre-wrapping -->
+!! html/php+tidy
 !! html/parsoid
  <link rel="mw:PageProp/Category" href="./Category:Foo"> <!-- No pre&#x2D;wrapping -->
 <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":" [[Category:foo]]"}},"i":0}}]}'> </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1"> <!-- No pre&#x2D;wrapping -->
@@ -3306,6 +3346,8 @@ Indent-Pre: Newlines in comments shouldn't affect sol state
 a <!--
 foo
 --> b
+!! html/php+tidy
+<p>a b</p>
 !! html/parsoid
 <p>a <!--
 foo
@@ -3335,8 +3377,10 @@ foo
 
 foo
 </pre>
-!! html
-<pre>foo</pre>
+!! html/php+tidy
+<pre>
+foo
+</pre>
 <pre>
 foo
 </pre>
@@ -3349,7 +3393,6 @@ foo
 
 foo
 </pre>
-
 !! html/parsoid
 <pre data-parsoid='{"stx":"html"}'>foo</pre>
 
@@ -3388,7 +3431,7 @@ haha
 
 
 </pre>
-!! html
+!! html/php+tidy
 <pre>
 
 
@@ -3405,7 +3448,6 @@ haha
 
 
 </pre>
-
 !! html/parsoid
 <pre data-parsoid='{"stx":"html"}'>
 
@@ -3787,7 +3829,7 @@ Definition Lists: Hacky use to indent tables (WS-insensitive)
 ##
 ## All Parsoid only definition list tests have this difference.
 ##
-## See also: https://bugzilla.wikimedia.org/show_bug.cgi?id=6569
+## See also: https://phabricator.wikimedia.org/T8569
 ## and http://lists.wikimedia.org/pipermail/wikitext-l/2011-November/000483.html
 
 !! test
@@ -3877,12 +3919,19 @@ parsoid
 
 !! test
 Definition Lists: Nesting: Test 2 (Parsoid only)
-!! options
-parsoid
 !! wikitext
 ;t1
 ::d2
-!! html
+!! html/php+tidy
+<dl>
+<dt>t1</dt>
+<dd>
+<dl>
+<dd>d2</dd>
+</dl>
+</dd>
+</dl>
+!! html/parsoid
 <dl>
   <dt>t1</dt>
   <dd>
@@ -3897,12 +3946,27 @@ parsoid
 
 !! test
 Definition Lists: Nesting: Test 3 (Parsoid only)
-!! options
-parsoid
 !! wikitext
 :;t1
 ::::d2
-!! html
+!! html/php+tidy
+<dl>
+<dd>
+<dl>
+<dt>t1</dt>
+<dd>
+<dl>
+<dd>
+<dl>
+<dd>d2</dd>
+</dl>
+</dd>
+</dl>
+</dd>
+</dl>
+</dd>
+</dl>
+!! html/parsoid
 <dl>
   <dd>
     <dl>
@@ -5185,38 +5249,6 @@ External link containing a single quote. (bug 63947)
 <p><a rel="mw:ExtLink" href="//foo.org/bar'baz">bang</a></p>
 !! end
 
-
-!! test
-External link containing a period in the anchor. (bug 63947)
-!! wikitext
-[//foo.org/bar#baz. bang]
-
-[//foo.org/bar. bang]
-!! html/php
-<p><a rel="nofollow" class="external text" href="//foo.org/bar#baz.">bang</a>
-</p><p><a rel="nofollow" class="external text" href="//foo.org/bar.">bang</a>
-</p>
-!! html/parsoid
-<p><a rel="mw:ExtLink" href="//foo.org/bar#baz.">bang</a></p>
-<p><a rel="mw:ExtLink" href="//foo.org/bar.">bang</a></p>
-!! end
-
-!! test
-External link containing a single quote. (bug 63947)
-!! wikitext
-[//foo.org/bar'baz]
-
-[//foo.org/bar'baz bang]
-!! html/php
-<p><a rel="nofollow" class="external autonumber" href="//foo.org/bar'baz">[1]</a>
-</p><p><a rel="nofollow" class="external text" href="//foo.org/bar'baz">bang</a>
-</p>
-!! html/parsoid
-<p><a rel="mw:ExtLink" href="//foo.org/bar'baz"></a></p>
-<p><a rel="mw:ExtLink" href="//foo.org/bar'baz">bang</a></p>
-!! end
-
-
 !! test
 External link containing double-single-quotes in text '' (bug 4598 sanity check)
 !! wikitext
@@ -5252,9 +5284,22 @@ External link containing double-single-quotes with no space separating the url f
 External link with comments in link text
 !! wikitext
 [http://www.google.com Google <!-- comment -->]
-!! html
+!! html/php
 <p><a rel="nofollow" class="external text" href="http://www.google.com">Google </a>
 </p>
+!! html/parsoid
+<p><a rel="mw:ExtLink" href="http://www.google.com">Google <!-- comment --></a></p>
+!! end
+
+!! test
+External link to bare IPv4 address
+!! wikitext
+[http://192.168.0.1 Link]
+!! html/php
+<p><a rel="nofollow" class="external text" href="http://192.168.0.1">Link</a>
+</p>
+!! html/parsoid
+<p><a rel="mw:ExtLink" href="http://192.168.0.1">Link</a></p>
 !! end
 
 !! test
@@ -5292,14 +5337,129 @@ http://example.com/index.php?foozoid&#x5B;&#x5D;=bar
 !! end
 
 !! test
-IPv6 urls (bug 21261)
-!! options
-disabled
+IPv6 urls, autolink format (T23261)
 !! wikitext
 http://[2404:130:0:1000::187:2]/index.php
-!! html
+
+Examples from RFC 2373, section 2.2:
+* http://[1080::8:800:200C:417A]/unicast
+* http://[FF01::101]/multicast
+* http://[::1]/loopback
+* http://[::]/unspecified
+* http://[::13.1.68.3]/ipv4compat
+* http://[::FFFF:129.144.52.38]/ipv4compat
+
+Examples from RFC 2732, section 2:
+* http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html
+* http://[1080:0:0:0:8:800:200C:417A]/index.html
+* http://[3ffe:2a00:100:7031::1]
+* http://[1080::8:800:200C:417A]/foo
+* http://[::192.9.5.5]/ipng
+* http://[::FFFF:129.144.52.38]:80/index.html
+* http://[2010:836B:4179::836B:4179]
+
+!! html/php
 <p><a rel="nofollow" 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><p>Examples from <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc2373">RFC 2373</a>, section 2.2:
+</p>
+<ul><li> <a rel="nofollow" class="external free" href="http://[1080::8:800:200C:417A]/unicast">http://[1080::8:800:200C:417A]/unicast</a></li>
+<li> <a rel="nofollow" class="external free" href="http://[FF01::101]/multicast">http://[FF01::101]/multicast</a></li>
+<li> <a rel="nofollow" class="external free" href="http://[::1]/loopback">http://[::1]/loopback</a></li>
+<li> <a rel="nofollow" class="external free" href="http://[::]/unspecified">http://[::]/unspecified</a></li>
+<li> <a rel="nofollow" class="external free" href="http://[::13.1.68.3]/ipv4compat">http://[::13.1.68.3]/ipv4compat</a></li>
+<li> <a rel="nofollow" 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 class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc2732">RFC 2732</a>, section 2:
+</p>
+<ul><li> <a rel="nofollow" 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="nofollow" 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="nofollow" class="external free" href="http://[3ffe:2a00:100:7031::1]">http://[3ffe:2a00:100:7031::1]</a></li>
+<li> <a rel="nofollow" class="external free" href="http://[1080::8:800:200C:417A]/foo">http://[1080::8:800:200C:417A]/foo</a></li>
+<li> <a rel="nofollow" class="external free" href="http://[::192.9.5.5]/ipng">http://[::192.9.5.5]/ipng</a></li>
+<li> <a rel="nofollow" class="external free" href="http://[::FFFF:129.144.52.38]:80/index.html">http://[::FFFF:129.144.52.38]:80/index.html</a></li>
+<li> <a rel="nofollow" class="external free" href="http://[2010:836B:4179::836B:4179]">http://[2010:836B:4179::836B:4179]</a></li></ul>
+
+!! html/parsoid
+<p><a rel="mw:ExtLink" 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="//tools.ietf.org/html/rfc2373" rel="mw:ExtLink">RFC 2373</a>, section 2.2:</p>
+<ul><li> <a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/unicast">http://[1080::8:800:200C:417A]/unicast</a></li>
+<li> <a rel="mw:ExtLink" href="http://[FF01::101]/multicast">http://[FF01::101]/multicast</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::1]/loopback">http://[::1]/loopback</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::]/unspecified">http://[::]/unspecified</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::13.1.68.3]/ipv4compat">http://[::13.1.68.3]/ipv4compat</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]/ipv4compat">http://[::FFFF:129.144.52.38]/ipv4compat</a></li></ul>
+
+<p>Examples from <a href="//tools.ietf.org/html/rfc2732" rel="mw:ExtLink">RFC 2732</a>, section 2:</p>
+<ul><li> <a rel="mw:ExtLink" 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" 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" href="http://[3ffe:2a00:100:7031::1]">http://[3ffe:2a00:100:7031::1]</a></li>
+<li> <a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/foo">http://[1080::8:800:200C:417A]/foo</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::192.9.5.5]/ipng">http://[::192.9.5.5]/ipng</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]:80/index.html">http://[::FFFF:129.144.52.38]:80/index.html</a></li>
+<li> <a rel="mw:ExtLink" href="http://[2010:836B:4179::836B:4179]">http://[2010:836B:4179::836B:4179]</a></li></ul>
+!! end
+
+!! test
+IPv6 urls, bracketed format (T23261)
+!! wikitext
+[http://[2404:130:0:1000::187:2]/index.php test]
+
+Examples from RFC 2373, section 2.2:
+* [http://[1080::8:800:200C:417A] unicast]
+* [http://[FF01::101] multicast]
+* [http://[::1]/ loopback]
+* [http://[::] unspecified]
+* [http://[::13.1.68.3] ipv4compat]
+* [http://[::FFFF:129.144.52.38] ipv4compat]
+
+Examples from RFC 2732, section 2:
+* [http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html 1]
+* [http://[1080:0:0:0:8:800:200C:417A]/index.html 2]
+* [http://[3ffe:2a00:100:7031::1] 3]
+* [http://[1080::8:800:200C:417A]/foo 4]
+* [http://[::192.9.5.5]/ipng 5]
+* [http://[::FFFF:129.144.52.38]:80/index.html 6]
+* [http://[2010:836B:4179::836B:4179] 7]
+
+!! html/php
+<p><a rel="nofollow" class="external text" href="http://[2404:130:0:1000::187:2]/index.php">test</a>
+</p><p>Examples from <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc2373">RFC 2373</a>, section 2.2:
+</p>
+<ul><li> <a rel="nofollow" class="external text" href="http://[1080::8:800:200C:417A]">unicast</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[FF01::101]">multicast</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[::1]/">loopback</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[::]">unspecified</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[::13.1.68.3]">ipv4compat</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[::FFFF:129.144.52.38]">ipv4compat</a></li></ul>
+<p>Examples from <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc2732">RFC 2732</a>, section 2:
+</p>
+<ul><li> <a rel="nofollow" class="external text" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html">1</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[1080:0:0:0:8:800:200C:417A]/index.html">2</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[3ffe:2a00:100:7031::1]">3</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[1080::8:800:200C:417A]/foo">4</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[::192.9.5.5]/ipng">5</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[::FFFF:129.144.52.38]:80/index.html">6</a></li>
+<li> <a rel="nofollow" class="external text" href="http://[2010:836B:4179::836B:4179]">7</a></li></ul>
+
+!! html/parsoid
+<p><a rel="mw:ExtLink" href="http://[2404:130:0:1000::187:2]/index.php">test</a></p>
+
+<p>Examples from <a href="//tools.ietf.org/html/rfc2373" rel="mw:ExtLink">RFC 2373</a>, section 2.2:</p>
+<ul><li> <a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]">unicast</a></li>
+<li> <a rel="mw:ExtLink" href="http://[FF01::101]">multicast</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::1]/">loopback</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::]">unspecified</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::13.1.68.3]">ipv4compat</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]">ipv4compat</a></li></ul>
+
+<p>Examples from <a href="//tools.ietf.org/html/rfc2732" rel="mw:ExtLink">RFC 2732</a>, section 2:</p>
+<ul><li> <a rel="mw:ExtLink" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html">1</a></li>
+<li> <a rel="mw:ExtLink" href="http://[1080:0:0:0:8:800:200C:417A]/index.html">2</a></li>
+<li> <a rel="mw:ExtLink" href="http://[3ffe:2a00:100:7031::1]">3</a></li>
+<li> <a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/foo">4</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::192.9.5.5]/ipng">5</a></li>
+<li> <a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]:80/index.html">6</a></li>
+<li> <a rel="mw:ExtLink" href="http://[2010:836B:4179::836B:4179]">7</a></li></ul>
 !! end
 
 !! test
@@ -5317,7 +5477,8 @@ Non-extlinks in brackets
 [{{echo|foo}}l's errand]
 [url={{echo|foo}}]
 [url=http://example.com]
-!! html
+[http:// bare protocols don't count]
+!! html/php
 <p>[foo]
 [foo bar]
 [foo <i>bar</i>]
@@ -5330,7 +5491,22 @@ Non-extlinks in brackets
 [fool's errand]
 [url=foo]
 [url=<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>]
+[http:// bare protocols don't count]
 </p>
+!! html/parsoid
+<p>[foo]
+[foo bar]
+[foo <i>bar</i>]
+[fool's] errand
+[fool's errand]
+[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}"}'>foo</span>]
+[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}"}'>foo</span> bar]
+[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}"}'>foo</span> <i>bar</i>]
+[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}l&#39;s"}'>fool's</span>] errand
+[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}l&#39;s"}'>fool's</span> errand]
+[<span typeof="mw:Placeholder" data-parsoid='{"src":"url={{echo|foo}}"}'>url=foo</span>]
+[url=<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>]
+[http:// bare protocols don't count]</p>
 !! end
 
 !! test
@@ -5415,7 +5591,7 @@ Parenthesis in external links, w/ transclusion or comment
 Serialize <a> tags with invalid link targets as plain text
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a rel="mw:WikiLink" href="[[foo]]">text</a>
 <a rel="mw:WikiLink" href="[[foo]]">*text</a>
 <a rel="mw:WikiLink" href="[[foo]]">[[foo]]</a>
@@ -5535,7 +5711,7 @@ Plain ''italic'''s plain
 ###
 ### Tables
 ###
-### some content taken from http://meta.wikimedia.org/wiki/MediaWiki_User%27s_Guide:_Using_tables
+### some content taken from http://meta.wikimedia.org/wiki/MediaWiki_User's_Guide:_Using_tables
 ###
 
 # This should not produce <table></table> as <table><tr><td></td></tr></table>
@@ -6679,7 +6855,7 @@ parsoid=wt2html,wt2wt
 Parsoid: Default to a newline after tables in new content (bug 51219)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <table><tbody>
 <tr><td>foo</td></tr></tbody></table> bar
 <table><tbody>
@@ -6699,7 +6875,7 @@ parsoid=html2wt
 Parsoid: newline inducing block nodes don't suppress <nowiki>
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
  a<h1>foo</h1>
 !! wikitext
 <nowiki> </nowiki>a
@@ -6733,9 +6909,6 @@ parsoid=wt2html,wt2wt
 </tbody></table>
 !! end
 
-
-# PHP throws away the (semi-broken) "foo" class here; Parsoid
-# preserves it.
 !!test
 Parsoid: Recover better from broken table attributes
 !!options
@@ -6746,7 +6919,7 @@ parsoid=wt2html
 foo
 |}
 !!html/php+tidy
-<table>
+<table class="foo">
 <tr>
 <td class="bar">
 <p>foo</p>
@@ -6761,11 +6934,28 @@ foo
 </tbody></table>
 !!end
 
+!! test
+Tables: Digest broken attributes on table and tr tag
+!! options
+parsoid=wt2html
+!! wikitext
+{| || |} ++
+|- || || ++ --
+|- > [
+|}
+!! html
+<table>
+<tbody>
+<tr></tr>
+<tr></tr>
+</tbody></table>
+!! end
+
 !! test
 Strip unsupported table tags
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <table>
 <thead>
 <tr>
@@ -7070,7 +7260,7 @@ Namespace takes precedence over interwiki link (bug 51680)
 Link to namespace preferred over interwiki with correct rel attribute
 !! options
 parsoid=html2wt,html2html
-!! html
+!! html/parsoid
 <p><a rel="mw:WikiLink" href="./MemoryAlpha:AlphaTest" title="MemoryAlpha:AlphaTest">MemoryAlpha:AlphaTest</a></p>
 !! wikitext
 [[MemoryAlpha:AlphaTest]]
@@ -7195,7 +7385,7 @@ Link containing double-single-quotes '' (bug 4598)
 !! wikitext
 [[Lista d''e paise d''o munno]]
 !! html/php
-<p><a href="/index.php?title=Lista_d%27%27e_paise_d%27%27o_munno&amp;action=edit&amp;redlink=1" class="new" title="Lista d''e paise d''o munno (page does not exist)">Lista d''e paise d''o munno</a>
+<p><a href="/index.php?title=Lista_d''e_paise_d''o_munno&amp;action=edit&amp;redlink=1" class="new" title="Lista d''e paise d''o munno (page does not exist)">Lista d''e paise d''o munno</a>
 </p>
 !! html/parsoid
 <p><a rel="mw:WikiLink" href="./Lista_d''e_paise_d''o_munno" title="Lista d''e paise d''o munno">Lista d''e paise d''o munno</a></p>
@@ -7232,10 +7422,10 @@ Link with double quotes in title part (literal) and alternate part (interpreted)
 
 [[''Pentecoste''|''Pentecoste'']]
 !! html/php
-<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Denys_Savchenko_%27%27Pentecoste%27%27.jpg" class="new" title="File:Denys Savchenko &#39;&#39;Pentecoste&#39;&#39;.jpg">File:Denys Savchenko <i>Pentecoste</i>.jpg</a>
-</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">''Pentecoste''</a>
-</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">Pentecoste</a>
-</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)"><i>Pentecoste</i></a>
+<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Denys_Savchenko_&#39;&#39;Pentecoste&#39;&#39;.jpg" class="new" title="File:Denys Savchenko &#39;&#39;Pentecoste&#39;&#39;.jpg">File:Denys Savchenko <i>Pentecoste</i>.jpg</a>
+</p><p><a href="/index.php?title=''Pentecoste''&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">''Pentecoste''</a>
+</p><p><a href="/index.php?title=''Pentecoste''&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">Pentecoste</a>
+</p><p><a href="/index.php?title=''Pentecoste''&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)"><i>Pentecoste</i></a>
 </p>
 !! html/parsoid
 <p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:Denys_Savchenko_''Pentecoste''.jpg"><img resource="./File:Denys_Savchenko_''Pentecoste''.jpg" src="./Special:FilePath/Denys_Savchenko_''Pentecoste''.jpg" height="220" width="220"/></a></span></p>
@@ -7258,10 +7448,10 @@ Broken image links with HTML captions (bug 39700)
 <a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">abc</a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&lt;script>&lt;/script>"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span>
-<span typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&lt;script>&lt;/script>"}'><a href="./File:Nonexistent" data-parsoid='{"a":{"href":"./File:Nonexistent"},"sa":{}}'><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="100" width="100"/></a></span>
-<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&amp;lt;"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span>
-<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"a&lt;i>b&lt;/i>c"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span></p>
+<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span>
+<span typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="100" width="100"/></a></span>
+<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&lt;span typeof=\"mw:Entity\" data-parsoid=\"{&amp;quot;src&amp;quot;:&amp;quot;&amp;amp;lt;&amp;quot;,&amp;quot;srcContent&amp;quot;:&amp;quot;&lt;&amp;quot;,&amp;quot;dsr&amp;quot;:[107,111,null,null]}\">&amp;lt;&lt;/span>"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span>
+<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"a&lt;i data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[134,142,3,4]}\">b&lt;/i>c"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span></p>
 !! end
 
 !! test
@@ -7578,7 +7768,7 @@ mótmælenda[[söfnuður|söfnuðir]]xxx
 Parsoid link trail escaping
 !! options
 parsoid=html2wt,html2html
-!! html
+!! html/parsoid
 <p><a rel="mw:WikiLink" href="Apple" title="Apple">apple</a>s</p>
 !! wikitext
 [[apple]]<nowiki/>s
@@ -7589,7 +7779,7 @@ Parsoid link prefix escaping
 !! options
 language=is
 parsoid=html2wt,html2html
-!! html
+!! html/parsoid
 <p>Aðrir mótmælenda<a rel="mw:WikiLink" href="Söfnuður" title="Söfnuður">söfnuður</a></p>
 !! wikitext
 Aðrir mótmælenda<nowiki/>[[söfnuður]]
@@ -7974,7 +8164,7 @@ language=ln
 Parsoid bug 53221: Wikilinks should be properly entity-escaped
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>He&amp;nbsp;llo <a href="Foo" rel="mw:WikiLink">He&amp;nbsp;llo</a></p>
 <p>He&amp;nbsp;llo <a href="He&amp;nbsp;llo" rel="mw:WikiLink">He&amp;nbsp;llo</a></p>
 !! wikitext
@@ -8080,7 +8270,7 @@ Blah blah blah
 </p>
 !! html/parsoid
 <p>Blah blah blah
-<a rel="mw:WikiLink" href="Template:Foo" title="Template:Foo">mi:Template:Foo</a></p>
+<a rel="mw:WikiLink" href="./Template:Foo" title="Template:Foo">mi:Template:Foo</a></p>
 !! end
 
 ###
@@ -9720,7 +9910,7 @@ parsoid=wt2wt,html2wt
 foo
 __NOTOC__
 bar
-!! html
+!! html/parsoid
 foo<meta property="mw:PageProp/notoc"/>bar
 !! end
 
@@ -9731,7 +9921,7 @@ parsoid=wt2wt
 language=de
 !! wikitext
 __NOEDITSECTION__
-!! html
+!! html/parsoid
 <meta property="mw:PageProp/noeditsection" data-parsoid='{"magicSrc":"__NOEDITSECTION__"}'/>
 !! end
 
@@ -9751,27 +9941,33 @@ __proto__
 Magic links: internal link to RFC (bug 479)
 !! wikitext
 [[RFC 123]]
-!! html
+!! html/php
 <p><a href="/index.php?title=RFC_123&amp;action=edit&amp;redlink=1" class="new" title="RFC 123 (page does not exist)">RFC 123</a>
 </p>
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="./RFC_123" title="RFC 123">RFC 123</a></p>
 !! end
 
 !! test
 Magic links: RFC (bug 479)
 !! wikitext
 RFC 822
-!! html
+!! html/php
 <p><a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc822">RFC 822</a>
 </p>
+!! html/parsoid
+<p><a href="//tools.ietf.org/html/rfc822" rel="mw:ExtLink">RFC 822</a></p>
 !! end
 
 !! test
 Magic links: RFC (bug 65278)
 !! wikitext
 This is RFC 822 but thisRFC 822 is not RFC 822linked.
-!! html
+!! html/php
 <p>This is <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc822">RFC 822</a> but thisRFC 822 is not RFC 822linked.
 </p>
+!! html/parsoid
+<p>This is <a href="//tools.ietf.org/html/rfc822" rel="mw:ExtLink">RFC 822</a> but thisRFC 822 is not RFC 822linked.</p>
 !! end
 
 !! test
@@ -9780,20 +9976,26 @@ Magic links: RFC (w/ non-newline whitespace, bug 28950/29025)
 RFC &nbsp;&#160;&#0160;&#xA0;&#Xa0; 822
 RFC
 822
-!! html
+!! html/php
 <p><a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc822">RFC 822</a>
 RFC
 822
 </p>
+!! html/parsoid
+<p><a href="//tools.ietf.org/html/rfc822" rel="mw:ExtLink">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
 
 !! test
 Magic links: ISBN (bug 1937)
 !! wikitext
 ISBN 0-306-40615-2
-!! html
+!! html/php
 <p><a href="/wiki/Special:BookSources/0306406152" class="internal mw-magiclink-isbn">ISBN 0-306-40615-2</a>
 </p>
+!! html/parsoid
+<p><a href="./Special:BookSources/0306406152" rel="mw:WikiLink">ISBN 0-306-40615-2</a></p>
 !! end
 
 !! test
@@ -9804,7 +10006,7 @@ This is ISBN 978-0-316-09811-3 but thisISBN 978-0-316-09811-3 is not ISBN 978-0-
 <p>This is <a href="/wiki/Special:BookSources/9780316098113" class="internal mw-magiclink-isbn">ISBN 978-0-316-09811-3</a> but thisISBN 978-0-316-09811-3 is not ISBN 978-0-316-09811-3linked.
 </p>
 !! html/parsoid
-<p>This is <a href="./Special:BookSources/9780316098113" rel="mw:ExtLink">ISBN 978-0-316-09811-3</a> but thisISBN 978-0-316-09811-3 is not ISBN 978-0-316-09811-3linked.</p>
+<p>This is <a href="./Special:BookSources/9780316098113" rel="mw:WikiLink">ISBN 978-0-316-09811-3</a> but thisISBN 978-0-316-09811-3 is not ISBN 978-0-316-09811-3linked.</p>
 !! end
 
 !! test
@@ -9815,31 +10017,41 @@ ISBN
 9780316098113
 ISBN 978
 0316098113
-!! html
+!! html/php
 <p><a href="/wiki/Special:BookSources/9780316098113" class="internal mw-magiclink-isbn">ISBN 978 0 316 09811 3</a>
 ISBN
 9780316098113
 ISBN 978
 0316098113
 </p>
+!! html/parsoid
+<p><a href="./Special:BookSources/9780316098113" rel="mw:WikiLink">ISBN <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> 978<span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>0<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span>316<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span>09811<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span>3</a>
+ISBN
+9780316098113
+ISBN 978
+0316098113</p>
 !! end
 
 !! test
 Magic links: PMID incorrectly converts space to underscore
 !! wikitext
 PMID 1234
-!! html
+!! html/php
 <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">PMID 1234</a></p>
 !! end
 
 !! test
 Magic links: PMID (bug 65278)
 !! wikitext
 This is PMID 1234 but thisPMID 1234 is not PMID 1234linked.
-!! html
+!! html/php
 <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">PMID 1234</a> but thisPMID 1234 is not PMID 1234linked.</p>
 !! end
 
 !! test
@@ -9848,11 +10060,15 @@ Magic links: PMID (w/ non-newline whitespace, bug 28950/29025)
 PMID &nbsp;&#160;&#0160;&#xA0;&#Xa0; 1234
 PMID
 1234
-!! html
+!! html/php
 <p><a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a>
 PMID
 1234
 </p>
+!! html/parsoid
+<p><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink">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
 
 ###
@@ -10321,6 +10537,7 @@ Template:MSGNW test
 <gallery>
 File:Foobar.jpg
 </gallery>
+<!-- comment -->
 !! endarticle
 
 # hmm, fix this or just deprecate msgnw and document its behavior?
@@ -10336,6 +10553,7 @@ msgnw keyword
 &#60;gallery&#62;
 File:Foobar.jpg
 &#60;/gallery&#62;
+&#60;!-- comment --&#62;
 </p>
 !! end
 
@@ -10348,6 +10566,15 @@ int keyword
 </p>
 !! end
 
+!! test
+int keyword - non-existing message
+!! wikitext
+{{int:var}}
+!! html
+<p>&lt;var&gt;
+</p>
+!! end
+
 !! article
 Template:Includes
 !! text
@@ -10589,7 +10816,7 @@ b}}
 !! end
 
 !! test
-Parsoid: Merge double tds (bug 50603)
+Parsoid: Merge double tds (T52603)
 !! options
 parsoid
 !! wikitext
@@ -10603,7 +10830,7 @@ parsoid
 !! end
 
 !! test
-Parsoid: Merge double tds in nested transclusion content (bug 50603)
+Parsoid: Merge double tds in nested transclusion content (T52603)
 !! options
 parsoid
 !! wikitext
@@ -12146,7 +12373,7 @@ parsoid=wt2html
 Parsoid: Escape nowiki with trailing space in tags
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>&lt;nowiki &gt; foo &lt/nowiki ></p>
 <p>a&lt;nowiki /&gt;b</p>
 <p>c&lt;nowiki/ &gt;d</p>
@@ -12162,7 +12389,7 @@ c&lt;nowiki/ &gt;d
 Parsoid: Escape weird noWikI capitalizations
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>&lt;noWikI &gt; foo &lt/NoWikI ></p>
 !! wikitext
 &lt;noWikI &gt; foo &lt;/NoWikI &gt;
@@ -12603,6 +12830,21 @@ Image with link parameter, protocol-less URL target
 <p><span class="mw-default-size" typeof="mw:Image"><a href="//example.com/"><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></span></p>
 !! end
 
+!! test
+Escaping non-block captions (T107435)
+!! options
+parsoid={
+  "modes": ["wt2wt"],
+  "changes": [
+    ["[typeof~='mw:Image']", "attr", "data-mw", "{\"caption\": \"|\"}"]
+  ]
+}
+!! wikitext
+[[Image:Foobar.jpg|caption]]
+!! wikitext/edited
+[[Image:Foobar.jpg|<nowiki>|</nowiki>]]
+!! end
+
 !! test
 Image with link parameter, wgExternalLinkTarget
 !! wikitext
@@ -12791,8 +13033,6 @@ parsoid=wt2html,wt2wt,html2html
 
 !! test
 Image with wiki markup in implicit alt
-!! options
-parsoid=wt2html,wt2wt,html2html
 !! wikitext
 [[Image:Foobar.jpg|testing '''bold''' in alt]]
 
@@ -12802,8 +13042,8 @@ parsoid=wt2html,wt2wt,html2html
 </p><p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="testing bold in alt" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw="{&quot;caption&quot;:&quot;testing '''bold''' in alt&quot;}"><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></span></p>
-<p><span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img alt="testing bold in alt" 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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"testing &lt;b data-parsoid=\"{&amp;quot;dsr&amp;quot;:[27,37,3,3]}\">bold&lt;/b> in alt"}'><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" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"Image:Foobar.jpg"}}'/></a></span></p>
+<p><span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img alt="testing bold in alt" 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" data-parsoid='{"a":{"alt":"testing bold in alt","resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"alt":"alt=testing &#39;&#39;&#39;bold&#39;&#39;&#39; in alt","resource":"Image:Foobar.jpg"}}'/></a></span></p>
 !! end
 
 !! test
@@ -12884,7 +13124,7 @@ parsoid=wt2html,wt2wt,html2html
 ###################
 # Image sizing.
 # See https://www.mediawiki.org/wiki/Help:Images#Size_and_frame
-# and https://bugzilla.wikimedia.org/show_bug.cgi?id=62258
+# and https://phabricator.wikimedia.org/T64258
 # Foobar has actual size of 1941x220
 # 1. Thumbs & frameless always reduce, can't be enlarged unless it's
 #    a scalable format.
@@ -13041,7 +13281,7 @@ Frameless image caption with a free URL
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="http://example.com"><img alt="http://example.com" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"http://example.com"}'><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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;a rel=\"mw:ExtLink\" href=\"http://example.com\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;url&amp;quot;,&amp;quot;dsr&amp;quot;:[18,36,0,0]}\">http://example.com&lt;/a>"}'><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></span></p>
 !! end
 
 !! test
@@ -13117,7 +13357,7 @@ BUG 1887: A ISBN with a thumbnail
 <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/1235467890" class="internal mw-magiclink-isbn">ISBN 1235467890</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 href="Special:BookSources/1235467890" rel="mw:ExtLink">ISBN 1235467890</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/1235467890" rel="mw:WikiLink">ISBN 1235467890</a></figcaption></figure>
 !! end
 
 !! test
@@ -13151,7 +13391,7 @@ BUG 648: Frameless image caption with a link
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a link in it"><img alt="text with a link in it" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a [[link]] in it"}'><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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a &lt;a rel=\"mw:WikiLink\" href=\"./Link\" title=\"Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;./Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;link&amp;quot;},&amp;quot;dsr&amp;quot;:[30,38,2,2]}\">link&lt;/a> in it"}'><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></span></p>
 !! end
 
 !! test
@@ -13162,7 +13402,7 @@ BUG 648: Frameless image caption with a link (suffix)
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a linkfoo in it"><img alt="text with a linkfoo in it" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a [[link]]foo in it"}'><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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a &lt;a rel=\"mw:WikiLink\" href=\"./Link\" title=\"Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;./Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;link&amp;quot;},&amp;quot;dsr&amp;quot;:[30,41,2,5],&amp;quot;tail&amp;quot;:&amp;quot;foo&amp;quot;}\">linkfoo&lt;/a> in it"}'><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></span></p>
 !! end
 
 !! test
@@ -13173,7 +13413,7 @@ BUG 648: Frameless image caption with an interwiki link
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a MeatBall:Link in it"><img alt="text with a MeatBall:Link in it" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a [[MeatBall:Link]] in it"}'><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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a &lt;a rel=\"mw:ExtLink\" href=\"http://www.usemod.com/cgi-bin/mb.pl?Link\" title=\"meatball:Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;http://www.usemod.com/cgi-bin/mb.pl?Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;MeatBall:Link&amp;quot;},&amp;quot;isIW&amp;quot;:true,&amp;quot;dsr&amp;quot;:[30,47,2,2]}\">MeatBall:Link&lt;/a> in it"}'><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></span></p>
 !! end
 
 !! test
@@ -13184,7 +13424,15 @@ BUG 648: Frameless image caption with a piped interwiki link
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a link in it"><img alt="text with a link in it" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a [[MeatBall:Link|link]] in it"}'><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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a &lt;a rel=\"mw:ExtLink\" href=\"http://www.usemod.com/cgi-bin/mb.pl?Link\" title=\"meatball:Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;piped&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;http://www.usemod.com/cgi-bin/mb.pl?Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;MeatBall:Link&amp;quot;},&amp;quot;isIW&amp;quot;:true,&amp;quot;dsr&amp;quot;:[30,52,16,2]}\">link&lt;/a> in it"}'><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></span></p>
+!! end
+
+!! test
+T107474: Frameless image caption with <nowiki>
+!! wikitext
+[[File:Foobar.jpg|<nowiki>text with a [[MeatBall:Link|link]] in it</nowiki>]]
+!! html/parsoid
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;span typeof=\"mw:Nowiki\" data-parsoid=\"{&amp;quot;dsr&amp;quot;:[18,75,8,9]}\">text with a [[MeatBall:Link|link]] in it&lt;/span>"}'><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></span></p>
 !! end
 
 !! test
@@ -13195,7 +13443,7 @@ Escape HTML special chars in image alt text
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="&amp; &lt; &gt; &quot;"><img alt="&amp; &lt; &gt; &quot;" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&amp; &lt; > \""}'><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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&amp;amp; &amp;lt; &amp;gt; \""}'><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></span></p>
 !! end
 
 !! test
@@ -13206,7 +13454,7 @@ BUG 499: Alt text should have &#1234;, not &amp;1234;
 <p><a href="/wiki/File:Foobar.jpg" class="image" title="♀"><img alt="♀" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
 </p>
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&amp;#9792;"}'><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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;span typeof=\"mw:Entity\" data-parsoid=\"{&amp;quot;src&amp;quot;:&amp;quot;&amp;amp;#9792;&amp;quot;,&amp;quot;srcContent&amp;quot;:&amp;quot;♀&amp;quot;,&amp;quot;dsr&amp;quot;:[18,25,null,null]}\">♀&lt;/span>"}'><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></span></p>
 !! end
 
 !! test
@@ -13533,7 +13781,7 @@ Parsoid-specific image handling - simple image with a formatted caption
 !! wikitext
 [[File:Foobar.jpg|<table><tr><td>a</td><td>b</td></tr><tr><td>c</td></tr></table>]]
 !! html/parsoid
-<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;table>&lt;tr>&lt;td>a&lt;/td>&lt;td>b&lt;/td>&lt;/tr>&lt;tr>&lt;td>c&lt;/td>&lt;/tr>&lt;/table>"}'><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></span></p>
+<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;table data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[18,81,7,8]}\">&lt;tbody data-parsoid=\"{&amp;quot;dsr&amp;quot;:[25,73,0,0]}\">&lt;tr data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[25,54,4,5]}\">&lt;td data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[29,39,4,5]}\">a&lt;/td>&lt;td data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[39,49,4,5]}\">b&lt;/td>&lt;/tr>&lt;tr data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[54,73,4,5]}\">&lt;td data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[58,68,4,5]}\">c&lt;/td>&lt;/tr>&lt;/tbody>&lt;/table>"}'><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></span></p>
 !! end
 
 !! test
@@ -13607,6 +13855,42 @@ bar
 bar</p>
 !! end
 
+## Edge case bugs in Parsoid from T93580
+!! test
+T93580: 1. Templated <ref> inside block images
+!! wikitext
+[[File:Foobar.jpg|thumb|Caption with templated ref: {{echo|<ref>foo</ref>}}]]
+
+<references />
+!! html/parsoid
+<figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"caption","ak":"Caption with templated ref: {{echo|&lt;ref>foo&lt;/ref>}}"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><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 with templated ref: <span about="#mwt5" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Transclusion  mw:Extension/ref" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;ref>foo&lt;/ref>"}},"i":0}}]}'><a href="#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></span></figcaption></figure>
+
+<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#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" data-parsoid="{}">foo</span></li></ol>
+!! end
+
+!! test
+T93580: 2. <ref> inside inline images
+!! wikitext
+[[File:Foobar.jpg|Undisplayed caption in inline image with ref: <ref>foo</ref>]]
+
+<references />
+!! html/parsoid
+<p><span class="mw-default-size" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"caption","ak":"Undisplayed caption in inline image with ref: &lt;ref>foo&lt;/ref>"}]}' data-mw='{"caption":"Undisplayed caption in inline image with ref: &lt;span about=\"#mwt2\" class=\"mw-ref\" id=\"cite_ref-1\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid=\"{&amp;quot;dsr&amp;quot;:[64,78,5,6]}\" data-mw=\"{&amp;quot;name&amp;quot;:&amp;quot;ref&amp;quot;,&amp;quot;body&amp;quot;:{&amp;quot;id&amp;quot;:&amp;quot;mw-reference-text-cite_note-1&amp;quot;},&amp;quot;attrs&amp;quot;:{}}\">&lt;a href=\"#cite_note-1\" style=\"counter-reset: mw-Ref 1;\">&lt;span class=\"mw-reflink-text\">[1]&lt;/span>&lt;/a>&lt;/span>&lt;meta typeof=\"mw:Extension/ref/Marker\" about=\"#mwt2\" data-parsoid=\"{&amp;quot;group&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;content&amp;quot;:&amp;quot;foo&amp;quot;,&amp;quot;hasRefInRef&amp;quot;:false,&amp;quot;dsr&amp;quot;:[64,78,5,6],&amp;quot;tmp&amp;quot;:{}}\" data-mw=\"{}\">"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><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" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
+
+<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#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" data-parsoid="{}">foo</span></li></ol>
+!! end
+
+!! test
+T93580: 3. Templated <ref> inside inline images
+!! wikitext
+[[File:Foobar.jpg|Undisplayed caption in inline image with ref: {{echo|<ref>{{echo|foo}}</ref>}}]]
+
+<references />
+!! html/parsoid
+<p><span class="mw-default-size" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"caption","ak":"Undisplayed caption in inline image with ref: {{echo|&lt;ref>{{echo|foo}}&lt;/ref>}}"}]}' data-mw='{"caption":"Undisplayed caption in inline image with ref: &lt;span about=\"#mwt2\" class=\"mw-ref\" id=\"cite_ref-1\" rel=\"dc:references\" typeof=\"mw:Transclusion  mw:Extension/ref\" data-parsoid=\"{&amp;quot;dsr&amp;quot;:[64,96,null,null],&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;&lt;ref>{{echo|foo}}&lt;/ref>&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">&lt;a href=\"#cite_note-1\" style=\"counter-reset: mw-Ref 1;\">&lt;span class=\"mw-reflink-text\">[1]&lt;/span>&lt;/a>&lt;/span>&lt;meta typeof=\"mw:Transclusion mw:Extension/ref/Marker\" about=\"#mwt2\" data-parsoid=\"{&amp;quot;group&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;content&amp;quot;:&amp;quot;foo&amp;quot;,&amp;quot;hasRefInRef&amp;quot;:false,&amp;quot;dsr&amp;quot;:[64,96,null,null],&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;tmp&amp;quot;:{}}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;&lt;ref>{{echo|foo}}&lt;/ref>&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><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" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
+
+<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#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" data-parsoid="{}">foo</span></li></ol>
+!! end
 
 ###
 ### Subpages
@@ -13790,7 +14074,7 @@ Link to category
 !! wikitext
 [[:Category:MediaWiki User's Guide]]
 !! html
-<p><a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">Category:MediaWiki User's Guide</a>
+<p><a href="/wiki/Category:MediaWiki_User's_Guide" title="Category:MediaWiki User's Guide">Category:MediaWiki User's Guide</a>
 </p>
 !! end
 
@@ -13801,7 +14085,7 @@ cat
 !! wikitext
 [[Category:MediaWiki User's Guide]]
 !! html
-<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
+<a href="/wiki/Category:MediaWiki_User's_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
 !! end
 
 !! test
@@ -13820,7 +14104,7 @@ cat
 !! wikitext
 [[Category:MediaWiki User's Guide|Foo]]
 !! html
-<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
+<a href="/wiki/Category:MediaWiki_User's_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
 !! end
 
 !! test
@@ -13830,7 +14114,7 @@ cat
 !! wikitext
 [[Category:MediaWiki User's Guide|MediaWiki User's Guide]]
 !! html
-<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
+<a href="/wiki/Category:MediaWiki_User's_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
 !! end
 
 !! test
@@ -13986,7 +14270,7 @@ parsoid=wt2html
 !! html/parsoid
 <ul>
 <li>This <link rel="mw:PageProp/Category" href="./Category:Foo"/> and this should be part of the same list item</li>
-<li>So should this <link rel="mw:PageProp/Category" href="Category:Foo" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Category:Foo]] and this should be part of the same list item"}},"i":0}}]}'/><span> and this should be part of the same list item</span></li>
+<li>So should this <link rel="mw:PageProp/Category" href="./Category:Foo" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Category:Foo]] and this should be part of the same list item"}},"i":0}}]}'/><span> and this should be part of the same list item</span></li>
 </ul>
 !! end
 
@@ -14095,8 +14379,8 @@ parsoid
 [[:Category:Foo|Bar]]
 !! html
 <p>
-<a rel="mw:WikiLink" href="Category:Foo" title="Category:Foo">Category:Foo</a>
-<a rel="mw:WikiLink" href="Category:Foo" title="Category:Foo">Bar</a>
+<a rel="mw:WikiLink" href="./Category:Foo" title="Category:Foo">Category:Foo</a>
+<a rel="mw:WikiLink" href="./Category:Foo" title="Category:Foo">Bar</a>
 </p>
 !! end
 
@@ -14140,15 +14424,15 @@ parsoid
 [[Category:Foo]]
 [[Category:Foo|Bar]]
 !! html
-<link rel="mw:PageProp/Category" href="Category:Foo">
-<link rel="mw:PageProp/Category" href="Category:Foo#Bar">
+<link rel="mw:PageProp/Category" href="./Category:Foo">
+<link rel="mw:PageProp/Category" href="./Category:Foo#Bar">
 !! end
 
 !! test
 Normalize hrefs properly before testing for invalid link targets (bug 70894)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <link rel="mw:PageProp/Category" href="./Category:Toxine_bactérienne"/>
 !! wikitext
 [[Category:Toxine bactérienne]]
@@ -15048,11 +15332,8 @@ I always thought &xacute; was a cute letter.
 </p>
 !! end
 
-# TODO: generalize to PHP parser?
 !! test
 HTML5 tags
-!! options
-parsoid
 !! wikitext
 <data value="5">five</data>
 <time datetime="2000-01-01T00:00Z">The new millenium started</time>
@@ -15060,7 +15341,8 @@ parsoid
 !! html
 <p><data value="5">five</data>
 <time datetime="2000-01-01T00:00Z">The new millenium started</time>
-<mark>This highlighted text</mark></p>
+<mark>This highlighted text</mark>
+</p>
 !! end
 
 !! test
@@ -15684,7 +15966,7 @@ CSS line continuation 2
 !! wikitext
 <div style="background-image: u\&#13;rl(test.jpg); "></div>
 !! html
-<div style="/* insecure input */"></div>
+<div style="/* invalid control char */"></div>
 
 !! end
 
@@ -18017,6 +18299,38 @@ parsoid=wt2html,wt2wt,html2html
 <p><span typeof="mw:Entity">î</span><span typeof="mw:Entity">î</span></p>
 !! end
 
+# See: http://www.w3.org/TR/html5/syntax.html#character-references
+# Note that U+000C (form feed) is not a valid XML character, so
+# it is banned even though allowed in HTML5.
+!! test
+Illegal character references (T106578)
+!! wikitext
+; Null: &#00;
+; FF: &#xC;
+; CR: &#xD;
+; Control (low): &#8;
+; Control (high): &#x7F; &#x9F;
+; Surrogate: &#xD83D;&#xDCA9;
+; This is an okay astral character: &#x1F4A9;
+!! html+tidy
+<dl>
+<dt>Null</dt>
+<dd>&amp;#00;</dd>
+<dt>FF</dt>
+<dd>&amp;#xC;</dd>
+<dt>CR</dt>
+<dd>&amp;#xD;</dd>
+<dt>Control (low)</dt>
+<dd>&amp;#8;</dd>
+<dt>Control (high)</dt>
+<dd>&amp;#x7F; &amp;#x9F;</dd>
+<dt>Surrogate</dt>
+<dd>&amp;#xD83D;&amp;#xDCA9;</dd>
+<dt>This is an okay astral character</dt>
+<dd>💩</dd>
+</dl>
+!! end
+
 !! test
 __FORCETOC__ override
 !! wikitext
@@ -18037,7 +18351,7 @@ ISBN  978-0-1234-56&#x20;789
 !! html+tidy
 <p><a href="/wiki/Special:BookSources/9780123456" class="internal mw-magiclink-isbn">ISBN 978-0-1234-56</a> 789</p>
 !! html/parsoid
-<p><a href="./Special:BookSources/9780123456" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 978-0-1234-56</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#x20;","srcContent":" "}'> </span>789</p>
+<p><a href="./Special:BookSources/9780123456" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 978-0-1234-56</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#x20;","srcContent":" "}'> </span>789</p>
 !! end
 
 !! test
@@ -18057,24 +18371,34 @@ ISBN ISBN 1234567890
 <p>ISBN <a href="/wiki/Special:BookSources/1234567890" class="internal mw-magiclink-isbn">ISBN 1234567890</a>
 </p>
 !! html/parsoid
-<p>ISBN <a href="./Special:BookSources/1234567890" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a></p>
+<p>ISBN <a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a></p>
 !! end
 
+# Uppercase X and lowercase x as well
 !! test
 ISBN with an X
 !! wikitext
 ISBN 3-462-04561-X
+ISBN 3-462-04561-x
 ISBN 080442957X
+ISBN 080442957x
 ISBN 978080442957X
+ISBN 978080442957x
 !! html/php
 <p><a href="/wiki/Special:BookSources/346204561X" class="internal mw-magiclink-isbn">ISBN 3-462-04561-X</a>
+<a href="/wiki/Special:BookSources/346204561X" class="internal mw-magiclink-isbn">ISBN 3-462-04561-x</a>
 <a href="/wiki/Special:BookSources/080442957X" class="internal mw-magiclink-isbn">ISBN 080442957X</a>
+<a href="/wiki/Special:BookSources/080442957X" class="internal mw-magiclink-isbn">ISBN 080442957x</a>
 <a href="/wiki/Special:BookSources/978080442957X" class="internal mw-magiclink-isbn">ISBN 978080442957X</a>
+<a href="/wiki/Special:BookSources/978080442957X" class="internal mw-magiclink-isbn">ISBN 978080442957x</a>
 </p>
 !! html/parsoid
-<p><a href="./Special:BookSources/346204561X" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 3-462-04561-X</a>
-<a href="./Special:BookSources/080442957X" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 080442957X</a>
-<a href="./Special:BookSources/978080442957X" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 978080442957X</a></p>
+<p><a href="./Special:BookSources/346204561X" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 3-462-04561-X</a>
+<a href="./Special:BookSources/346204561X" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 3-462-04561-x</a>
+<a href="./Special:BookSources/080442957X" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 080442957X</a>
+<a href="./Special:BookSources/080442957X" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 080442957x</a>
+<a href="./Special:BookSources/978080442957X" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 978080442957X</a>
+<a href="./Special:BookSources/978080442957X" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 978080442957x</a></p>
 !! end
 
 !! test
@@ -18085,7 +18409,7 @@ ISBN 1234567890
 <p><a href="/wiki/Special:BookSources/1234567890" class="internal mw-magiclink-isbn">ISBN 1234567890</a>
 </p>
 !! html/parsoid
-<p><a href="Special:BookSources/1234567890" rel="mw:ExtLink">ISBN 1234567890</a></p>
+<p><a href="./Special:BookSources/1234567890" rel="mw:WikiLink">ISBN 1234567890</a></p>
 !! end
 
 !! test
@@ -18096,7 +18420,7 @@ Bug 22905: <abbr> followed by ISBN followed by </a>
 <p><abbr>(fr)</abbr> <a href="/wiki/Special:BookSources/2753300917" class="internal mw-magiclink-isbn">ISBN 2753300917</a> <a rel="nofollow" class="external text" href="http://www.example.com">example.com</a>
 </p>
 !! html/parsoid
-<p><abbr data-parsoid='{"stx":"html"}'>(fr)</abbr> <a href="./Special:BookSources/2753300917" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 2753300917</a> <a rel="mw:ExtLink" href="http://www.example.com">example.com</a></p>
+<p><abbr data-parsoid='{"stx":"html"}'>(fr)</abbr> <a href="./Special:BookSources/2753300917" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 2753300917</a> <a rel="mw:ExtLink" href="http://www.example.com">example.com</a></p>
 !! end
 
 !! test
@@ -18742,7 +19066,7 @@ language=sr cat
 !! wikitext
 [[Category:МедиаWики Усер'с Гуиде]]
 !! html
-<a href="/wiki/%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%98%D0%B0:MediaWiki_User%27s_Guide" title="Категорија:MediaWiki User's Guide">MediaWiki User's Guide</a>
+<a href="/wiki/%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%98%D0%B0:MediaWiki_User's_Guide" title="Категорија:MediaWiki User's Guide">MediaWiki User's Guide</a>
 !! end
 
 
@@ -20104,7 +20428,7 @@ percent-encoding and + signs in internal links (Bug 26410)
 !! html/parsoid
 <p><a rel="mw:WikiLink" href="./User:+%25" title="User:+%">User:+%</a> <a rel="mw:WikiLink" href="Page+title%25" title="Page+title%">Page+title%</a>
 <a rel="mw:WikiLink" href="%25+" title="%+">%+</a> <a rel="mw:WikiLink" href="%25+" title="%+">%20</a> <a rel="mw:WikiLink" href="%25+" title="%+">%+ </a> <a rel="mw:WikiLink" href="%25+r" title="%+r">%+r</a>
-<a rel="mw:WikiLink" href="%25" title="%">%</a> <a rel="mw:WikiLink" href="+" title="+">+</a> <span class="mw-default-size" typeof="mw:Error mw:Image" data-parsoid='{"optList":[{"ck":"bogus","ak":"foo"},{"ck":"caption","ak":"[[bar]]"}]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"[[bar]]"}'><a href="./File:%25+abc9" data-parsoid='{"a":{"href":"./File:%25+abc9"},"sa":{}}'><img resource="./File:%25+abc9" src="./Special:FilePath/%25+abc9" height="220" width="220" data-parsoid='{"a":{"resource":"./File:%25+abc9","height":"220","width":"220"},"sa":{"resource":"File:%+abc%39"}}'/></a></span>
+<a rel="mw:WikiLink" href="%25" title="%">%</a> <a rel="mw:WikiLink" href="+" title="+">+</a> <span class="mw-default-size" typeof="mw:Error mw:Image" data-parsoid='{"optList":[{"ck":"bogus","ak":"foo"},{"ck":"caption","ak":"[[bar]]"}]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&lt;a rel=\"mw:WikiLink\" href=\"./Bar\" title=\"Bar\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;./Bar&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;bar&amp;quot;},&amp;quot;dsr&amp;quot;:[94,101,2,2]}\">bar&lt;/a>"}'><a href="./File:%25+abc9"><img resource="./File:%25+abc9" src="./Special:FilePath/%25+abc9" height="220" width="220" data-parsoid='{"a":{"resource":"./File:%25+abc9","height":"220","width":"220"},"sa":{"resource":"File:%+abc%39"}}'/></a></span>
 <a rel="mw:WikiLink" href="./3E" title="3E" data-parsoid='{"stx":"simple","a":{"href":"./3E"},"sa":{"href":"%33%45"}}'>3E</a> <a rel="mw:WikiLink" href="./3E+" title="3E+" data-parsoid='{"stx":"simple","a":{"href":"./3E+"},"sa":{"href":"%33%45+"}}'>3E+</a></p>
 !! end
 
@@ -20119,7 +20443,7 @@ Special characters in embedded file links (bug 27679)
 </p>
 !! html/parsoid
 <p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:Contains_&amp;_ampersand.jpg"><img resource="./File:Contains_&amp;_ampersand.jpg" src="./Special:FilePath/Contains_&amp;_ampersand.jpg" height="220" width="220"/></a></span>
-<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"Title with &amp; ampersand"}'><a href="./File:Does_not_exist.jpg"><img resource="./File:Does_not_exist.jpg" src="./Special:FilePath/Does_not_exist.jpg" height="220" width="220"/></a></span></p>
+<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"Title with &amp;amp; ampersand"}'><a href="./File:Does_not_exist.jpg"><img resource="./File:Does_not_exist.jpg" src="./Special:FilePath/Does_not_exist.jpg" height="220" width="220"/></a></span></p>
 !! end
 
 !! test
@@ -20406,7 +20730,7 @@ __TOC__
 </div>
 
 <h2><span class="mw-headline" id="Hello"><sup class="in-h2">Hello</sup></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: Hello">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
-<h2><span class="mw-headline" id="b.22.3EEvilbye"><sup> b"&gt;Evilbye</sup></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: b&quot;&gt;Evilbye">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
+<h2><span class="mw-headline" id="b.22.3EEvilbye"><sup class="a"> b"&gt;Evilbye</sup></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: b&quot;&gt;Evilbye">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
 
 !! end
 
@@ -20698,7 +21022,7 @@ File:foobar.jpg|caption|alt=galleryalt|link=" onclick="alert('malicious javascri
 !! html
 <ul class="gallery mw-gallery-traditional">
                <li class="gallerybox" style="width: 155px"><div style="width: 155px">
-                       <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/%22_onclick%3D%22alert(%27malicious_javascript_code!%27);"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
+                       <div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/%22_onclick%3D%22alert(&#39;malicious_javascript_code!&#39;);"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
                        <div class="gallerytext">
 <p>caption
 </p>
@@ -20891,7 +21215,7 @@ parsoid=wt2html,wt2wt
 <small>'''foo[[File:Foobar.jpg|thumb|caption]]bar'''</small>
 !! html/parsoid
 <p><small><b>foo</b></small></p>
-<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><small><b>caption</b></small></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><small><b>caption</b></small></figcaption></figure>
 <p><small><b>bar</b></small></p>
 !! end
 
@@ -20903,7 +21227,7 @@ parsoid=wt2html,wt2wt
 '''<small>[[Image:Foobar.jpg|right|300px]]</small>'''
 !! html/parsoid
 <p><b><small></small></b></p>
-<figure class="mw-halign-right" typeof="mw:Image"><a href="File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300"/></a></figure>
+<figure class="mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300"/></a></figure>
 <p></p>
 !! end
 
@@ -21606,23 +21930,23 @@ Empty TR nodes should not be stripped if they have any attributes set
 !! test
 Headings: 0. Unnested
 !! options
-parsoid
+parsoid=html2wt
+!! html/parsoid
+<p>=foo=</p>
+
+<p> =foo=
+<!--cmt-->
+=foo=</p>
+
+<p>=foo<i>a</i>=</p>
 !! wikitext
 <nowiki>=foo=</nowiki>
 
-<nowiki> =foo= </nowiki>
+<nowiki> </nowiki>=foo=
 <!--cmt-->
 <nowiki>=foo=</nowiki>
 
 =foo''a''<nowiki>=</nowiki>
-!! html
-<p><span typeof="mw:Nowiki">=foo=</span></p>
-
-<p><span typeof="mw:Nowiki"> =foo= </span>
-<!--cmt-->
-<span typeof="mw:Nowiki">=foo=</span></p>
-
-<p>=foo<i>a</i><span typeof="mw:Nowiki">=</span></p>
 !!end
 
 # New headings and existing headings are handled differently
@@ -21630,7 +21954,7 @@ parsoid
 Headings: 1. Nested inside html
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <h1>=foo=</h1>
 <h2>=foo=</h2>
 <h3>=foo=</h3>
@@ -21661,7 +21985,7 @@ parsoid=html2wt
 Headings: 2. Outside heading nest on a single line <h1>foo</h1>*bar
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <h1>foo</h1>*bar
 <h1>foo</h1>=bar
 <h1>foo</h1>=bar=
@@ -21679,15 +22003,26 @@ parsoid=html2wt
 !! test
 Headings: 3. Nested inside html with wikitext split by html tags
 !! options
-parsoid=html2wt,wt2wt
-!! wikitext
-= ='''bold'''<nowiki>foo=</nowiki> =
+parsoid=html2wt
 !! html/parsoid
 <h1>=<b>bold</b>foo=</h1>
+!! wikitext
+= ='''bold'''<nowiki>foo=</nowiki> =
 !!end
 
 !! test
 Headings: 4a. No escaping needed (testing just h1 and h2)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<h1>=foo</h1>
+<h1>foo=</h1>
+<h1> =foo= </h1>
+<h1>=foo= bar</h1>
+<h2>=foo</h2>
+<h2>foo=</h2>
+<h1>=</h1>
+<h1><i>=</i>foo=</h1>
 !! wikitext
 = =foo =
 
@@ -21704,22 +22039,13 @@ Headings: 4a. No escaping needed (testing just h1 and h2)
 = = =
 
 = ''=''foo= =
-!! html/parsoid
-<h1>=foo</h1>
-<h1>foo=</h1>
-<h1> =foo= </h1>
-<h1>=foo= bar</h1>
-<h2>=foo</h2>
-<h2>foo=</h2>
-<h1>=</h1>
-<h1><i>=</i>foo=</h1>
 !!end
 
 !! test
 Headings: 4b. No escaping needed (inside p-tags)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>===
 =foo= x
 =foo= <s></s>
@@ -21732,6 +22058,20 @@ parsoid=html2wt
 
 !! test
 Headings: 5. Empty headings
+!! options
+parsoid=html2wt
+!! html/parsoid
+<h1 data-parsoid='{}'></h1>
+
+<h2 data-parsoid='{}'></h2>
+
+<h3 data-parsoid='{}'></h3>
+
+<h4 data-parsoid='{}'></h4>
+
+<h5 data-parsoid='{}'></h5>
+
+<h6 data-parsoid='{}'></h6>
 !! wikitext
 =<nowiki/>=
 
@@ -21744,112 +22084,74 @@ Headings: 5. Empty headings
 =====<nowiki/>=====
 
 ======<nowiki/>======
-!! html/parsoid
-<h1 data-parsoid='{}'><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/></h1>
-
-<h2 data-parsoid='{}'><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/></h2>
-
-<h3 data-parsoid='{}'><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/></h3>
-
-<h4 data-parsoid='{}'><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/></h4>
-
-<h5 data-parsoid='{}'><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/></h5>
-
-<h6 data-parsoid='{}'><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/></h6>
 !!end
 
 !! test
 Headings: 6a. Heading chars in SOL context (with trailing spaces)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>=a=</p>
+
+<p>=a=</p> 
+
+<p>=a=</p>     
 !! wikitext
 <nowiki>=a=</nowiki>
 
 <nowiki>=a=</nowiki> 
 
 <nowiki>=a=</nowiki>   
-
-<nowiki>=a=</nowiki>   
-!! html/php
-<p>=a=
-</p><p>=a= 
-</p><p>=a=     
-</p><p>=a=     
-</p>
-!! html/parsoid
-<p><span typeof="mw:Nowiki">=a=</span></p>
-
-<p><span typeof="mw:Nowiki">=a=</span></p> 
-
-<p><span typeof="mw:Nowiki">=a=</span></p>     
-
-<p><span typeof="mw:Nowiki">=a=</span></p>     
 !!end
 
 !! test
 Headings: 6b. Heading chars in SOL context (with trailing newlines)
-!! wikitext
-<nowiki>=a=
-b</nowiki>
-
-<nowiki>=a= 
-b</nowiki>
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>=a=
+b</p>
 
-<nowiki>=a=    
-b</nowiki>
+<p>=a= 
+b</p>
 
-<nowiki>=a=     
-b</nowiki>
-!! html/php
-<p>=a=
-b
-</p><p>=a= 
-b
-</p><p>=a=     
-b
-</p><p>=a=      
+<p>=a= 
+b</p>
+!! wikitext
+<nowiki>=a=</nowiki>
 b
-</p>
-!! html/parsoid
-<p><span typeof="mw:Nowiki">=a=
-b</span></p>
-
-<p><span typeof="mw:Nowiki">=a= 
-b</span></p>
 
-<p><span typeof="mw:Nowiki">=a=        
-b</span></p>
+<nowiki>=a=</nowiki> 
+b
 
-<p><span typeof="mw:Nowiki">=a=         
-b</span></p>
+<nowiki>=a=</nowiki>   
+b
 !!end
 
 !! test
 Headings: 6c. Heading chars in SOL context (leading newline break)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>a
+=b=</p>
 !! wikitext
 a
 <nowiki>=b=</nowiki>
-!! html/php
-<p>a
-=b=
-</p>
-!! html/parsoid
-<p>a
-<span typeof="mw:Nowiki">=b=</span>
 !!end
 
 !! test
 Headings: 6d. Heading chars in SOL context (with interspersed comments)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<!--c0--><p>=a=</p>
+
+<!--c1--><p>=a=</p> <!--c2-->   <!--c3-->
 !! wikitext
 <!--c0--><nowiki>=a=</nowiki>
 
 <!--c1--><nowiki>=a=</nowiki> <!--c2-->         <!--c3-->
-!! html/php
-<p>=a=
-</p><p>=a=      
-</p>
-!! html/parsoid
-<!--c0--><p><span typeof="mw:Nowiki">=a=</span></p>
-
-<!--c1--><p><span typeof="mw:Nowiki">=a=</span></p> <!--c2-->   <!--c3-->
 !!end
 
 !! test
 
 !! test
 Lists: 0. Outside nests
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>*foo</p>
+
+<p>#foo</p>
+
+<p>;Foo:bar</p>
 !! wikitext
 <nowiki>*</nowiki>foo
 
 <nowiki>#</nowiki>foo
 
-<nowiki>;Foo:</nowiki>bar
-!! html/php
-<p>*foo
-</p><p>#foo
-</p><p>;Foo:bar
-</p>
-!! html/parsoid
-<p><span typeof="mw:Nowiki">*</span>foo</p>
-
-<p><span typeof="mw:Nowiki">#</span>foo</p>
-
-<p><span typeof="mw:Nowiki">;Foo:</span>bar</p>
+<nowiki>;</nowiki>Foo<nowiki>:</nowiki>bar
 !!end
 
 !! test
 Lists: 1. Nested inside html
+!! options
+parsoid=html2wt
+!! html/parsoid
+<ul><li>*foo</li></ul>
+<ul><li>#foo</li></ul>
+<ul><li>:foo</li></ul>
+<ul><li>;foo</li></ul>
+<ol><li>*foo</li></ol>
+<ol><li>#foo</li></ol>
+<ol><li>:foo</li></ol>
+<ol><li>;foo</li></ol>
+
 !! wikitext
 *<nowiki>*foo</nowiki>
 
@@ -21930,20 +22241,19 @@ Lists: 1. Nested inside html
 #<nowiki>:foo</nowiki>
 
 #<nowiki>;foo</nowiki>
-!! html
-<ul><li>*foo</li></ul>
-<ul><li>#foo</li></ul>
-<ul><li>:foo</li></ul>
-<ul><li>;foo</li></ul>
-<ol><li>*foo</li></ol>
-<ol><li>#foo</li></ol>
-<ol><li>:foo</li></ol>
-<ol><li>;foo</li></ol>
-
 !!end
 
 !! test
 Lists: 2. Inside definition lists
+!! options
+parsoid=html2wt
+!! html/parsoid
+<dl><dt>;foo</dt></dl>
+<dl><dt>:foo</dt></dl>
+<dl><dt>:foo</dt>
+<dd>bar</dd></dl>
+<dl><dd>:foo</dd></dl>
+
 !! wikitext
 ;<nowiki>;foo</nowiki>
 
@@ -21953,40 +22263,27 @@ Lists: 2. Inside definition lists
 :bar
 
 :<nowiki>:foo</nowiki>
-!! html
-<dl><dt>;foo</dt></dl>
-<dl><dt>:foo</dt></dl>
-<dl><dt>:foo</dt>
-<dd>bar</dd></dl>
-<dl><dd>:foo</dd></dl>
-
 !!end
 
 !! test
 Lists: 3. Only bullets at start of text should be escaped
+!! options
+parsoid=html2wt
+!! html/parsoid
+<ul><li>*foo*bar</li></ul>
+<ul><li>*foo<i>it</i>*bar</li></ul>
+
 !! wikitext
 *<nowiki>*foo*bar</nowiki>
 
 *<nowiki>*foo</nowiki>''it''*bar
-!! html
-<ul><li>*foo*bar</li></ul>
-<ul><li>*foo<i>it</i>*bar</li></ul>
-
 !!end
 
 !! test
 Lists: 4. No escapes needed
 !! options
-parsoid
-!! wikitext
-*foo*bar
-
-*''foo''*bar
-
-*[[Foo]]: bar
-
-*[[Foo]]*bar
-!! html
+parsoid=html2wt
+!! html/parsoid
 <ul>
 <li>foo*bar
 </li>
@@ -22003,10 +22300,29 @@ parsoid
 <li><a rel="mw:WikiLink" href="Foo" title="Foo">Foo</a>*bar
 </li>
 </ul>
+!! wikitext
+*foo*bar
+
+*''foo''*bar
+
+*[[Foo]]: bar
+
+*[[Foo]]*bar
 !!end
 
 !! test
 Lists: 5. No unnecessary escapes
+!! options
+parsoid=html2wt
+!! html/parsoid
+<ul><li> bar <span>[[foo]]</span></li></ul>
+<ul><li> =bar <span>[[foo]]</span></li></ul>
+<ul><li> [[bar <span>[[foo]]</span></li></ul>
+<ul><li> ]]bar <span>[[foo]]</span></li></ul>
+<ul><li> =bar <span>foo]]</span>=</li></ul>
+<ul><li> <s></s>: a</li></ul>
+<ul><li> <i>* foo</i></li></ul>
+
 !! wikitext
 * bar <span><nowiki>[[foo]]</nowiki></span>
 
@@ -22021,22 +22337,13 @@ Lists: 5. No unnecessary escapes
 * <s></s>: a
 
 * ''* foo''
-!! html
-<ul><li> bar <span>[[foo]]</span></li></ul>
-<ul><li> =bar <span>[[foo]]</span></li></ul>
-<ul><li> [[bar <span>[[foo]]</span></li></ul>
-<ul><li> ]]bar <span>[[foo]]</span></li></ul>
-<ul><li> =bar <span>foo]]</span>=</li></ul>
-<ul><li> <s></s>: a</li></ul>
-<ul><li> <i>* foo</i></li></ul>
-
 !!end
 
 !! test
 Lists: 6. Escape bullets in SOL position
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p><!--cmt-->*foo</p>
 !! wikitext
 <!--cmt--><nowiki>*</nowiki>foo
@@ -22044,20 +22351,22 @@ parsoid=html2wt
 
 !! test
 Lists: 7. Escape bullets in a multi-line context
-!! wikitext
-a
-<nowiki>*</nowiki>b
-!! html
+!! options
+parsoid=html2wt
+!! html/parsoid
 <p>a
 *b
 </p>
+!! wikitext
+a
+<nowiki>*</nowiki>b
 !!end
 
 !! test
 Lists: 8. Escape colons only if not present in tags
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <dl><dt>a:b<i>c:d</i></dt></dl>
 !! wikitext
 ; <nowiki>a:b</nowiki>''c:d''
@@ -22069,17 +22378,16 @@ parsoid=html2wt
 
 !! test
 HRs: 1. Single line
+!! options
+parsoid=html2wt
+!! html/parsoid
+<hr />----
+<hr />=foo=
+<hr />*foo
 !! wikitext
 ----<nowiki>----</nowiki>
 ----=foo=
 ----*foo
-!! html+tidy
-<hr />
-<p>----</p>
-<hr />
-<p>=foo=</p>
-<hr />
-<p>*foo</p>
 !! end
 
 #### --------------- Tables ---------------
@@ -22103,40 +22411,48 @@ HRs: 1. Single line
 
 !! test
 Tables: 1a. Simple example
-!! wikitext
-<nowiki>{|
-|}</nowiki>
-!! html
+!! options
+parsoid=html2wt
+!! html/parsoid
 <p>{|
 |}
 </p>
+!! wikitext
+<nowiki>{|
+|}</nowiki>
 !! end
 
 !! test
 Tables: 1b. No escaping needed
-!! wikitext
-!foo
-!! html
+!! options
+parsoid=html2wt
+!! html/parsoid
 <p>!foo
 </p>
+!! wikitext
+!foo
 !! end
 
 !! test
 Tables: 1c. No escaping needed
-!! wikitext
-|foo
-!! html
+!! options
+parsoid=html2wt
+!! html/parsoid
 <p>|foo
 </p>
+!! wikitext
+|foo
 !! end
 
 !! test
 Tables: 1d. No escaping needed
-!! wikitext
-|}foo
-!! html
+!! options
+parsoid=html2wt
+!! html/parsoid
 <p>|}foo
 </p>
+!! wikitext
+|}foo
 !! end
 
 !! test
@@ -22197,11 +22513,8 @@ parsoid=html2wt
 
 !! test
 Tables: 2c. Nested in td -- no escaping needed
-!! wikitext
-{|
-
-|foo!!bar
-|}
+!! options
+parsoid=html2wt
 !! html/*
 <table>
 
@@ -22209,15 +22522,17 @@ Tables: 2c. Nested in td -- no escaping needed
 <td>foo!!bar
 </td></tr></table>
 
-!! end
-
-!! test
-Tables: 3a. Nested in th
 !! wikitext
 {|
 
-!foo!bar
+|foo!!bar
 |}
+!! end
+
+!! test
+Tables: 3a. Nested in th
+!! options
+parsoid=html2wt
 !! html/*
 <table>
 
@@ -22225,6 +22540,11 @@ Tables: 3a. Nested in th
 <th>foo!bar
 </th></tr></table>
 
+!! wikitext
+{|
+
+!foo!bar
+|}
 !! end
 
 !! test
@@ -22333,6 +22653,19 @@ parsoid=html2wt
 
 !! test
 Tables: 4c. No escaping needed
+!! options
+parsoid=html2wt
+!! html/parsoid
+<table><tbody>
+<tr><td>foo-bar</td><td>foo+bar</td></tr>
+<tr><td><i>foo</i>-bar</td><td><i>foo</i>+bar</td></tr>
+<tr><td>foo
+<p>bar|baz
++bar
+-bar</p></td></tr>
+<tr><td>x
+<div>a|b</div></td>
+</tbody></table>
 !! wikitext
 {|
 |foo-bar
@@ -22373,21 +22706,18 @@ bar|baz
 <div>a|b</div>
 </td></tr></table>
 
-!! html/parsoid
-<table><tbody>
-<tr><td>foo-bar</td><td>foo+bar</td></tr>
-<tr><td><i>foo</i>-bar</td><td><i>foo</i>+bar</td></tr>
-<tr><td>foo
-<p>bar|baz
-+bar
--bar</p></td></tr>
-<tr><td>x
-<div>a|b</div></td>
-</tbody></table>
 !! end
 
 !! test
 Tables: 4d. No escaping needed
+!! options
+parsoid=html2wt
+!! html/parsoid
+<table>
+<tbody><tr><td><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a>-bar</td>
+<td data-parsoid='{"startTagSrc":"|","attrSepSrc":"|"}'>+1</td>
+<td data-parsoid='{"startTagSrc":"|","attrSepSrc":"|"}'>-2</td></tr>
+</tbody></table>
 !! wikitext
 {|
 |[[Foo]]-bar
@@ -22404,36 +22734,13 @@ Tables: 4d. No escaping needed
 <td>-2
 </td></tr></table>
 
-!! html/parsoid
-<table>
-<tbody><tr><td><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a>-bar</td>
-<td data-parsoid='{"startTagSrc":"|","attrSepSrc":"|"}'>+1</td>
-<td data-parsoid='{"startTagSrc":"|","attrSepSrc":"|"}'>-2</td></tr>
-</tbody></table>
-!! end
-
-!! test
-Tables: Digest broken attributes on table and tr tag
-!! options
-parsoid=wt2html
-!! wikitext
-{| || |} ++
-|- || || ++ --
-|- > [
-|}
-!! html
-<table>
-<tbody>
-<tr></tr>
-<tr></tr>
-</tbody></table>
 !! end
 
 !! test
 T97430: Don't emit empty nowiki pairs around marker meta tags
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>*This is a long sentence here that will make the nowiki algo split up the nowikis into multiple pairs
 |** Make this another long long long sentence forcing the nowiki algo to split up the nowikis.</p>
 !! wikitext
@@ -22443,6 +22750,13 @@ parsoid=html2wt
 
 !! test
 Unclosed xmlish element in table line shouldn't eat end delimiters
+!! options
+parsoid=html2wt
+!! html/parsoid
+<table>
+<tbody><tr><td> &lt;foo</td>
+<td> bar></td></tr>
+</tbody></table>
 !! wikitext
 {|
 | <foo
@@ -22456,11 +22770,6 @@ Unclosed xmlish element in table line shouldn't eat end delimiters
 <td> bar&gt;
 </td></tr></table>
 
-!! html/parsoid
-<table>
-<tbody><tr><td> &lt;foo</td>
-<td> bar></td></tr>
-</tbody></table>
 !! end
 
 #### --------------- Links ----------------
@@ -22472,6 +22781,12 @@ Unclosed xmlish element in table line shouldn't eat end delimiters
 #### --------------------------------------
 !! test
 Links 1. WikiLinks: No escapes needed
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="Foo" title="Foo">Foo<i>boo</i></a>
+<a rel="mw:WikiLink" href="Foo" title="Foo">[Foobar]</a>
+<a rel="mw:WikiLink" href="Foo" title="Foo">x [Foobar] x</a></p>
 !! wikitext
 [[Foo|Foo''boo'']]
 [[Foo|[Foobar]]]
@@ -22481,10 +22796,6 @@ Links 1. WikiLinks: No escapes needed
 <a href="/wiki/Foo" title="Foo">[Foobar]</a>
 <a href="/wiki/Foo" title="Foo">x [Foobar] x</a>
 </p>
-!! html/parsoid
-<p><a rel="mw:WikiLink" href="Foo" title="Foo">Foo<i>boo</i></a>
-<a rel="mw:WikiLink" href="Foo" title="Foo">[Foobar]</a>
-<a rel="mw:WikiLink" href="Foo" title="Foo">x [Foobar] x</a></p>
 !! end
 
 !! test
@@ -22529,6 +22840,11 @@ parsoid=html2wt
 
 !! test
 Links 3. WikiLinks: No escapes needed
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="Foo">[Foobar</a>
+<a rel="mw:WikiLink" href="Foo" title="Foo">foo|bar</a></p>
 !! wikitext
 [[Foo|[Foobar]]
 [[Foo|foo|bar]]
@@ -22536,9 +22852,6 @@ Links 3. WikiLinks: No escapes needed
 <p><a href="/wiki/Foo" title="Foo">[Foobar</a>
 <a href="/wiki/Foo" title="Foo">foo|bar</a>
 </p>
-!! html/parsoid
-<p><a rel="mw:WikiLink" href="Foo">[Foobar</a>
-<a rel="mw:WikiLink" href="Foo" title="Foo">foo|bar</a></p>
 !! end
 
 !! test
@@ -22568,17 +22881,21 @@ parsoid=html2wt
 
 !! test
 Links 5. ExtLinks: No escapes needed
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p><a rel="mw:ExtLink" href="http://google.com">[google</a></p>
 !! wikitext
 [http://google.com [google]
 !! html/php
 <p><a rel="nofollow" class="external text" href="http://google.com">[google</a>
 </p>
-!! html/parsoid
-<p><a rel="mw:ExtLink" href="http://google.com">[google</a></p>
 !! end
 
 !! test
 Links 6. Add <nowiki/>s between text-nodes and url-links when required (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
 <p>x<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>y
 <a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>?x
@@ -22612,6 +22929,8 @@ http://example.com(x<nowiki/>)
 
 !! test
 Links 7a. Don't add spurious <nowiki/>s between text-nodes and url-links (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
 <p>x
 <a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>
 
 !! test
 Links 7b. Don't add spurious <nowiki/>s between text-nodes and url-links (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
 <p><a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>.,;:!?\
 -<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>:</p>
@@ -22659,6 +22980,8 @@ http://example.com.,;:!?\
 
 !! test
 Links 8. Add <nowiki/>s between text-nodes and RFC-links when required (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
 <p><a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>4
 <a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>y
@@ -22671,6 +22994,8 @@ X<nowiki/>RFC 123<nowiki/>y
 
 !! test
 Links 9. Don't add spurious <nowiki/>s between text-nodes and RFC-links (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
 <p><a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>?foo
 <a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>&amp;foo
@@ -22689,6 +23014,8 @@ RFC 123&foo
 
 !! test
 Links 10. Add <nowiki/>s between text-nodes and PMID-links when required (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
 <p><a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>4
 <a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>y
@@ -22701,6 +23028,8 @@ X<nowiki/>PMID 123<nowiki/>y
 
 !! test
 Links 11. Don't add spurious <nowiki/>s between text-nodes and PMID-links (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
 <p><a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>?foo
 <a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>&foo
@@ -22719,10 +23048,12 @@ PMID 123&foo
 
 !! test
 Links 12. Add <nowiki/>s between text-nodes and ISBN-links when required (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
-<p><a href="./Special:BookSources/1234567890" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>1
-<a href="./Special:BookSources/1234567890" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>x
-a<a href="./Special:BookSources/1234567890" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>b
+<p><a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>1
+<a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>x
+a<a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>b
 </p>
 !! wikitext
 ISBN 1234567890<nowiki/>1
@@ -22732,8 +23063,10 @@ a<nowiki/>ISBN 1234567890<nowiki/>b
 
 !! test
 Links 13. Don't add spurious <nowiki/>s between text-nodes and ISBN-links (bug 64300)
+!! options
+parsoid=html2wt
 !! html/parsoid
-<p>-<a href="./Special:BookSources/1234567890" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>'s
+<p>-<a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>'s
 !! wikitext
 -ISBN 1234567890's
 !! html/php
@@ -22749,20 +23082,21 @@ parsoid=html2wt
 <p>this is not a link: http://example.com
 </p>
 !! wikitext
-this is not a link: <nowiki>http://example.com</nowiki>
+<nowiki>this is not a link: http://example.com</nowiki>
 !! end
 
 !! test
 Links 15. Link trails can't become link prefixes.
 !! options
 language=is
+parsoid=html2wt
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="Söfnuður" title="Söfnuður" data-parsoid='{"stx":"simple","tail":"-"}'>Söfnuður-</a><a rel="mw:WikiLink" href="00" title="00">00</a></p>
 !! wikitext
 [[Söfnuður]]-[[00]]
 !! html/php
 <p><a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">Söfnuður-</a><a href="/wiki/00" title="00">00</a>
 </p>
-!! html/parsoid
-<p><a rel="mw:WikiLink" href="Söfnuður" title="Söfnuður" data-parsoid='{"stx":"simple","tail":"-"}'>Söfnuður-</a><a rel="mw:WikiLink" href="00" title="00">00</a></p>
 !! end
 
 #### --------------- Quotes ---------------
@@ -22774,28 +23108,7 @@ language=is
 !! test
 1a. Quotes inside <b> and <i>
 !! options
-parsoid=html2wt,wt2wt
-!! wikitext
-''<nowiki/>'foo'''
-''<nowiki>''foo''</nowiki>''
-''<nowiki>'''foo'''</nowiki>''
-''foo''<nowiki/>'s
-'''<nowiki/>'foo''''
-'''<nowiki>''foo''</nowiki>'''
-'''<nowiki>'''foo'''</nowiki>'''
-'''foo'<nowiki/>''bar'<nowiki/>''baz'''
-'''foo'''<nowiki/>'s
-'''foo''
-''foo''<nowiki/>'
-''foo'''<nowiki/>'
-'''foo''<nowiki/>'
-''''foo'''
-'''foo'''<nowiki/>'
-''''foo'''<nowiki/>'
-''fools'<span> errand</span>''
-''<span>fool</span>'s errand''
-'<nowiki/>''foo'' bar '''baz''
-a|!*#-:;+-~[]{}b'''x''
+parsoid=html2wt
 !! html/*
 <p><i>'foo'</i>
 <i>''foo''</i>
@@ -22818,22 +23131,34 @@ a|!*#-:;+-~[]{}b'''x''
 '<i>foo</i> bar '<i>baz</i>
 a|!*#-:;+-~[]{}b'<i>x</i>
 </p>
+!! wikitext
+''<nowiki/>'foo'''
+''<nowiki>''foo''</nowiki>''
+''<nowiki>'''foo'''</nowiki>''
+''foo''<nowiki/>'s
+'''<nowiki/>'foo''''
+'''<nowiki>''foo''</nowiki>'''
+'''<nowiki>'''foo'''</nowiki>'''
+'''foo'<nowiki/>''bar'<nowiki/>''baz'''
+'''foo'''<nowiki/>'s
+'''foo''
+''foo''<nowiki/>'
+''foo'''<nowiki/>'
+'''foo''<nowiki/>'
+''''foo'''
+'''foo'''<nowiki/>'
+''''foo'''<nowiki/>'
+''fools'<span> errand</span>''
+''<span>fool</span>'s errand''
+'<nowiki/>''foo'' bar '''baz''
+a|!*#-:;+-~[]{}b'''x''
 !! end
 
 !! test
 1b. Quotes inside <b> and <i> with other tags on same line
 !! options
-parsoid=html2wt,wt2wt
-!! wikitext
-'''a'' foo ''[[bar]]''
-''a''' foo ''[[bar]]''
-''a''' foo '''{{echo|[[bar]]}}'''
-[[foo]] x'''[[bar]]''
-'''foo'' <ref>test</ref>
-'''foo'' <div title="name">test</div>
-'''foo'' and <br> bar
-<references />
-!! html
+parsoid=html2wt
+!! html/parsoid
 '<i>a</i> foo <i><a rel="mw:WikiLink" href="Bar" title="Bar">bar</a></i>
 <i>a'</i> foo <i><a rel="mw:WikiLink" href="Bar" title="Bar">bar</a></i>
 <i>a'</i> foo <b><a rel="mw:WikiLink" href="Bar" title="Bar" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[bar]]"}},"i":0}}]}'>bar</a></b>
@@ -22844,45 +23169,58 @@ parsoid=html2wt,wt2wt
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
 <li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">test</span></li>
 </ol>
+!! wikitext
+'''a'' foo ''[[bar]]''
+''a''' foo ''[[bar]]''
+''a''' foo '''{{echo|[[bar]]}}'''
+[[foo]] x'''[[bar]]''
+'''foo'' <ref>test</ref>
+'''foo'' <div title="name">test</div>
+'''foo'' and <br> bar
+<references />
 !! end
 
 !! test
 2. Link fragments separated by <i> and <b> tags
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>[[<i>foo</i>hello]]</p>
+<p>[[<b>foo</b>hello]]</p>
 !! wikitext
 [[''foo''<nowiki>hello]]</nowiki>
 
 [['''foo'''<nowiki>hello]]</nowiki>
-!! html
-<p>[[<i>foo</i>hello]]
-</p><p>[[<b>foo</b>hello]]
-</p>
 !! end
 
 # FIXME: Escaping one or both of [[ and ]] is also acceptable --
 #        this is one of the shortcomings of this format
 !! test
 3. Link fragments inside <i> and <b>
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p><i>[[foo</i>]]</p>
+<p><b>[[foo</b>]]</p>
 !! wikitext
 ''[[foo''<nowiki>]]</nowiki>
 
 '''[[foo'''<nowiki>]]</nowiki>
-!! html
-<p><i>[[foo</i>]]
-</p><p><b>[[foo</b>]]
-</p>
 !! end
 
 !! test
 4. No escaping needed
-!! wikitext
-'<span>''bar''</span>'
-'<span>'''bar'''</span>'
-'a:b'foo
-!! html
+!! options
+options=html2wt
+!! html/parsoid
 <p>'<span><i>bar</i></span>'
 '<span><b>bar</b></span>'
 'a:b'foo
 </p>
+!! wikitext
+'<span>''bar''</span>'
+'<span>'''bar'''</span>'
+'a:b'foo
 !! end
 
 #### ----------- Paragraphs ---------------
@@ -22891,6 +23229,15 @@ parsoid=html2wt,wt2wt
 
 !! test
 1. No unnecessary escapes
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>bar <span>[[foo]]</span>
+</p><p>=bar <span>[[foo]]</span>
+</p><p>[[bar <span>[[foo]]</span>
+</p><p>]]bar <span>[[foo]]</span>
+</p><p>=bar <span>foo]]</span>=
+</p>
 !! wikitext
 bar <span><nowiki>[[foo]]</nowiki></span>
 
@@ -22901,13 +23248,6 @@ bar <span><nowiki>[[foo]]</nowiki></span>
 ]]bar <span><nowiki>[[foo]]</nowiki></span>
 
 =bar <span>foo]]</span><nowiki>=</nowiki>
-!! html
-<p>bar <span>[[foo]]</span>
-</p><p>=bar <span>[[foo]]</span>
-</p><p>[[bar <span>[[foo]]</span>
-</p><p>]]bar <span>[[foo]]</span>
-</p><p>=bar <span>foo]]</span>=
-</p>
 !!end
 
 #### ----------------------- PRE --------------------------
@@ -22916,90 +23256,110 @@ bar <span><nowiki>[[foo]]</nowiki></span>
 !! test
 1. Leading whitespace in SOL context should be escaped
 !! options
-parsoid
+parsoid=html2wt
+!! html/parsoid
+<p> a</p>
+
+<p>  a</p>
+
+<p>    a(tab)</p>
+
+<p>    a
+<!--cmt-->
+  a</p>
+
+<p>a
+ b</p>
+
+<p>a
+       b</p>
+
+<p>a
+        b</p>
 !! wikitext
 <nowiki> </nowiki>a
 
 <nowiki> </nowiki> a
 
-<nowiki>       </nowiki>a(tab)
+       a(tab)
 
 <nowiki> </nowiki>     a
 <!--cmt-->
-<nowiki> </nowiki> a
+<nowiki>  </nowiki>a
 
 a
 <nowiki> </nowiki>b
 
 a
-<nowiki>       </nowiki>b
+       b
 
 a
-<nowiki>       </nowiki> b
-!! html
-<p> a</p>
-<p>  a</p>
-<p>    a(tab)</p>
-<p>    a</p>
-<p><!--cmt-->  a</p>
-<p>a
- b</p>
-<p>a
-       b</p>
-<p>a
-        b</p>
+        b
+!! html/php
+<p> a
+</p><p>  a
+</p><p>        a(tab)
+</p><p>        a
+  a
+</p><p>a
+ b
+</p><p>a
+       b
+</p><p>a
+        b
+</p>
 !! end
 
 !! test
 2. Leading whitespace in non-indent-pre contexts should not be escaped
 !! options
-parsoid
-!! wikitext
-foo <ref>''a''
- b</ref>
-<references />
-!! html
+parsoid=htm2wt
+!! html/parsoid
 <p>foo <span 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="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
 <li about="#cite_note-1" id="cite_note-1"><a href="#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"><i data-parsoid='{"dsr":[9,14,2,2]}'>a</i>
  b</span></li>
 </ol>
+!! wikitext
+foo <ref>''a''
+ b</ref>
+<references />
 !! end
 
 !! test
 3. Leading whitespace in indent-pre suppressing contexts should not be escaped
 !! options
-parsoid
-!! wikitext
+parsoid=html2wt
+!! html/parsoid
 <blockquote>
+<p>
  a
  <span>b</span>
- c
+ c</p>
 </blockquote>
-!! html
+!! wikitext
 <blockquote>
-<p>
  a
  <span>b</span>
- c</p>
+ c
 </blockquote>
 !! end
 
 !! test
 4. Leading whitespace in indent-pre suppressing contexts should not be escaped
 !! options
-parsoid
-!! wikitext
- [[File:Foobar.jpg|thumb|caption]]
+options=html2wt
 !! 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>caption</figcaption></figure>
+!! wikitext
+ [[File:Foobar.jpg|thumb|caption]]
 !! end
 
 !! test
 5. Nowiki escaping should account for indent-pres
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <pre>==foo==</pre>
 !! wikitext
  ==foo==
@@ -23008,15 +23368,15 @@ parsoid=html2wt
 !!test
 T95794: nowiki escaping should account for leading space at start-of-line in an indent-pre block
 !! options
-parsoid
-!! wikitext
- * foo
- * bar
-!! html
+parsoid=html2wt
+!! html/parsoid
 <pre>
 * foo
 * bar
 </pre>
+!! wikitext
+ * foo
+ * bar
 !! end
 
 #### --------------- Behavior Switches --------------------
@@ -23025,7 +23385,7 @@ parsoid
 1. Valid behavior switches should be escaped
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 __TOC__
 <i>__TOC__</i>
 !! wikitext
@@ -23037,7 +23397,7 @@ __TOC__
 2. Invalid behavior switches should not be escaped
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 __TOO__
 __|__
 !! wikitext
@@ -23048,15 +23408,8 @@ __|__
 # We use indent-pre as an indirect way to test for sol-transparent behavior.
 !! test
 Behavior switches should be SOL-transparent
-!! wikitext
- __TOC__
-
- <!-- this one's bogus -->
- __TOO__
-
- __TOC__ foo
-
-__TOC__ bar
+!! options
+parsoid=html2wt
 !! html/parsoid
  <meta property="mw:PageProp/toc" />
 
@@ -23066,6 +23419,15 @@ __TOC__ bar
 <pre data-parsoid='{}'><meta property="mw:PageProp/toc" data-parsoid='{"src":"__TOC__","magicSrc":"__TOC__"}'/> foo</pre>
 
 <meta property="mw:PageProp/toc" data-parsoid='{"src":"__TOC__","magicSrc":"__TOC__"}'/><pre data-parsoid='{}'>bar</pre>
+!! wikitext
+ __TOC__
+
+ <!-- this one's bogus -->
+ __TOO__
+
+ __TOC__ foo
+
+__TOC__ bar
 !! end
 
 #### --------------- HTML tags ---------------
@@ -23077,75 +23439,85 @@ __TOC__ bar
 !! test
 1. a tags
 !! options
-parsoid
+parsoid=html2wt
+!! html/parsoid
+&lt;a href=&quot;http://google.com&quot;&gt;google&lt;/a&gt;
 !! wikitext
 <a href="http://google.com">google</a>
-!! html
-&lt;a href=&quot;http://google.com&quot;&gt;google&lt;/a&gt;
 !! end
 
 !! test
 2. other tags
-!! wikitext
-* <nowiki><div>foo</div></nowiki>
-* <nowiki><div style="color:red">foo</div></nowiki>
-* <nowiki><td></nowiki>
-!! html
+!! options
+parsoid=html2wt
+!! html/parsoid
 <ul><li> &lt;div&gt;foo&lt;/div&gt;</li>
 <li> &lt;div style=&quot;color:red&quot;&gt;foo&lt;/div&gt;</li>
 <li> &lt;td&gt;</li></ul>
 
+!! wikitext
+* <nowiki><div>foo</div></nowiki>
+* <nowiki><div style="color:red">foo</div></nowiki>
+* <nowiki><td></nowiki>
 !! end
 
 !! test
 3. multi-line html tag
-!! wikitext
-<nowiki><div
->foo</div
-></nowiki>
-!! html
+!! options
+parsoid=html2wt
+!! html/parsoid
 <p>&lt;div
 &gt;foo&lt;/div
 &gt;
 </p>
+!! wikitext
+<nowiki><div
+>foo</div
+></nowiki>
 !! end
 
 !! test
 4. extension tags
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>&lt;ref&gt;foo&lt;/ref&gt;
+</p><p>&lt;ref&gt;bar
+</p><p>baz&lt;/ref&gt;
+</p>
 !! wikitext
 <nowiki><ref>foo</ref></nowiki>
 
 <nowiki><ref>bar</nowiki>
 
 baz<nowiki></ref></nowiki>
-!! html
-<p>&lt;ref&gt;foo&lt;/ref&gt;
-</p><p>&lt;ref&gt;bar
-</p><p>baz&lt;/ref&gt;
-</p>
 !! end
 
 #### --------------- Others ---------------
 !! test
 Escaping nowikis
-!! wikitext
-&lt;nowiki&gt;foo&lt;/nowiki&gt;
-!! html
+!! options
+parsoid=html2wt
+!! html/parsoid
 <p>&lt;nowiki&gt;foo&lt;/nowiki&gt;
 </p>
+!! wikitext
+&lt;nowiki&gt;foo&lt;/nowiki&gt;
 !! end
 
 ## The quote-char in the input is necessary for triggering the bug
 !! test
 (Bug 52035) Nowiki-escaping should not get tripped by " :" in text
 !! options
-parsoid=wt2wt,html2wt
+parsoid=html2wt
+!! html/parsoid
+<p>foo's bar :</p>
 !! wikitext
 foo's bar :
-!! html
-<p>foo's bar :</p>
 !! end
 
+#----------- End of wikitext escaping tests --------------
+
 !! test
 
 Tag-like HTML structures are passed through as text
@@ -23197,20 +23569,9 @@ HTML tag with broken attribute value quoting
 !! wikitext
 <span title="Hello world>Foo</span>
 !! html/php
-<p><span>Foo</span>
-</p>
-!! html/parsoid
 <p><span title="Hello world">Foo</span>
 </p>
-!! end
-
-!! test
-Parsoid-only: HTML tag with broken attribute value quoting
-!! options
-parsoid
-!! wikitext
-<span title="Hello world>Foo</span>
-!! html
+!! html/parsoid
 <p><span title="Hello world">Foo</span>
 </p>
 !! end
@@ -23224,7 +23585,7 @@ Table with broken attribute value quoting
 !! html/php
 <table>
 <tr>
-<td>Foo
+<td title="Hello world">Foo
 </td></tr></table>
 
 !! html/parsoid
@@ -23245,9 +23606,9 @@ Table with broken attribute value quoting on consecutive lines
 !! html/php
 <table>
 <tr>
-<td>Foo
+<td title="Hello world">Foo
 </td>
-<td>Bar
+<td style="color:red">Bar
 </td></tr></table>
 
 !! html/parsoid
@@ -23260,7 +23621,7 @@ Table with broken attribute value quoting on consecutive lines
 !! end
 
 !! test
-Parsoid-only: Don't wrap broken template tags in <nowiki> on wt2wt (Bug 42353)
+2. Parsoid-only: Don't wrap broken template tags in <nowiki> on wt2wt (Bug 42353)
 !! options
 parsoid
 !! wikitext
@@ -23270,7 +23631,7 @@ parsoid
 !! end
 
 !! test
-Parsoid-only: Don't wrap broken template tags in <nowiki> on wt2wt (Bug 42353)
+1. Parsoid-only: Don't wrap broken template tags in <nowiki> on wt2wt (Bug 42353)
 !! options
 parsoid
 !! wikitext
@@ -23872,7 +24233,7 @@ Don't block XML namespace declaration
 Serialize interwiki links pointing to the current wiki as plain wiki links (bug 65869)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p><a rel="mw:ExtLink" href="http://mi.wikipedia.org/wiki/Foo">Foo</a></p>
 !! wikitext
 [[Foo]]
@@ -23883,7 +24244,7 @@ parsoid=html2wt
 New wikilinks should be serialized properly
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{}'>Foo</a>
 <a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a>
 !! wikitext
@@ -23895,7 +24256,7 @@ parsoid=html2wt
 New wiki links (href variations)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a rel="mw:WikiLink" href="./Foo_bar">Foo_bar</a>
 <a rel="mw:WikiLink" href="Foo_bar">Foo_bar</a>
 <a rel="mw:WikiLink" href="Foo bar">Foo_bar</a>
@@ -23911,7 +24272,7 @@ parsoid=html2wt
 New wiki links (content string variations)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a rel="mw:WikiLink" href="./Foo_bar">Foo_bar</a>
 <a rel="mw:WikiLink" href="./Foo_bar">Foo bar</a>
 <a rel="mw:WikiLink" href="./Foo_bar">./Foo_bar</a>
@@ -23925,7 +24286,7 @@ parsoid=html2wt
 New category links (href variations)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <link rel="mw:PageProp/Category" href="./Category:Toxine_bactérienne" />
 <link rel="mw:PageProp/Category" href="./Category:Toxine_bact%C3%A9rienne" />
 <link rel="mw:PageProp/Category" href="Category:Toxine_bact%C3%A9rienne" />
@@ -23940,7 +24301,7 @@ New sol transparent links don't need indent-pre nowiki protection
 !! options
 parsoid=html2wt
 language=de
-!! html
+!! html/parsoid
          <link rel="mw:PageProp/redirect" href="./Main_Page">
 <!-- this is good  -->    <link rel="mw:PageProp/Category" href="./Category:Good" />
 <!-- this is great -->    <link rel="mw:PageProp/Category" href="./Kategorie:Great" />
@@ -23954,7 +24315,7 @@ language=de
 New interlanguage links (href variations)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine bactérienne" />
 <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine_bactérienne" />
 <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine_bact%C3%A9rienne" />
@@ -24101,16 +24462,17 @@ parsoid
 <figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"alt","ak":"alt="},{"ck":"caption","ak":"bar"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img alt="" 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":{"alt":"","resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"alt":"alt=","resource":"File:Foobar.jpg"}}'/></a><figcaption>bar</figcaption></figure>
 !! end
 
-#!! test
-#Image: new attributes should be serialized in wiki's language for RTL languages (bug 51852)
-#!! options
-#parsoid=html2wt
-#language=ar
-#!! html
-#<figure class="mw-default-size mw-halign-right" typeof="mw:Image/Thumb"><a href="Imagen:Foobar.jpg"><img resource="./Imagen:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="180"/></a></figure>
-#!! wikitext
-#[[Imagen:Foobar.jpg|derecha|miniaturadeimagen]]
-#!! end
+!! test
+Image: new attributes should be serialized in wiki's language for RTL languages (bug 51852)
+!! options
+parsoid=html2wt
+language=ar
+disabled
+!! html/parsoid
+<figure class="mw-default-size mw-halign-right" typeof="mw:Image/Thumb"><a href="./Imagen:Foobar.jpg"><img resource="./Imagen:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="180"/></a></figure>
+!! wikitext
+[[Imagen:Foobar.jpg|derecha|miniaturadeimagen]]
+!! end
 
 !! test
 Image: Block level image should have \n before and after
@@ -24202,7 +24564,7 @@ parsoid=html2wt
 Lists: Serialize correctly even when list content is wrapped in p-tags (like VE does)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <ul>
 <li><p>foo</p></li>
 </ul>
@@ -24214,7 +24576,7 @@ parsoid=html2wt
 Lists: Serialize correctly even when list tags has unneeded whitespace between tags
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <ul> <li>foo</li></ul>
 !! wikitext
 * foo
@@ -24224,7 +24586,7 @@ parsoid=html2wt
 Don't strip leading whitespace when handling indent-pre suppressing tags
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <table>
   <tr><td> indented row</td></tr>
 </table>
@@ -24257,31 +24619,31 @@ foo
 Nowiki-wrap leading whitespace when handling indent-pre inducing tags
 !! options
 parsoid=html2wt
-!! wikitext
-foo
-<nowiki> </nowiki><span>bar</span>
+!! html/parsoid
+<p>foo</p>
+ <span>bar</span>
 
 <span>foo2
-<nowiki> </nowiki></span>bar2
+ </span>bar2
 
 <div>foo</div>
-<nowiki> </nowiki><span>bar</span>
+ <span>bar</span>
 
 <div>
-<nowiki> </nowiki><span>foo</span>
+ <span>foo</span>
 </div>
-!! html
-<p>foo</p>
- <span>bar</span>
+!! wikitext
+foo
+<nowiki> </nowiki><span>bar</span>
 
 <span>foo2
- </span>bar2
+<nowiki> </nowiki></span>bar2
 
 <div>foo</div>
- <span>bar</span>
+<nowiki> </nowiki><span>bar</span>
 
 <div>
- <span>foo</span>
+<nowiki> </nowiki><span>foo</span>
 </div>
 !! end
 
@@ -24289,7 +24651,7 @@ foo
 Lists: Dont insert newlines in a serialized list item.
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <ul><li>a<br>b</li><li>c</li></ul>
 !! wikitext
 * a<br>b
@@ -24303,14 +24665,14 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": false
 }
-!! html
-<h2>hello there<link href="Category:A1" rel="mw:PageProp/Category" /></h2>
-<h2><link href="Category:A2" rel="mw:PageProp/Category" />hi pal</h2>
+!! html/parsoid
+<h2>hello there<link href="./Category:A1" rel="mw:PageProp/Category" /></h2>
+<h2><link href="./Category:A2" rel="mw:PageProp/Category" />hi pal</h2>
 
-<h2><!--foo-->  <link href="Category:A3" rel="mw:PageProp/Category" />   how goes it</h2>
-<h2>it goes well   <link href="Category:A4" rel="mw:PageProp/Category" />  <!--bar--></h2>
+<h2><!--foo-->  <link href="./Category:A3" rel="mw:PageProp/Category" />   how goes it</h2>
+<h2>it goes well   <link href="./Category:A4" rel="mw:PageProp/Category" />  <!--bar--></h2>
 
-<h2 data-parsoid='{}'>howdy<link href="Category:A5" rel="mw:PageProp/Category" /></h2>
+<h2 data-parsoid='{}'>howdy<link href="./Category:A5" rel="mw:PageProp/Category" /></h2>
 
 <h2><meta property="mw:PageProp/toc" /> ok</h2>
 !! wikitext
@@ -24318,7 +24680,7 @@ parsoid={
 
 ==  [[Category:A2]] hi pal ==
 
-== <!--foo-->   [[Category:A3]]    how goes it ==
+==  <!--foo-->  [[Category:A3]]    how goes it ==
 
 == it goes well    [[Category:A4]]  <!--bar-->  ==
 
@@ -24334,14 +24696,12 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
-<h2>hello there<link href="Category:A1" rel="mw:PageProp/Category" /></h2>
-<h2><link href="Category:A2" rel="mw:PageProp/Category" />hi pal</h2>
-
-<h2><!--foo-->  <link href="Category:A3" rel="mw:PageProp/Category" />   how goes it</h2>
-<h2>it goes well   <link href="Category:A4" rel="mw:PageProp/Category" />  <!--bar--></h2>
+!! html/parsoid
+<h2>hello there<link href="./Category:A1" rel="mw:PageProp/Category" /></h2>
+<h2><link href="./Category:A2" rel="mw:PageProp/Category" />hi pal</h2>
 
-<h2 data-parsoid='{}'>howdy<link href="Category:A5" rel="mw:PageProp/Category" /></h2>
+<h2><!--foo-->  <link href="./Category:A3" rel="mw:PageProp/Category" />   how goes it</h2>
+<h2>it goes well   <link href="./Category:A4" rel="mw:PageProp/Category" />  <!--bar--></h2>
 
 <h2><meta property="mw:PageProp/toc" /> ok</h2>
 !! wikitext
@@ -24358,8 +24718,6 @@ parsoid={
 == it goes well ==
 [[Category:A4]]  <!--bar-->
 
-==howdy [[Category:A5]] ==
-
 __TOC__
 
 == ok ==
@@ -24372,7 +24730,7 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
+!! html/parsoid
 <h2><span about="#mwt1" typeof="mw:Transclusion" data-parsoid="{}" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo [[Category:Foo]]"}},"i":0}}]}'>foo </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" data-parsoid="{}" /></h2>
 !! wikitext
 == {{echo|foo [[Category:Foo]]}} ==
@@ -24385,8 +24743,8 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
-<h2> foo <span about="#mwt2" class="reference" 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="#cite_note-1">[1]</a></span> </h2>
+!! html/parsoid
+<h2> foo <span 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="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> </h2>
 
 <ol class="references" typeof="mw:Extension/references" about="#mwt3" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">bar <link rel="mw:PageProp/Category" href="./Category:Baz" /> </span></li></ol>
 !! wikitext
@@ -24400,7 +24758,7 @@ parsoid={
 Parsoid: Serialize positional parameters with = in them as named parameter
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p about="#mwt1" typeof="mw:Transclusion"
 data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"f=oo"}},"i":0}}]}'>foo</p>
 
@@ -24424,7 +24782,7 @@ data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},
 Parsoid: Serialize positional parameters with = in extlink as named parameter
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p><a rel="mw:ExtLink" href="http://stuff?is=ok" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"http://stuff?is=ok"}},"i":0}}]}'>http://stuff?is=ok</a></p>
 !! wikitext
 {{echo|1 = http://stuff?is=ok}}
@@ -24434,7 +24792,7 @@ parsoid=html2wt
 Parsoid: Correctly serialize block-node children when they are a combination of text and p-nodes
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <div>a<p>b</p></div>
 <div>a
 <p>b</p></div>
 Substrings resembling wikitext in hrefs should not get nowiki escapes
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a rel="mw:WikiLink" href="./Foo''bar''baz">Foo''bar''baz</a>
 !! wikitext
 [[Foo''bar''baz]]
@@ -24469,14 +24827,14 @@ parsoid=html2wt
 Enforce single-line context in the serializer
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <h2>testing
 123</h2>
 
 <h2> hi <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bogus","href":"./Template:Bogus"},"params":{"1":{"wt":"there\nyou"}},"i":0}}]}'>there</span><span about="#mwt1">
 </span><span about="#mwt1">you</span> </h2>
 
-<h2> foo <span about="#mwt2" class="reference" 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="#cite_note-1">[1]</a></span> </h2>
+<h2> foo <span 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="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> </h2>
 
 <ol class="references" typeof="mw:Extension/references" about="#mwt3" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">hello
 there</span></li></ol>
@@ -24528,7 +24886,7 @@ ha
 Serialize new placeholder space without spans
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p>foo<span typeof="mw:Placeholder"> </span>: bar</p>
 
 <p>foo<span typeof="mw:DisplaySpace mw:Placeholder" data-parsoid='{"src":" ","isDisplayHack":true}'> </span>: bar</p>
@@ -24551,7 +24909,7 @@ foo : bar
 1. I/B quote minimization: wikitext-only tags should be combined
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p><i>A</i><i>B</i></p>
 <p><b>A</b><b>B</b></p>
 <p><i>A</i><b><i>B</i></b></p>
@@ -24582,7 +24940,7 @@ parsoid=html2wt
 2. I/B quote minimization: wikitext and html tags should not be combined
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p><i>A</i><i data-parsoid='{"stx":"html"}'>B</i></p>
 <p><i>A</i><b><i data-parsoid='{"stx":"html"}'>B</i></b></p>
 !! wikitext
@@ -24595,7 +24953,7 @@ parsoid=html2wt
 3. I/B quote minimization: templated content stops minimization
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p><i>A</i><i about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&#39;&#39;B&#39;&#39;"}},"i":0}}]}'>B</i>
 <p><i>A</i><b about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&#39;&#39;&#39;&#39;&#39;B&#39;&#39;&#39;&#39;&#39;"}},"i":0}}]}'><i>B</i></b>
 !! wikitext
@@ -24608,7 +24966,7 @@ parsoid=html2wt
 4. I/B quote minimization: new content should be mimimized with adjacent old content
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p><i>A</i><i>B</i></p>
 <p><b>A</b><b>B</b></p>
 <p><i>A</i><b><i>B</i></b></p>
@@ -24657,7 +25015,7 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
+!! html/parsoid
 <a rel="mw:WikiLink" href="./Football">Foot</a><a rel="mw:WikiLink" href="./Football">ball</a>
 <a data-parsoid="{}" rel="mw:WikiLink" href="./Football">Foot</a><a rel="mw:WikiLink" href="./Football">ball</a>
 <a data-parsoid="{}" rel="mw:WikiLink" href="./Football">Foot</a><a data-parsoid="{}" rel="mw:WikiLink" href="./Football">ball</a>
@@ -24674,7 +25032,7 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
+!! 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'']]
@@ -24687,7 +25045,7 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": false
 }
-!! html
+!! html/parsoid
 <a rel="mw:WikiLink" href="./Football">Foot</a><a rel="mw:WikiLink" href="./Football">ball</a>
 !! wikitext
 [[Football|Foot]][[Football|ball]]
@@ -24701,10 +25059,10 @@ parsoid={
 Bug 54262: New entities
 !! options
 parsoid=html2wt
+!! html/parsoid
+<span typeof="mw:Entity">&nbsp;</span>
 !! wikitext
 &nbsp;
-!! html
-<span typeof="mw:Entity">&nbsp;</span>
 !! end
 
 ## Note that there is no wikitext output for 'unknownproperty' ##
@@ -24741,7 +25099,7 @@ __NOCONTENTCONVERT__
 Consecutive <pre>s should not get merged
 !! options
 parsoid=html2wt,html2html
-!! html
+!! html/parsoid
 <pre>a</pre><pre>b</pre>
 
 <pre>c
@@ -24773,8 +25131,8 @@ f</pre>
 Edited ISBN links not serializable as ISBN links should serialize as wikilinks
 !! options
 parsoid=html2wt
-!! html
-<a rel="mw:ExtLink" href="./Special:BookSources/1234567890">ISBN 1234567895</a>
+!! html/parsoid
+<a href="./Special:BookSources/1234567890" rel="mw:ExtLink">ISBN 1234567895</a>
 !! wikitext
 [[Special:BookSources/1234567890|ISBN 1234567895]]
 !! end
@@ -24783,7 +25141,7 @@ parsoid=html2wt
 Edited RFC links not serializable as RFC links should serialize as extlinks
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink">New RFC</a>
 !! wikitext
 [//tools.ietf.org/html/rfc123 New RFC]
@@ -24793,7 +25151,7 @@ parsoid=html2wt
 Edited PMID links not serializable as PMID links should serialize as extlinks
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink">New PMID</a>
 !! wikitext
 [//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract New PMID]
@@ -24874,11 +25232,107 @@ parsoid=html2wt
 <nowiki>http://example.com is not a link.</nowiki>
 !! end
 
+!! test
+WTS of autolink-like text after an autolink (T108563)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a> http://example.com is not a link.</p>
+!! wikitext
+http://example.com<nowiki> http://example.com is not a link.</nowiki>
+!! end
+
+!! test
+Magic links inside links (not autolinked)
+!! wikitext
+[[Foo|http://example.com]]
+[[Foo|RFC 1234]]
+[[Foo|PMID 1234]]
+[[Foo|ISBN 123456789x]]
+
+[http://foo.com http://example.com]
+[http://foo.com RFC 1234]
+[http://foo.com PMID 1234]
+[http://foo.com ISBN 123456789x]
+!! html+tidy
+<p><a href="/wiki/Foo" title="Foo">http://example.com</a> <a href="/wiki/Foo" title="Foo">RFC 1234</a> <a href="/wiki/Foo" title="Foo">PMID 1234</a> <a href="/wiki/Foo" title="Foo">ISBN 123456789x</a></p>
+<p><a rel="nofollow" class="external text" href="http://foo.com">http://example.com</a> <a rel="nofollow" class="external text" href="http://foo.com">RFC 1234</a> <a rel="nofollow" class="external text" href="http://foo.com">PMID 1234</a> <a rel="nofollow" class="external text" href="http://foo.com">ISBN 123456789x</a></p>
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="./Foo" title="Foo">http://example.com</a>
+<a rel="mw:WikiLink" href="./Foo" title="Foo">RFC 1234</a>
+<a rel="mw:WikiLink" href="./Foo" title="Foo">PMID 1234</a>
+<a rel="mw:WikiLink" href="./Foo" title="Foo">ISBN 123456789x</a></p>
+
+<p><a rel="mw:ExtLink" href="http://foo.com">http://example.com</a>
+<a rel="mw:ExtLink" href="http://foo.com">RFC 1234</a>
+<a rel="mw:ExtLink" href="http://foo.com">PMID 1234</a>
+<a rel="mw:ExtLink" href="http://foo.com">ISBN 123456789x</a></p>
+!! end
+
+!! test
+Magic links inside image captions (autolinked)
+!! wikitext
+[[File:Foobar.jpg|thumb|http://example.com]]
+[[File:Foobar.jpg|thumb|RFC 1234]]
+[[File:Foobar.jpg|thumb|PMID 1234]]
+[[File:Foobar.jpg|thumb|ISBN 123456789x]]
+!! html+tidy
+<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 rel="nofollow" class="external free" href="http://example.com">http://example.com</a></div>
+</div>
+</div>
+<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 class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc1234">RFC 1234</a></div>
+</div>
+</div>
+<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 class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a></div>
+</div>
+</div>
+<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" 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="//tools.ietf.org/html/rfc1234" rel="mw:ExtLink">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">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
+
+!! test
+WTS of magic word text (T109371)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>RFC 1234</p>
+<p><a href="http://foo.com" rel="mw:ExtLink">RFC 1234</a></p>
+<p><a href="./Foo" rel="mw:WikiLink">RFC 1234</a></p>
+!! wikitext
+<nowiki>RFC 1234</nowiki>
+
+[http://foo.com RFC 1234]
+
+[[Foo|RFC 1234]]
+!! end
+
 !! test
 Edited Redirect link should emit a non-piped wikitext link
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <link rel="mw:PageProp/redirect" href="Bar" data-parsoid='{"a":{"href":"./Foo"},"sa":{"href":"Foo"}}'>
 !! wikitext
 #REDIRECT [[Bar]]
@@ -24888,7 +25342,7 @@ parsoid=html2wt
 T75121: Infer extension name from typeOf if data-mw is not present
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <div typeOf="mw:Extension/foo"></div>
 !! wikitext
 <foo />
@@ -24948,7 +25402,7 @@ parsoid=html2wt,wt2wt
 HTML id attribute with Parsoid-like element ids should not be serialized to wikitext
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <table id='mwAb'>
 <td id='mwAc'>foo</td>
 <td id='serialize-this'>bar</td>
@@ -24964,7 +25418,7 @@ parsoid=html2wt
 Parsoid-like element ids should not be serialized to wikitext unless shadowed
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <div id="mwAQ" data-parsoid='{"stx":"html","a":{"id":"mwAQ"},"sa":{"id":"hello"}}'>ok</div>
 !! wikitext
 <div id="hello">ok</div>
@@ -24991,7 +25445,7 @@ parsoid={
 Never serialize a-tag as html, regardless of what data-parsoid has to say
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"html"}'>Foo</a>
 !! wikitext
 [[Foo]]
@@ -25005,12 +25459,25 @@ parsoid=html2wt
 Never serialize a-tag as html, no matter what attributes it has
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <a bad='true' href='http://boo.org'><img src='http://boohoo.org' /></a>
 !! wikitext
 [http://boo.org http://boohoo.org]
 !! end
 
+# Misnested is an indication that selser can reuse the source but these have
+# shown to sneak through on occasion. See T101768.
+# The original wikitext here is: [http://test.com [[one]] two three]
+!! test
+Strip span tags added to mark as misnested
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p data-parsoid='{}'><a rel="mw:ExtLink" href="http://test.com" data-parsoid='{"targetOff":17,"contentOffsets":[17,34]}'></a><a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"simple","a":{"href":"./One"},"sa":{"href":"one"},"misnested":true}'>one</a><span data-parsoid='{"misnested":true}'> two three</span></p>
+!! wikitext
+[http://test.com][[one]] two three
+!! end
+
 # --------------------------------------------
 # Tests spec'ing wikitext serialization norms |
 # --------------------------------------------
@@ -25019,7 +25486,7 @@ parsoid=html2wt
 Lists: Add space after bullets
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <ul>
 <li>foo</li>
 <li> bar</li>
@@ -25035,7 +25502,7 @@ parsoid=html2wt
 1. Headings: Add space before/after == (T53744)
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <h2>foo</h2>
 <h2> bar</h2>
 <h2>baz </h2>
@@ -25057,8 +25524,8 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
-<h2> <link href="Category:A2" rel="mw:PageProp/Category" />ok</h2>
+!! html/parsoid
+<h2> <link href="./Category:A2" rel="mw:PageProp/Category" />ok</h2>
 !! wikitext
  [[Category:A2]]
 
@@ -25072,7 +25539,7 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
+!! html/parsoid
 <h2></h2>
 !! wikitext
 !! end
@@ -25081,23 +25548,25 @@ parsoid={
 2. Headings: don't suppress empty headings if scrubWikitext is false
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <h2></h2>
 !! wikitext
 ==<nowiki/>==
 !! end
 
 !! test
-3. Headings: don't suppress empty headings for existing headings even if scrubWikitext is true
+3. Headings: suppress empty headings on edits
 !! options
 parsoid={
-  "modes": ["html2wt"],
-  "scrubWikitext": true
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "#x", "remove"]
+  ]
 }
-!! html
-<h2 data-parsoid='{}'></h2>
 !! wikitext
-==<nowiki/>==
+==<span id="x">foo</span>==
+!! wikitext/edited
 !! end
 
 !! test
@@ -25107,7 +25576,7 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
+!! html/parsoid
 <i></i><b></b>
 !! wikitext
 !! end
@@ -25116,20 +25585,160 @@ parsoid={
 2. WT Quote Tags: don't suppress empty style tags if scrubWikitext is false
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <i></i><b></b>
 !! wikitext
 ''<nowiki/>'''''<nowiki/>'''
 !! end
 
 !! test
-1. Indent Pre Nowiki: suppress whitespace at the start of new paragraph
+3. WT Quote Tags: suppress empty style tags on edits
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "#x", "remove"]
+  ]
+}
+!! wikitext
+'''<span id="x">foo</span>'''
+!! wikitext/edited
+!! end
+
+!! test
+1. Anchors: suppress newly created empty anchors
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": true
+}
+!! html/parsoid
+<a rel="mw:WikiLink" href="./Test" title="Test"></a>
+!! wikitext
+!! end
+
+!! test
+2. Anchors: don't suppress empty anchors if scrubWikitext is false
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": false
+}
+!! html/parsoid
+<a rel="mw:WikiLink" href="./Test" title="Test"></a>
+!! wikitext
+[[Test|<nowiki/>]]
+!! end
+
+!! test
+3. Anchors: suppress empty anchors on edits
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "#x", "remove"]
+  ]
+}
+!! wikitext
+[[Test|<span id="x">foo</span>]]
+!! wikitext/edited
+!! end
+
+!! test
+3a. Anchors: do not suppress numbered extlinks
+!! options
+parsoid={
+  "modes": ["wt2wt"],
+  "scrubWikitext": true
+}
+!! wikitext
+[http://foo.com]
+!! html/parsoid
+<a rel="mw:ExtLink" href="http://foo.com"></a>
+!! end
+
+!! test
+3b. Anchors: do not suppress numbered extlinks
+!! options
+parsoid={
+  "modes": ["wt2wt"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "#x", "remove"]
+  ]
+}
+!! wikitext
+[http://foo.com <span id="x">foo</span>]
+!! wikitext/edited
+[http://foo.com]
+!! end
+
+!!test
+Normalizations should be restricted to edited content
+!!options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "h1", "before", "<i></i>"]
+  ]
+}
+!!wikitext
+a
+= =
+b
+!!wikitext/edited
+a
+= =
+b
+!!end
+
+!! test
+1. Multiple normalizations (html2wt)
 !! options
 parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
 !! html
+<h2><i></i></h2>
+<p><a href='Foo' rel='mw:WikiLink'>foo<i></i>
+ </a><b><i></i></b>x</p>
+!! wikitext
+
+[[foo]]
+x
+
+!! end
+
+!! test
+2. Multiple normalizations (selser)
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "#x", "after", "<h1><i></i></h1>\n<p> x<b></b></p>"]
+  ]
+}
+!! wikitext
+<span id="x">foo</span>
+!! wikitext/edited
+<span id="x">foo</span>
+
+x
+!! end
+
+!! test
+1. Indent Pre Nowiki: suppress whitespace at the start of new paragraph
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": true
+}
+!! html/parsoid
 <p> hi</p>
 <p>    hello</p>
 !! wikitext
@@ -25142,7 +25751,7 @@ hello
 2. Indent Pre Nowiki: don't suppress whitespace at the start of new paragraph if scrubWikitext is false
 !! options
 parsoid=html2wt
-!! html
+!! html/parsoid
 <p> hi</p>
 <p>    hello</p>
 !! wikitext
@@ -25190,6 +25799,23 @@ foo
 bar<span>boo</span>
 !! end
 
+!! test
+4. Indent Pre Nowiki: suppress leading whitespace in edited paragraphs
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "p", "html", " a\n b" ]
+  ]
+}
+!! wikitext
+xyz
+!! wikitext/edited
+a
+b
+!! end
+
 !! test
 1. New links that end in spaces
 !! options
@@ -25197,13 +25823,16 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": false
 }
-!! html
+!! html/parsoid
 <p><a rel="mw:WikiLink" href="./Berlin" title="Berlin">Berlin </a>is the capital of Germany.</p>
 <p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo </a><b>bar</b></p>
+<p><a rel="mw:WikiLink" href="./Boston" title="Boston">Boston </a> is a city.</p>
 !! wikitext
 [[Berlin ]]<nowiki/>is the capital of Germany.
 
 [[Foo ]]'''bar'''
+
+[[Boston ]] is a city.
 !! end
 
 !! test
@@ -25213,30 +25842,205 @@ parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
-!! html
+!! html/parsoid
 <p><a rel="mw:WikiLink" href="./Berlin" title="Berlin">Berlin </a>is the capital of Germany.</p>
 <p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo </a><b>bar</b></p>
+<p><a rel="mw:WikiLink" href="./Boston" title="Boston">Boston </a> is a city.</p>
 !! wikitext
 [[Berlin]] is the capital of Germany.
 
 [[Foo]] '''bar'''
+
+[[Boston]] is a city.
+!! end
+
+!! test
+1. Table cells with escapable prefixes
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": false
+}
+!! html
+<table>
+<tr><td>a</td></tr>
+<tr><td>-</td></tr>
+<tr><td>+</td></tr>
+</table>
+!! wikitext
+{|
+|a
+|-
+|<nowiki>-</nowiki>
+|-
+|<nowiki>+</nowiki>
+|}
 !! end
 
 !! test
-3. Existing links that end in spaces
+2. Table cells with escapable prefixes
 !! options
 parsoid={
   "modes": ["html2wt"],
   "scrubWikitext": true
 }
 !! html
-<p><a rel="mw:WikiLink" href="./Berlin" title="Berlin" data-parsoid='{"stx":"simple","a":{"href":"./Berlin"},"sa":{"href":"Berlin "}}'>Berlin </a>is the capital of Germany.</p>
+<table>
+<tr><td>a</td></tr>
+<tr><td>-</td></tr>
+<tr><td>+</td></tr>
+</table>
+!! wikitext
+{|
+|a
+|-
+| -
+|-
+| +
+|}
+!! end
 
-<p><a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"Foo "}}'>Foo </a><b>bar</b></p>
+!! test
+3a. Table cells with escapable prefixes after edits
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "table tbody tr:first-child td:first-child", "remove"]
+  ]
+}
 !! wikitext
-[[Berlin ]]<nowiki/>is the capital of Germany.
+{|
+|a||-
+|}
+!! wikitext/edited
+{|
+| -
+|}
+!! end
 
-[[Foo ]]'''bar'''
+!! test
+3b. Table cells with escapable prefixes after edits
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "table tbody tr:first-child td:first-child", "html", "-" ],
+    [ "#x", "remove" ]
+  ]
+}
+!! wikitext
+{|
+|pqr
+|<span id="x">foo</span>+
+|}
+!! wikitext/edited
+{|
+| -
+| +
+|}
+!! end
+
+# FIXME: This test will fail because
+# normalization doesn't realize that the id attribute
+# will eliminate the escapable scenario
+!! test
+4a. Table cells without escapable prefixes after edits
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "#x", "html", "-" ]
+  ]
+}
+!! wikitext
+{|
+| id="x" |abcd
+|}
+!! wikitext/edited
+{|
+| id="x" |-
+|}
+!! end
+
+## This tests normalizer's ability to discriminate between
+## cells having identical content.
+!! test
+4b. Table cells without escapable prefixes after edits
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "td", "html", "-" ]
+  ]
+}
+!! wikitext
+{|
+|a||b
+|}
+!! wikitext/edited
+{|
+| -||-
+|}
+!! end
+
+## This tests normalizer's ability to not be tripped by
+## comments (and whitespace)
+!! test
+4c. Table cells without escapable prefixes after edits
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "table tbody tr td:first-child", "remove" ]
+  ]
+}
+!! wikitext
+{|
+|-
+<!--foo--> |a||-
+|}
+!! wikitext/edited
+{|
+|-
+<!--foo--> | -
+|}
+!! end
+
+## This tests normalizer's ability to handle HTML cells
+!! test
+4d. Table cells without escapable prefixes after edits
+!! options
+parsoid={
+  "modes": ["selser"],
+  "scrubWikitext": true,
+  "changes": [
+    [ "td", "html", "-" ]
+  ]
+}
+!! wikitext
+<table>
+<tr><td>a</td></tr>
+</table>
+!! wikitext/edited
+<table>
+<tr><td>-</td></tr>
+</table>
+!! end
+
+!! test
+Escape nowiki DOM elements
+!! options
+parsoid=html2wt
+!! html/parsoid
+<nowiki><i>foo</i></nowiki>
+!! wikitext
+&lt;nowiki&gt;''foo''&lt;/nowiki&gt;
 !! end
 
 # ---------------------------------------------------