# This file will hold tests for table fixup dom handlers.
# For now, we are only adding tests for unsupported scenarios here.
# Eventually, once the monolithic parser test file is split up,
# all table fixup tests will move here.
!! options
version=2
parsoid-compatible=wt2html,wt2wt
!! end

!! article
Main Page
!! text
blah blah
!! endarticle

!! article
Template:1x
!! text
{{{1}}}
!! endarticle

!! article
Template:td_class
!! text
class="foo"
!! endarticle

!! article
Template:td_content
!! text
| foobar
!! endarticle

!! article
Template:td_attrs_and_content
!! text
{{{1}}} | foobar
!! endarticle

!! article
Template:td_attrs_and_content_with_newlines
!! text
class="foo" | foobar 
  baz 
!! endarticle

!! article
No Merging Here
!! text
Dummy article to suppress redlinks in tests
!! end

## This fixup requires reaching across a <tbody> boundary to
## merge a child of <tbody><tr><td> with a <caption> node.
## We won't likely support this unless this is really necessary.
!! test
Unsupported scenario: Cell combining with captions
!! options
parsoid=wt2html
!! wikitext
{|
|+class="foo"{{1x|{{!}}some caption}}
|bar
|}
!! html/php
<table>
<caption class="foo">some caption
</caption>
<tbody><tr>
<td>bar
</td></tr></tbody></table>
!! html/parsoid
<table>
<caption>class="foo"</caption><tbody about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}some caption"}},"i":0}},"\n|bar\n"]}'><tr><td>some caption</td>
<td>bar</td></tr>
</tbody></table>
!! end

!! test
Unsupported scenario: Templated cell merge with another templated cell
!! options
parsoid=wt2html
!! wikitext
{|
|{{1x|1=class="foo"}}{{1x|{{!}}foo}}
|}
!! html/php
<table>
<tbody><tr>
<td class="foo">foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":["|{{1x|1=class=\"foo\"}}",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}foo"}},"i":0}}]}'>foo</td></tr>
</tbody></table>
!! end

## FIXME:Same as "6. table-fixups td-td cell-combining: prev=single_pipe,attrs,no_content; cell=attrs"
## This test fails in standalone mode and hence marked +integrated only
!! test
Templated cell with attributes merging with previous cell
!! options
parsoid=wt2html
!! wikitext
{|
|class="foo"{{1x|1={{!}}title="foo"{{!}}foo}}
|}
!! html/php
<table>
<tbody><tr>
<td class="foo">title="foo"|foo
</td></tr></tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" class="foo" data-mw='{"parts":["|class=\"foo\"",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}title=\"foo\"{{!}}foo"}},"i":0}}]}'>title="foo"|foo</td></tr>
</tbody></table>
!! end

## FIXME:Same as "7. table-fixups td-td cell-combining: prev=single_pipe,attrs,content; cell=no_attrs"
!! test
Templated cell merging with previous cell with attributes
!! wikitext
{|
|class="foo"|title="foo"{{1x|{{!}}foo}}
|}
!! html/php
<table>
<tbody><tr>
<td class="foo">title="foo"|foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" class="foo" data-mw='{"parts":["|class=\"foo\"|title=\"foo\"",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}foo"}},"i":0}}]}'>title="foo"|foo</td></tr>
</tbody></table>
!! end

## FIXME:Same as "1. table-fixups td-td cell-combining: prev=single_pipe,no_attrs,no_content; cell=no_attrs"
!! test
Merge tds (T52603)
!! wikitext
{|
|{{1x|{{!}} foo}}
|}
!! html/php
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
<table><tbody>
<tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}} foo"}},"i":0}}]}'> foo</td></tr>
</tbody></table>
!! end

!! test
Merge tds in nested transclusion content (T52603)
!! wikitext
{{1x|<div>}}
{|
|{{1x|{{!}} foo}}
|}
{{1x|</div>}}
!! html/php
<div>
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
</div>
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>"}},"i":0}},"\n{|\n|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}} foo"}},"i":1}},"\n|}\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/div>"}},"i":2}}]}'>
<table>
<tbody><tr><td>foo</td></tr>
</tbody></table>
</div>
!! end

!! test
Table cell attributes and content from multiple templates
!! wikitext
{|
|-
| {{td_class}} {{td_attrs_and_content|1=style='border:1px solid blue'}} baz
|}
!! html/php
<table>

<tbody><tr>
<td class="foo" style="border:1px solid blue">foobar baz
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
<td class="foo" style="border:1px solid blue" typeof="mw:Transclusion" about="#mwt2" data-parsoid='{"pi":[[],[{"k":"1","named":true}]]}' data-mw='{"parts":["| ",{"template":{"target":{"wt":"td_class","href":"./Template:Td_class"},"params":{},"i":0}}," ",{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"style=&apos;border:1px solid blue&apos;"}},"i":1}}," baz"]}'>foobar baz</td></tr>
</tbody></table>
!! end

!! test
Table cell attribute merging edge cases
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
{|
| {{td_attrs_and_content|1=<div>foo</div> class="foo"}} baz
|-
|{{td_attrs_and_content|1=[[No Merging Here]] class="foo"}} baz
|-
|{{td_attrs_and_content|1=[[wikipedia:No Merging Here]] class="foo"}} baz
|-
|{{td_attrs_and_content|1=[[en:No Merging Here]] class="foo"}} baz
|-
|{{td_attrs_and_content|1=[[Category:No Merging Here]] class="foo"}} baz
|-
|{{td_attrs_and_content|1=[[File:Foo.jpg]] class="foo"}} baz
|}
!! html/php
<table>
<tbody><tr>
<td class="foo">foobar baz
</td></tr>
<tr>
<td><a href="/wiki/No_Merging_Here" title="No Merging Here">No Merging Here</a> class="foo" | foobar baz
</td></tr>
<tr>
<td><a href="http://en.wikipedia.org/wiki/No_Merging_Here" class="extiw" title="wikipedia:No Merging Here">wikipedia:No Merging Here</a> class="foo" | foobar baz
</td></tr>
<tr>
<td> class="foo" | foobar baz
</td></tr>
<tr>
<td> class="foo" | foobar baz
</td></tr>
<tr>
<td><span class="mw-default-size" typeof="mw:Error mw:File"><a href="/index.php?title=Special:Upload&amp;wpDestFile=Foo.jpg" class="new" title="File:Foo.jpg"><span class="mw-file-element mw-broken-media">File:Foo.jpg</span></a></span> class="foo" | foobar baz
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td class="foo" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":["| ",{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"&lt;div>foo&lt;/div> class=\"foo\""}},"i":0}}," baz"]}'>foobar baz</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td><a rel="mw:WikiLink" href="./No_Merging_Here" title="No Merging Here" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./No_Merging_Here"},"sa":{"href":"No Merging Here"},"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"[[No Merging Here]] class=\"foo\""}},"i":0}}]}'>No Merging Here</a><span about="#mwt2"> class="foo" | foobar</span> baz</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/No%20Merging%20Here" title="wikipedia:No Merging Here" about="#mwt3" typeof="mw:Transclusion" class="extiw" data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/No%20Merging%20Here"},"sa":{"href":"wikipedia:No Merging Here"},"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"[[wikipedia:No Merging Here]] class=\"foo\""}},"i":0}}]}'>wikipedia:No Merging Here</a><span about="#mwt3"> class="foo" | foobar</span> baz</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td><link rel="mw:PageProp/Language" href="//en.wikipedia.org/wiki/No%20Merging%20Here" about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"[[en:No Merging Here]] class=\"foo\""}},"i":0}}]}'/><span about="#mwt4"> class="foo" | foobar</span> baz</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td><link rel="mw:PageProp/Category" href="./Category:No_Merging_Here" about="#mwt5" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"[[Category:No Merging Here]] class=\"foo\""}},"i":0}}]}'/><span about="#mwt5"> class="foo" | foobar</span> baz</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td><span class="mw-default-size" typeof="mw:Transclusion mw:Error mw:File" about="#mwt3" data-parsoid='{"optList":[],"pi":[[{"k":"1","named":true}]]}' data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}],"parts":[{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"[[File:Foo.jpg]] class=\"foo\""}},"i":0}}]}'><a href="./Special:FilePath/Foo.jpg"><span class="mw-file-element mw-broken-media" resource="./File:Foo.jpg">File:Foo.jpg</span></a></span><span about="#mwt3"> class="foo" | foobar</span> baz</td></tr>
</tbody></table>
!! end

!! test
Fixup of interrupted table-cell parsing because of multi-line transclusion
!! wikitext
{|
! class="c1" |Col 1.1!! class="c2" |{{1x|
1=Col 1.2}}!! class="c3" |Col 1.3!! class="c4" |Col 1.4
! class="d1" |Col 2.1!! class="d2" |{{1x|
1=Col 2.2}}!! class="d3" |Col 2.3! abcd!! class="d4" |Col 2.4
| class="e1" |Col 3.1|| class="e2" |{{1x|
1=Col 3.2}}|| class="e3" |Col 3.3| abcd|| class="e4" |Col 3.4
|}
!! html/php
<table>
<tbody><tr>
<th class="c1">Col 1.1</th>
<th class="c2">Col 1.2</th>
<th class="c3">Col 1.3</th>
<th class="c4">Col 1.4
</th>
<th class="d1">Col 2.1</th>
<th class="d2">Col 2.2</th>
<th class="d3">Col 2.3! abcd</th>
<th class="d4">Col 2.4
</th>
<td class="e1">Col 3.1</td>
<td class="e2">Col 3.2</td>
<td class="e3">Col 3.3| abcd</td>
<td class="e4">Col 3.4
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><th class="c1">Col 1.1</th><th class="c2" data-parsoid='{"stx":"row"}'><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Col 1.2"}},"i":0}}]}'>Col 1.2</span></th><th class="c3" data-parsoid='{"stx":"row"}'>Col 1.3</th><th class="c4" data-parsoid='{"stx":"row"}'>Col 1.4</th>
<th class="d1">Col 2.1</th><th class="d2" data-parsoid='{"stx":"row"}'><span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Col 2.2"}},"i":0}}]}'>Col 2.2</span></th><th class="d3" data-parsoid='{"stx":"row"}'>Col 2.3! abcd</th><th class="d4" data-parsoid='{"stx":"row"}'>Col 2.4</th>
<td class="e1">Col 3.1</td><td class="e2" data-parsoid='{"stx":"row"}'><span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Col 3.2"}},"i":0}}]}'>Col 3.2</span></td><td class="e3" data-parsoid='{"stx":"row"}'>Col 3.3| abcd</td><td class="e4" data-parsoid='{"stx":"row"}'>Col 3.4</td></tr>
</tbody></table>
!! end

!! test
Ensure newlines in collected attribute doesn't trip up reparsing
!! wikitext
{|
|rowspan="1" {{td_attrs_and_content_with_newlines}}
|}
!! html/php
<table>
<tbody><tr>
<td rowspan="1" class="foo">foobar
<pre> baz
</pre>
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td rowspan="1" class="foo" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"pi":[[]]}' data-mw='{"parts":["|rowspan=\"1\" ",{"template":{"target":{"wt":"td_attrs_and_content_with_newlines","href":"./Template:Td_attrs_and_content_with_newlines"},"params":{},"i":0}}]}'>foobar 
<pre about="#mwt1"> baz </pre></td></tr>
</tbody></table>
!! end

!! test
Ensure a cell with newlines doesn't combine with following cell
!! wikitext
{|
|-
| combined-and-lost {{td_content|}}
|-
|not combined
 {{td_content|}}
|}
!! html/php
<table>

<tbody><tr>
<td>foobar
</td></tr>
<tr>
<td>not combined
</td>
<td>foobar
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
<td about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":["| combined-and-lost ",{"template":{"target":{"wt":"td_content","href":"./Template:Td_content"},"params":{"1":{"wt":""}},"i":0}}]}'>foobar</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td>not combined
 </td><td about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"td_content","href":"./Template:Td_content"},"params":{"1":{"wt":""}},"i":0}}]}'>foobar</td></tr>
</tbody></table>
!! end

!! test
Table cell attributes and nested transclusions
!! wikitext
{|
| '''{{td_attrs_and_content|1=style='border:1px solid blue;'}}'''
|}
!! html/php
<table>
<tbody><tr>
<td>foobar<b></b>
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td style="border:1px solid blue;" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["| &apos;&apos;&apos;",{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"style=&apos;border:1px solid blue;&apos;"}},"i":0}},"&apos;&apos;&apos;"]}'>foobar</td></tr>
</tbody></table>
!! end

!! test
T331486: Newline entities should be properly handled while fixing up table cells
!! wikitext
{|
|{{td_attrs_and_content|1=title="a&#10;b" class="xyz"}}
|}
!! html/php
<table>
<tbody><tr>
<td title="a&#10;b" class="xyz">foobar
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td title="a
b" class="xyz" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["|",{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"title=\"a&amp;#10;b\" class=\"xyz\""}},"i":0}}]}'>foobar</td></tr>
</tbody></table>
!! end

!! article
Template:tdfoo
!! text
|| y
!! endarticle

# This test currently fails in Parsoid
!! test
Ensure td-cell-type is switched to th when the first cell in a row is a <th>
!! wikitext
{|
!a||b
!c{{tdfoo}}
|}
!! html/php
<table>
<tbody><tr>
<th>a</th>
<th>b
</th>
<th>c</th>
<th>y
</th></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr>
<th>a</th><th>b</tb>
<th>c</th><th about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"tdfoo","href":"./Template:Tdfoo"},"params":{},"i":0}}]}'>y</th></tr>
</tbody></table>
!! end

## ---------------------------------------------------------------------
## Semi-exhaustive list of tests for TableFixups::reparseWithPreviousell
## A bunch of these tests fail standalone mode, but pass integrated mode
## Those tests use html/parsoid+integrated sections only
## ---------------------------------------------------------------------
!! test
1. table-fixups td-td cell-combining: prev=single_pipe,no_attrs,no_content; cell=no_attrs
!! wikitext
{|
|{{1x|{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>y
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}y"}},"i":0}}]}'>y</td></tr>
</tbody></table>
!! end

## In standalone mode, Parsoid fails this test because the template parses as
## two cells instead of a single cell.
!! test
2. table-fixups td-td cell-combining: prev=single_pipe,no_attrs,no_content; cell=attrs
!! wikitext
{|
|{{1x|1={{!}}class='x'{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>class='x'|y
</td></tr></tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}class=&apos;x&apos;{{!}}y"}},"i":0}}]}'>class='x'|y</td></tr>
</tbody></table>
!! end

!! test
3. table-fixups td-td cell-combining: prev=single_pipe,no_attrs,content; cell=no_attrs
!! wikitext
{|
| b {{1x|{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>y
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["| b ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}y"}},"i":0}}]}'>y</td></tr>
</tbody></table>
!! end

!! test
4. table-fixups td-td cell-combining: prev=single_pipe,no_attrs,content; cell=attrs
!! wikitext
{|
| b {{1x|1={{!}}class='x'{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>class='x'|y
</td></tr></tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["| b ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}class=&apos;x&apos;{{!}}y"}},"i":0}}]}'>class='x'|y</td></tr>
!! end

!! test
5. table-fixups td-td cell-combining: prev=single_pipe,attrs,no_content; cell=no_attrs
!! wikitext
{|
|title='a'|{{1x|{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>title='a'</td>
<td>y
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>title='a'</td><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}y"}},"i":0}}]}'>y</td></tr>
</tbody></table>
!! end

!! test
6. table-fixups td-td cell-combining: prev=single_pipe,attrs,no_content; cell=attrs
!! wikitext
{|
|title='a'|{{1x|1={{!}}class='x'{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>title='a'</td>
<td class="x">y
</td></tr></tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr><td>title='a'</td><td class='x' about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}class=&apos;x&apos;{{!}}y"}},"i":0}}]}'>y</td></tr>
</tbody></table>
!! end

!! test
7. table-fixups td-td cell-combining: prev=single_pipe,attrs,content; cell=no_attrs
!! wikitext
{|
|title='a'| b {{1x|{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td title="a">b |y
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" title="a" data-mw='{"parts":["|title=&apos;a&apos;| b ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}y"}},"i":0}}]}'>b |y</td></tr>
</tbody></table>
!! end

!! test
8. table-fixups td-td cell-combining: prev=single_pipe,attrs,content; cell=attrs
!! wikitext
{|
|title='a'| b {{1x|1={{!}}class='x'{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td title="a">b |class='x'|y
</td></tr></tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" title="a" data-mw='{"parts":["|title=&apos;a&apos;| b ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}class=&apos;x&apos;{{!}}y"}},"i":0}}]}'>b |class='x'|y</td></tr>
</tbody></table>
!! end

!! test
9. table-fixups td-td cell-combining: prev=double_pipe,no_content; cell=no_attrs
!! wikitext
{|
||{{1x|{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td></td>
<td>y
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td></td><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}y"}},"i":0}}]}'>y</td></tr>
</tbody></table>
!! end

!! test
10. table-fixups td-td cell-combining: prev=double_pipe,no_content; cell=attrs
!! wikitext
{|
||{{1x|1={{!}}class='x'{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td></td>
<td class="x">y
</td></tr></tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr><td></td><td class='x' about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}class=&apos;x&apos;{{!}}y"}},"i":0}}]}'>y</td></tr>
</tbody></table>
!! end

!! test
11. table-fixups td-td cell-combining: prev=double_pipe,content; cell=no_attrs
!! wikitext
{|
|| a {{1x|{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>a |y
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|| a ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}y"}},"i":0}}]}'>a |y</td></tr>
</tbody></table>
!! end

!! test
12. table-fixups td-td cell-combining: prev=double_pipe,content; cell=attrs
!! wikitext
{|
|| a {{1x|1={{!}}class='x'{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>a |class='x'|y
</td></tr></tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|| a ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}class=&apos;x&apos;{{!}}y"}},"i":0}}]}'>a |class='x'|y</td></tr>
</tbody></table>
!! end

## These are the only interesting th-th combination scenarios that are different from td-td
!! test
1. table-fixups th-th cell-combining: cell=no-attrs
!! wikitext
{|
!{{1x|!y}}
|}
!! html/php
<table>
<tbody><tr>
<th>!y
</th></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><th about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":["!",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"!y"}},"i":0}}]}'>!y</th></tr>
</tbody></table>
!! end

# NOTE: the whitespace in "! class='x'" is important
# because "!!class='x'" and ""!! class='x'"" parse differently.
# That seems like a bug in legacy (which Parsoid replicates).
!! test
2. table-fixups th-th cell-combining: cell=attrs
!! wikitext
{|
!{{1x|1=! class="x"{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<th class="x">y
</th></tr></tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr><th class="x" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"firstWikitextNode":"TH","pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":["!",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"! class=\"x\"{{!}}y"}},"i":0}}]}'>y</th></tr>
</tbody></table>

!! end

!! test
Templated cell not merging with previous cell with attributes and trailing vertical bar
!! wikitext
{|
| class="foo" |content|{{1x|{{!}}foo}}
|}
!! html/php
<table>
<tbody><tr>
<td class="foo">content</td>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td class="foo">content</td><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}foo"}},"i":0}}]}'>foo</td></tr>
</tbody></table>
!! end

!! test
Templated cell not merging with previous cell and trailing vertical bar
!! wikitext
{|
|[[Main Page]] content|{{1x|{{!}}foo}}
|}
!! html/php
<table>
<tbody><tr>
<td><a href="/wiki/Main_Page" title="Main Page">Main Page</a> content</td>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr>
<td><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a> content</td><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}foo"}},"i":0}}]}'>foo</td>
</tr>
</tbody></table>
!! end

!! test
Templated cell not merging with previous cell and trailing vertical bar, attributes and row syntax
!! wikitext
{|
|one||[[two]]||three|{{1x|{{!}}four}}
|}
!! html/php
<table>
<tbody><tr>
<td>one</td>
<td><a href="/index.php?title=Two&amp;action=edit&amp;redlink=1" class="new" title="Two (page does not exist)">two</a></td>
<td>three</td>
<td>four
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>one</td><td data-parsoid='{"stx":"row"}'><a rel="mw:WikiLink" href="./Two?action=edit&amp;redlink=1" title="Two" class="new" typeof="mw:LocalizedAttrs" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Two"]}}'>two</a></td><td data-parsoid='{"stx":"row"}'>three</td><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}four"}},"i":0}}]}'>four</td></tr>
</tbody></table>
!! end

!! test
Convert non-plaintext attributes to content
!! wikitext
{|
|test [http://google.com 123]|{{1x|{{!}}four}}
|}
!! html/php
<table>
<tbody><tr>
<td>test <a rel="nofollow" class="external text" href="http://google.com">123</a></td>
<td>four
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>test <a rel="mw:ExtLink nofollow" href="http://google.com" class="external text">123</a></td><td about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"row"}' data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}four"}},"i":0}}]}'>four</td></tr>
</tbody></table>
!! end

!! test
Convert multiple expanded attributes to content
!! wikitext
{|
|{{1x|title}}='a' class='234'|{{1x|{{!}}y}}
|title='{{1x|a}}'|{{1x|{{!}}y}}
|}
!! html/php
<table>
<tbody><tr>
<td>title='a' class='234'</td>
<td>y
</td>
<td>title='a'</td>
<td>y
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt4"><span about="#mwt9" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"title"}},"i":0}}]}'>title</span>='a' class='234'</td><td about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"row"}' data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}y"}},"i":0}}]}'>y</td>
<td about="#mwt8">title='<span about="#mwt10" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span>'</td><td about="#mwt5" typeof="mw:Transclusion" data-parsoid='{"stx":"row"}' data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}y"}},"i":0}}]}'>y</td></tr>
</tbody></table>
!! end

!! test
Combine with a previous cell that follows fostered content
!! options
parsoid=wt2html
!! wikitext
{|
{{1x|{{!}}-}}
q
|{{1x|{{!}}test}}
|}
!! html/php


q
<table><tbody><tr>
<td>test
</td></tr></tbody></table>
!! html/parsoid+integrated
<p>q</p>
<table>
<tbody typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}-"}},"i":0}},"\nq\n|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}test"}},"i":1}},"\n"]}'>
<tr>
<td>test</td>
</tr>
</tbody>
</table>
!! end

!! test
Pipes in nowikis should suppress table fixups
!! options
parsoid=wt2html
!! wikitext
{|
|-
|<nowiki>foo||</nowiki>||bar
|-
|{{1x|<nowiki>foo||</nowiki>}}||bar
|}
!! html/php
<table>

<tbody><tr>
<td>foo||</td>
<td>bar
</td></tr>
<tr>
<td>foo||</td>
<td>bar
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr>
<td><span typeof="mw:Nowiki">foo||</span></td><td>bar</td></tr>
<tr>
<td><span typeof="mw:Nowiki mw:Transclusion" about="#mwt5" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;nowiki>foo||&lt;/nowiki>"}},"i":0}}]}'>foo||</span></td><td>bar</td></tr>
</tbody></table>
!! end
