# The parsoid-compatible option below is only relevant when we are running
# parser tests in integrated mode with Parsoid. This option is ignored
# when this test file is run with Parsoid in standalone mode.
!! options
version=2
parsoid-compatible=wt2html,wt2wt
!! end

# This is the standard article assumed to exist.
!! article
Main Page
!! text
blah blah
!! endarticle

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

!! article
Template:tbl-start
!! text
{|
!! endarticle

!! article
Template:tbl-end
!! text
|}
!! endarticle

!! article
Template:table_attribs
!! text
<noinclude>
|</noinclude>style="color:red;"|Foo
!! endarticle

!! article
Template:table_attribs_2
!! text
<noinclude>
|</noinclude>data-sort-value="" style="color:red;"|Foo
|Bar||Baz
!! endarticle

!! article
Template:table_attribs_4
!! text
| style="background-color:#DC241f;" width="10px" |
!! endarticle

!! article
Template:table_attribs_5
!! text
<noinclude>
|</noinclude>style="color:red;"||Bar
!! endarticle

!! article
Template:table_header_cells
!! text
{{table_attribs}}!!style='color:red;'|''Bar''||style='color:brown;'|''Foo'' and Baz
!! endarticle

!! article
Template:table_cells
!! text
{{table_attribs}}||style='color:red;'|''Bar''||style='color:brown;'|''Foo'' and Baz
!! endarticle

!! article
Template:table_cell_content
!! text
{{{attr|}}}{{{cmt|}}}| foo
!! endarticle

## FIXME: Unused right now
!! article
Template:table_cell_content_with_leading_spc
!! text
 | foo
!! endarticle

!! article
Test
!! text
foo
!! end

###
### Table tests
### some content taken from http://meta.wikimedia.org/wiki/MediaWiki_User%27s_Guide:_Using_tables
###

# This should not produce <table></table> as <table><tr><td></td></tr></table>
# is the bare minimum required by the spec, see:
# https://www.w3.org/TR/xhtml-modularization/dtd_module_defs.html#a_module_Basic_Tables
# Parsoid team replies: empty table tags are legal in HTML5
!! test
A table with no data.
!! options
parsoid=wt2html
!! wikitext
{||}
!! html/php
!! html/parsoid
<table></table>
!! end

!! test
A table with no data (take 2)
!! wikitext
{|
|}
!! html/php
<table>
<tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<table></table>
!! end

!! test
A table with no data generated by a <table> markup
!! wikitext
<table></table>
!! html/php
<table></table>
!! html/parsoid
<table data-parsoid='{"stx":"html"}'></table>
!! end

# PHP has one more row in the output than Parsoid does: T208619
!! test
Parsoid: Don't paragraph-wrap fosterable content even if table syntax is unbalanced
!! options
parsoid=wt2html
!! wikitext
{|
<td>
<td>
</td>



|}
!! html/php
<table>
<tbody><tr><td>
</td><td>
</td>



</tr><tr><td></td></tr></tbody></table>
!! html/parsoid
<table>

<tbody>
<tr>
<td></td>

<td>
</td></tr>



</tbody></table>
!! end

!! test
A table with stray table end tags on start tag line (wt2html)
!! options
parsoid=wt2html
!! wikitext
{|style="color: red;"|}

{|style="color: red;" |}
|foo
|}

{|style="color: red;"|} id="foo"
|foo
|}

{|style="color: red;" |} id="foo"
|foo
|}
!! html/php
<table style="color: red;">

</table><table style="color: red;">
<tbody><tr>
<td>foo
</td></tr></tbody></table>
<table style="color: red;" id="foo">
<tbody><tr>
<td>foo
</td></tr></tbody></table>
<table style="color: red;" id="foo">
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
<table style="color: red;"></table>

<table style="color: red;">
<tbody><tr>
<td>foo</td>
</tr></tbody>
</table>

<table style="color: red;" id="foo">
<tbody><tr>
<td>foo</td>
</tr></tbody>
</table>

<table style="color: red;" id="foo">
<tbody><tr>
<td>foo</td>
</tr></tbody>
</table>
!! end

# A table with nothing but a caption is invalid XHTML, we might want to render
# this as <p>caption</p>
# Parsoid team replies: table with only a caption is legal in HTML5
!! test
A table with nothing but a caption
!! wikitext
{|
|+caption
|}
!! html/php
<table>
<caption>caption
</caption><tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<table><caption>caption</caption></table>
!! end

!! test
A table with caption with default-spaced attributes and a table row
!! wikitext
{|
|+ style="color: red;" |caption1
|-
|foo
|}
!! html
<table>
<caption style="color: red;">caption1
</caption>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! end

!! test
A table with captions with non-default spaced attributes and a table row
!! wikitext
{|
|+style="color: red;"|caption2
|+ style="color: red;"|caption3
|-
|foo
|}
!! html
<table>
<caption style="color: red;">caption2
</caption>
<caption style="color: red;">caption3
</caption>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! end

!! test
Multi-line captions in tables
!! wikitext
{|
|+line 1 of caption
line 2 of caption
|data
|}
!! html
<table>
<caption>line 1 of caption
line 2 of caption
</caption>
<tbody><tr>
<td>data
</td></tr></tbody></table>
!! end

!! test
Table td-cell syntax variations
!! wikitext
{|
|foo bar foo|baz
|foo bar foo||baz
|style='color:red;'|baz
|style='color:red;'||baz
|}
!! html
<table>
<tbody><tr>
<td>baz
</td>
<td>foo bar foo</td>
<td>baz
</td>
<td style="color:red;">baz
</td>
<td>style='color:red;'</td>
<td>baz
</td></tr></tbody></table>
!! end

!! test
Simple table
!! wikitext
{|
|1||2
|-
|3||4
|}
!! html
<table>
<tbody><tr>
<td>1</td>
<td>2
</td></tr>
<tr>
<td>3</td>
<td>4
</td></tr></tbody></table>
!! end

## T387922
!! test
Row-syntax table cells require that the row start with a table cell
!! wikitext
{|
|a
b||c
|}
!! html
<table>
<tbody><tr>
<td>a
<p>b||c
</p>
</td></tr></tbody></table>
!! end

!! test
Simple table but with multiple dashes for row wikitext
!! wikitext
{|
|foo
|-----
|bar
|}
!! html
<table>
<tbody><tr>
<td>foo
</td></tr>
<tr>
<td>bar
</td></tr></tbody></table>
!! end

!! test
Multiplication table
!! wikitext
{| border="1" cellpadding="2"
|+Multiplication table
|-
!&times;!!1!!2!!3
|-
!1
|1||2||3
|-
!2
|2||4||6
|-
!3
|3||6||9
|-
!4
|4||8||12
|-
!5
|5||10||15
|}
!! html
<table border="1" cellpadding="2">
<caption>Multiplication table
</caption>
<tbody><tr>
<th>&#215;</th>
<th>1</th>
<th>2</th>
<th>3
</th></tr>
<tr>
<th>1
</th>
<td>1</td>
<td>2</td>
<td>3
</td></tr>
<tr>
<th>2
</th>
<td>2</td>
<td>4</td>
<td>6
</td></tr>
<tr>
<th>3
</th>
<td>3</td>
<td>6</td>
<td>9
</td></tr>
<tr>
<th>4
</th>
<td>4</td>
<td>8</td>
<td>12
</td></tr>
<tr>
<th>5
</th>
<td>5</td>
<td>10</td>
<td>15
</td></tr></tbody></table>
!! end

!! test
Accept "||" in table headings
!! wikitext
{|
!h1||h2
|}
!! html
<table>
<tbody><tr>
<th>h1</th>
<th>h2
</th></tr></tbody></table>
!! end

!! test
Accept "!!" in table data
!! wikitext
{|
|Foo!!||
|}
!! html
<table>
<tbody><tr>
<td>Foo!!</td>
<td>
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{}'> Foo!! </td><td data-parsoid='{"stx":"row"}'></td></tr>
</tbody></table>
!! end

!! test
Accept "||" in indented table headings
!! wikitext
:{|
!h1||h2
|}
!! html
<dl><dd><table>
<tbody><tr>
<th>h1</th>
<th>h2
</th></tr></tbody></table></dd></dl>
!! end

!! test
Accept "!!" in templates
!! wikitext
{|
!a {{1x|b!!c}}
|}
!! html/php
<table>
<tbody><tr>
<th>a b</th>
<th>c
</th></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><th typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":["!a ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b!!c"}},"i":0}}]}'>a b</th><th about="#mwt1">c</th></tr>
</tbody></table>
!! end

!! test
Accept "!!" in table headings after newline
!! wikitext
{|
!a
b!!c
|}
!! html/php
<table>
<tbody><tr>
<th>a
<p>b!!c
</p>
</th></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><th>a
<p>b!!c</p></th></tr>
</tbody></table>
!! end

!! test
Accept "!!" in table data of mixed wikitext / html syntax
!! wikitext
{|
!a
<tr><td>b!!c</td></tr>
|}
!! html/php
<table>
<tbody><tr>
<th>a
</th></tr><tr><td>b!!c</td></tr>
</tbody></table>
!! html/parsoid
<table>
<tbody><tr><th>a</th></tr>
<tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'>b!!c</td></tr>
</tbody></table>
!! end

!! test
Accept empty attributes in td/th cells (td/th cells starting with leading ||)
!! wikitext
{|
!|h1
||a
|}
!! html
<table>
<tbody><tr>
<th>h1
</th>
<td>a
</td></tr></tbody></table>
!! end

!!test
Accept "| !" at start of line in tables (ignore !-attribute)
!! wikitext
{|
|-
|!style="color:red"|bar
|}
!! html
<table>

<tbody><tr>
<td>bar
</td></tr></tbody></table>
!!end

!!test
Allow +/- in 2nd and later cells in a row, in 1st cell when td-attrs are present, or in 1st cell when there is a space between "|" and +/- 
!! wikitext
{|
|-
|style='color:red;'|+1
|style='color:blue;'|-1
|-
|1||2||3
|1||+2||-3
|-
| +1
| -1
|}
!! html
<table>

<tbody><tr>
<td style="color:red;">+1
</td>
<td style="color:blue;">-1
</td></tr>
<tr>
<td>1</td>
<td>2</td>
<td>3
</td>
<td>1</td>
<td>+2</td>
<td>-3
</td></tr>
<tr>
<td>+1
</td>
<td>-1
</td></tr></tbody></table>
!!end

# Differences between Parsoid and PHP re: trailing whitespace in a
# table cell.
!! test
Table rowspan
!! wikitext
{| border=1
|Cell 1, row 1
|rowspan=2|Cell 2, row 1 (and 2)
|Cell 3, row 1
|-
|Cell 1, row 2
|Cell 3, row 2
|}
!! html/php
<table border="1">
<tbody><tr>
<td>Cell 1, row 1
</td>
<td rowspan="2">Cell 2, row 1 (and 2)
</td>
<td>Cell 3, row 1
</td></tr>
<tr>
<td>Cell 1, row 2
</td>
<td>Cell 3, row 2
</td></tr></tbody></table>
!! html/parsoid
<table border="1">
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td>Cell 1, row 1</td>
<td rowspan="2">Cell 2, row 1 (and 2)</td>
<td>Cell 3, row 1</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td>Cell 1, row 2</td>
<td>Cell 3, row 2</td></tr>
</tbody></table>
!! end

!! test
Nested table
!! wikitext
{| border=1
| &alpha;
|
{| bgcolor=#ABCDEF border=2
|nested
|-
|table
|}
|the original table again
|}
!! html
<table border="1">
<tbody><tr>
<td>&#945;
</td>
<td>
<table bgcolor="#ABCDEF" border="2">
<tbody><tr>
<td>nested
</td></tr>
<tr>
<td>table
</td></tr></tbody></table>
</td>
<td>the original table again
</td></tr></tbody></table>
!! end

!! test
Invalid attributes in table cell (T3830)
!! wikitext
{|
|Cell:|broken
|}
!! html
<table>
<tbody><tr>
<td>broken
</td></tr></tbody></table>
!! end

!! test
Table cell attributes: Pipes protected by nowikis should be treated as a plain character
!! wikitext
{|
|title="foo" |bar
|title="foo<nowiki>|</nowiki>" |bar
|title="foo<nowiki>|</nowiki>" bar
|}
!! html/php
<table>
<tbody><tr>
<td title="foo">bar
</td>
<td title="foo&#124;">bar
</td>
<td>title="foo|" bar
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td title="foo">bar</td>
<td title="foo|" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"a":{"title":"foo|"},"sa":{"title":"foo&lt;nowiki>|&lt;/nowiki>"}}' data-mw='{"attribs":[[{"txt":"title"},{"html":"foo&lt;span typeof=\"mw:Nowiki\" data-parsoid=&apos;{\"dsr\":[32,50,8,9]}&apos;>|&lt;/span>"}]]}'>bar</td>
<td>title="foo<span typeof="mw:Nowiki">|</span>" bar</td></tr>
</tbody></table>
!! end

!! test
Table cell attributes: Pipes protected by nested nowikis should be treated as a plain character
!! wikitext
{|
|<code><nowiki>{{ACB|PG}}</nowiki></code>
|}
!! html/php
<table>
<tbody><tr>
<td><code>{{ACB|PG}}</code>
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td><code><span typeof="mw:Nowiki">{{ACB|PG}}</span></code></td></tr>
</tbody></table>
!! end

# See: http://lists.wikimedia.org/mailman/htdig/wikitech-l/2006-April/022293.html
# N.B. The "|}" to close the table is missing from the input, so parsoid's
#      *2wt modes will fail.
!! test
Table security: embedded pipes
!! options
parsoid=wt2html,html2html
!! wikitext
{|
| |[ftp://|x||]" onmouseover="alert(document.cookie)">test
!! html/php
<table>
<tbody><tr>
<td>[<a rel="nofollow" class="external free" href="ftp://%7Cx">ftp://%7Cx</a></td>
<td>]" onmouseover="alert(document.cookie)"&gt;test
</td>
</tr>
</tbody></table>
!! html/parsoid
<table data-parsoid='{"autoInsertedEnd":true}'>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{"startTagSrc":"| ","attrSepSrc":"|"}'>[<a rel="mw:ExtLink nofollow" href="ftp://%7Cx" class="external free" data-parsoid='{"stx":"url","a":{"href":"ftp://%7Cx"},"sa":{"href":"ftp://|x"}}'>ftp://|x</a></td><td data-parsoid='{"stx":"row"}'>]" onmouseover="alert(document.cookie)">test</td></tr></tbody></table>
!! end

!! test
Element attributes with double ! should not be broken up by <th>
!! wikitext
{|
!hi <div class="!!">ha</div> ho
|}
!! html/php
<table>
<tbody><tr>
<th>hi <div class="!!">ha</div> ho
</th></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><th>hi <div class="!!" data-parsoid='{"stx":"html"}'>ha</div> ho</th></tr>
</tbody></table>
!! end

!! test
! and || in element attributes should not be parsed as <th>/<td>
!! wikitext
{|
|<div style="color: red !important;" data-contrived="put this here ||">hi</div>
|}
!! html/php
<table>
<tbody><tr>
<td><div style="color: red !important;" data-contrived="put this here &#124;&#124;">hi</div>
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td><div style="color: red !important;" data-contrived="put this here ||" data-parsoid='{"stx":"html"}'>hi</div></td></tr>
</tbody></table>
!! end

# FIXME: The output seems broken. Filed as T110268.
!! test
! and || in td attributes should not be parsed as <th>/<td>
!! options
parsoid=wt2html
!! wikitext
{|
|style="color: red !important;" data-contrived="put this here ||"|foo
|}
!! html/php
<table>
<tbody><tr>
<td>style="color: red !important;" data-contrived="put this here</td>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>style="color: red !important;" data-contrived="put this here</td><td data-parsoid='{"stx":"row","a":{"\"":null},"sa":{"\"":""}}'>foo</td></tr>
</tbody></table>
!! end

## We don't support roundtripping of these attributes in Parsoid.
## Selective serialization takes care of preventing dirty diffs.
## But, on edits, we dirty-diff the invalid attribute text.
!! test
Invalid text in table attributes should be discarded
!! options
parsoid=wt2html
!! wikitext
{| <span>boo</span> style='border:1px solid black'
|  <span>boo</span> style='color:blue'  |1
|<span>boo</span> style='color:blue'|2
|}
!! html/php
<table style="border:1px solid black">
<tbody><tr>
<td style="color:blue">1
</td>
<td style="color:blue">2
</td></tr></tbody></table>
!! html/parsoid
<table style="border:1px solid black">
<tr>
<td style="color:blue">1</td>
<td style="color:blue">2</td>
</tr>
</table>
!! end

!! test
Invalid text in table attributes should be preserved by selective serializer
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td:first-child", "text", "abc"],
    ["td + td", "text", "xyz"]
  ]
}
!! wikitext
{| <span>boo</span> style='border:1px solid black'
|  <span>boo</span> style='color:blue'  | 1
|<span>boo</span> style='color:blue'| 2
|}
!! wikitext/edited
{| <span>boo</span> style='border:1px solid black'
|  <span>boo</span> style='color:blue'  | abc
|<span>boo</span> style='color:blue'| xyz
|}
!! end

!! test
1. Template-generated table cell attributes and cell content
!! wikitext
{|
|{{table_attribs}}
| {{table_attribs}}
|| {{table_attribs_5}}
| <!--foo--> <!--bar--> <!--baz--> {{table_attribs}}
|align=center {{table_attribs}}
| <!--foo--> align=center <!--bar--> {{table_attribs}}
|}
!! html
<table>
<tbody><tr>
<td style="color:red;">Foo
</td>
<td style="color:red;">Foo
</td>
<td>style="color:red;"</td>
<td>Bar
</td>
<td style="color:red;">Foo
</td>
<td align="center" style="color:red;">Foo
</td>
<td align="center" style="color:red;">Foo
</td></tr></tbody></table>
!! end

# This test introduces a newline in a fosterable position which tangentially
# tests template-wrapping behavior more explicitly tested by the # next test
# ("2b: Delete ...").
!! test
2a. Template-generated table cell attributes and cell content
!! wikitext
{|
|{{table_attribs_2}}
|}
!! html/php
<table>
<tbody><tr>
<td data-sort-value="" style="color:red;">Foo
</td>
<td>Bar</td>
<td>Baz
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" data-sort-value="" style="color:red;" data-mw='{"parts":["|",{"template":{"target":{"wt":"table_attribs_2","href":"./Template:Table_attribs_2"},"params":{},"i":0}}]}'>Foo</td><td about="#mwt1">Bar</td><td about="#mwt1">Baz</td></tr>
</tbody></table>
!! end

!! test
2b: Delete whitespace/comments if found in fosterable position while template-wrapping
!! options
!! wikitext
<table>
<tr>
<td>hi</td>
{{1x|<td>ho</td>
<!--comment-->
<td>hi</td>}}
<td>ho</td>
</tr>
</table>
!! html/parsoid
<table data-parsoid='{"stx":"html"}'>
<tbody><tr>
<td data-parsoid='{"stx":"html"}'>hi</td>
<td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;td>ho&lt;/td>\n&lt;!--comment-->\n&lt;td>hi&lt;/td>"}},"i":0}}]}'>ho</td><td about="#mwt1">hi</td>
<td>ho</td>
</tr>
</tbody></table>
!! end

!! test
3. Template-generated table cell attributes and cell content
!! wikitext
{|
!align=center {{table_header_cells}}
|-
|align=center {{table_cells}}
|}
!! html/php
<table>
<tbody><tr>
<th align="center" style="color:red;">Foo</th>
<th style="color:red;"><i>Bar</i></th>
<th style="color:brown;"><i>Foo</i> and Baz
</th></tr>
<tr>
<td align="center" style="color:red;">Foo</td>
<td style="color:red;"><i>Bar</i></td>
<td style="color:brown;"><i>Foo</i> and Baz
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><th align="center" style="color:red;" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["!align=center ",{"template":{"target":{"wt":"table_header_cells","href":"./Template:Table_header_cells"},"params":{},"i":0}}]}'>Foo</th><th about="#mwt1" style="color:red;"><i about="#mwt1">Bar</i></th><th about="#mwt1" style="color:brown;"><i about="#mwt1">Foo</i> and Baz</th></tr><tr>
<td align="center" style="color:red;" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["|align=center ",{"template":{"target":{"wt":"table_cells","href":"./Template:Table_cells"},"params":{},"i":0}}]}'>Foo</td><td about="#mwt1" style="color:red;"><i about="#mwt1">Bar</i></td><td about="#mwt1" style="color:brown;"><i about="#mwt1">Foo</i> and Baz</td></tr>
</tbody></table>
!! end

!! test
4. Template-generated table cell attributes and cell content inside a templated table
!! wikitext
{{tbl-start}}
!align=center {{table_header_cells}}
|-
|align=center {{table_cells}}
{{tbl-end}}
!! html/php
<table>
<tbody><tr>
<th align="center" style="color:red;">Foo</th>
<th style="color:red;"><i>Bar</i></th>
<th style="color:brown;"><i>Foo</i> and Baz
</th></tr>
<tr>
<td align="center" style="color:red;">Foo</td>
<td style="color:red;"><i>Bar</i></td>
<td style="color:brown;"><i>Foo</i> and Baz
</td></tr></tbody></table>
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[],[],[],[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"tbl-start","href":"./Template:Tbl-start"},"params":{},"i":0}},"\n!align=center ",{"template":{"target":{"wt":"table_header_cells","href":"./Template:Table_header_cells"},"params":{},"i":1}},"\n|-\n|align=center ",{"template":{"target":{"wt":"table_cells","href":"./Template:Table_cells"},"params":{},"i":2}},"\n",{"template":{"target":{"wt":"tbl-end","href":"./Template:Tbl-end"},"params":{},"i":3}}]}'>
<tbody><tr><th align="center" style="color:red;">Foo</th><th style="color:red;"><i>Bar</i></th><th style="color:brown;"><i>Foo</i> and Baz</th></tr>
<tr>
<td align="center" style="color:red;">Foo</td><td style="color:red;"><i>Bar</i></td><td style="color:brown;"><i>Foo</i> and Baz</td></tr>
</tbody></table>
!! end

!! test
Table with row followed by newlines and table heading
!! options
parsoid=wt2html,html2html
!! wikitext
{|
|-

!foo
|}
!! html/*
<table>


<tbody><tr>
<th>foo
</th></tr></tbody></table>
!! end

!! test
Table with empty line following the start tag
!! options
parsoid=wt2html,html2html
!! wikitext
{|

|-
|foo
|}
!! html/*
<table>


<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! end

!! test
Table attributes with empty value
!! options
parsoid=wt2html,html2html
!! wikitext
{|
| style=|hello
|}
!! html/php
<table>
<tbody><tr>
<td style="">hello
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td style="">hello</td></tr>
</tbody></table>
!! end

!! test
Wikitext table with a lot of comments
!! wikitext
{|
<!-- c0 -->
|foo
<!-- c1 -->
|-<!-- c2 -->
<!-- c3 -->
|<!-- c4 -->
<!-- c5 -->
|}
!! html
<table>
<tbody><tr>
<td>foo
</td></tr>
<tr>
<td>
</td></tr></tbody></table>
!! end

!! test
Wikitext table comments represented in parsoid dom
!! wikitext
{|<!--c1--><!--c2-->
|-<!--c3-->
|x
|}
!! html/php
<table>

<tbody><tr>
<td>x
</td></tr></tbody></table>
!! html/parsoid
<table><!--c1--><!--c2-->
<tbody><tr data-parsoid='{"startTagSrc":"|-"}'><!--c3-->
<td data-parsoid='{}'>x</td></tr>
</tbody></table>
!! end

!! test
Wikitext table with double-line table cell
!! wikitext
{|
|a
b
|}
!! html
<table>
<tbody><tr>
<td>a
<p>b
</p>
</td></tr></tbody></table>
!! end

!! test
Table cell with a single comment
!! wikitext
{|
|<!-- c1 -->
|a
|}
!! html
<table>
<tbody><tr>
<td>
</td>
<td>a
</td></tr></tbody></table>
!! end

!! test
Table-cell after a comment-only-empty-line
!! wikitext
{|
|a
<!--c1-->
<!--c2-->|b
|}
!! html
<table>
<tbody><tr>
<td>a
</td>
<td>b
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{}'>a
<!--c1-->
<!--c2--></td><td data-parsoid='{}'>b</td></tr>
</tbody></table>
!! end

!! test
Build table with {{!}}
!! wikitext
{{{!}} class="wikitable"
!header
!second header
{{!}}- style="color:red;"
{{!}}data{{!}}{{!}} style="color:red;"{{!}}second data
{{!}}data{{!}}| style="color:green;"{{!}}third data
{{!}}data|{{!}} style="color:blue;"{{!}}fourth data
{{!}}}
!! html/php
<table class="wikitable">
<tbody><tr>
<th>header
</th>
<th>second header
</th></tr>
<tr style="color:red;">
<td>data</td>
<td style="color:red;">second data
</td>
<td>data</td>
<td style="color:green;">third data
</td>
<td>data</td>
<td style="color:blue;">fourth data
</td></tr></tbody></table>
!! html/parsoid
<table class="wikitable" data-parsoid='{"startTagSrc":"{{{!}}","endTagSrc":"{{!}}}"}'>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><th>header</th>
<th>second header</th></tr>
<tr style="color:red;" data-parsoid='{"startTagSrc":"{{!}}-"}'>
<td data-parsoid='{"startTagSrc":"{{!}}"}'>data</td><td style="color:red;" data-parsoid='{"attrSepSrc":"{{!}}","stx":"row","startTagSrc":"{{!}}{{!}}"}'>second data</td>
<td data-parsoid='{"startTagSrc":"{{!}}"}'>data</td><td style="color:green;" data-parsoid='{"attrSepSrc":"{{!}}","stx":"row","startTagSrc":"{{!}}|"}'>third data</td>
<td data-parsoid='{"startTagSrc":"{{!}}"}'>data</td><td style="color:blue;" data-parsoid='{"attrSepSrc":"{{!}}","stx":"row","startTagSrc":"|{{!}}"}'>fourth data</td></tr>
</tbody></table>
!! end

# When quotes are not used around attribute values, {{!}} should not
# prevent attribute detection when there is no preceding whitespace
!! test
Edge cases with use of {{!}}
!! options
parsoid=wt2html
!! wikitext
{|
| width=60{{!}} foo
| width=60 {{!}} foo
| width="60{{!}}0" foo
| width="60 {{!}}0" foo
|}
!! html/php
<table>
<tbody><tr>
<td width="60">foo
</td>
<td width="60">foo
</td>
<td width="60">0" foo
</td>
<td width="60">0" foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td width="60">foo</td>
<td width="60">foo</td>
<td width="60">0" foo</td>
<td width="60 ">0" foo</td></tr>
</tbody></table>
!! end

!! test
Build table with pipe as data
!! wikitext
{| class="wikitable"
!header
!second header
|- style="color:red;"
|data|| style="color:red;" |second data
|-
| style="color:red;" |data with | || style="color:red;" | second data with |
|-
||data with | |||second data with |
|}
!! html
<table class="wikitable">
<tbody><tr>
<th>header
</th>
<th>second header
</th></tr>
<tr style="color:red;">
<td>data</td>
<td style="color:red;">second data
</td></tr>
<tr>
<td style="color:red;">data with |</td>
<td style="color:red;">second data with |
</td></tr>
<tr>
<td>data with |</td>
<td>second data with |
</td></tr></tbody></table>
!! end

!! test
Build table with wikilink
!! wikitext
{| class="wikitable"
!header||second header
|- style="color:red;"
|data [[Main Page|linktext]]||second data [[Main Page|linktext]]
|-
|data||second data [[Main Page|link|text with pipe]]
|}
!! html
<table class="wikitable">
<tbody><tr>
<th>header</th>
<th>second header
</th></tr>
<tr style="color:red;">
<td>data <a href="/wiki/Main_Page" title="Main Page">linktext</a></td>
<td>second data <a href="/wiki/Main_Page" title="Main Page">linktext</a>
</td></tr>
<tr>
<td>data</td>
<td>second data <a href="/wiki/Main_Page" title="Main Page">link|text with pipe</a>
</td></tr></tbody></table>
!! end

# The expected HTML structure in this test is debatable. The PHP parser does
# not parse this kind of table at all. The main focus for Parsoid is on
# round-tripping, so this output is ok for now. TODO: revisit!
!! test
Wikitext table with html-syntax row
!! wikitext
{|
|-
<td>foo</td>
|}
!! html/parsoid
<table>
<tbody>
<tr>
<td>foo</td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
Fostered content in tables: Plain text
!! options
parsoid=wt2html
!! wikitext
{|
|-
a
|}
!! html/php


a
<table></table>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>
a</p>
<table>
<tbody class="mw-empty-elt"><tr class="mw-empty-elt" data-parsoid='{"startTagSrc":"|-"}'></tr></tbody></table>
!! end

# selser tests are needed below as a regression test for T233815
# they also demonstrate DSR errors in fostered content (T254412)
!! test
Fostered content in tables: Lists
!! options
parsoid={ "modes": ["wt2html","selser"], "suppressErrors": true }
!! wikitext
{|
|-
*a
*b
|}
!! html/php
<ul><li>a</li>
<li>b</li></ul><table>


</table>
!! html/parsoid
<ul data-parsoid='{"fostered":true,"autoInsertedEnd":true}'><li>a</li><li>b</li></ul><table>
<tbody class="mw-empty-elt"><tr class="mw-empty-elt" data-parsoid='{"startTagSrc":"|-"}'>

</tr></tbody></table>
!! end

!! test
Template generated table cell with attributes
!! wikitext
{|
|-
{{table_attribs_4}} ||a||b
|}
!! html/php
<table>

<tbody><tr>
<td style="background-color:#DC241f;" width="10px"></td>
<td>a</td>
<td>b
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
<td style="background-color:#DC241f;" width="10px" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"table_attribs_4","href":"./Template:Table_attribs_4"},"params":{},"i":0}}," ||a||b"]}'></td><td about="#mwt1">a</td><td about="#mwt1">b</td></tr>
</tbody></table>
!! end

## FIXME: The only difference between the standalone & integrated modes
## is the ordering of attributes. This could perhaps be fixed differently
## in the test runner.
!! test
Templated table cell with untemplated attributes: Cell combination tests
!! wikitext
{|
|-
!class="test"{{table_cell_content|attr=! align=left}} /* th & th combine */
|-
|class="test"{{table_cell_content}} /* td & td combine */
|-
!class="test"{{table_cell_content}} /* th & td combine */
|-
|class="test"{{table_cell_content|attr=! align=left}} /* td & th combine */
|-
|class="test"{{table_cell_content|attr=style='color:red;'}}
|-
|class="test"{{table_cell_content|cmt=<!--bar-->}}
|}
!! html/php
<table>

<tbody><tr>
<th class="test" align="left">foo /* th &amp; th combine */
</th></tr>
<tr>
<td class="test">foo /* td &amp; td combine */
</td></tr>
<tr>
<th class="test">foo /* th &amp; td combine */
</th></tr>
<tr>
<td class="test" align="left">foo /* td &amp; th combine */
</td></tr>
<tr>
<td class="test" style="color:red;">foo
</td></tr>
<tr>
<td class="test">foo
</td></tr></tbody></table>
!! html/parsoid+standalone
<table>
<tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
<th class="test" align="left" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["!class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"attr":{"wt":"! align=left"}},"i":0}}," /* th &amp; th combine */"]}'>foo /* th &amp; th combine */</th></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td class="test" typeof="mw:Transclusion" about="#mwt2" data-mw='{"parts":["|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{},"i":0}}," /* td &amp; td combine */"]}'>foo /* td &amp; td combine */</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<th class="test" typeof="mw:Transclusion" about="#mwt3" data-mw='{"parts":["!class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{},"i":0}}," /* th &amp; td combine */"]}'>foo /* th &amp; td combine */</th></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td class="test" align="left" about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":["|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"attr":{"wt":"! align=left"}},"i":0}}," /* td &amp; th combine */"]}'>foo /* td &amp; th combine */</td>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td class="test" style="color:red;" typeof="mw:Transclusion" about="#mwt5" data-parsoid='{"pi":[[{"k":"attr","named":true}]]}' data-mw='{"parts":["|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"attr":{"wt":"style=&apos;color:red;&apos;"}},"i":0}}]}'>foo</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td class="test" typeof="mw:Transclusion" about="#mwt6" data-parsoid='{"pi":[[{"k":"cmt","named":true}]]}' data-mw='{"parts":["|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"cmt":{"wt":"&lt;!--bar-->"}},"i":0}}]}'>foo</td></tr>
</tbody></table>
!! html/parsoid+integrated
<table>
<tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
<th align="left" typeof="mw:Transclusion" class="test" about="#mwt1" data-mw='{"parts":["!class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"attr":{"wt":"! align=left"}},"i":0}}," /* th &amp; th combine */"]}'>foo /* th &amp; th combine */</th></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td typeof="mw:Transclusion" class="test" about="#mwt2" data-mw='{"parts":["|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{},"i":0}}," /* td &amp; td combine */"]}'>foo /* td &amp; td combine */</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<th typeof="mw:Transclusion" class="test" about="#mwt3" data-mw='{"parts":["!class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{},"i":0}}," /* th &amp; td combine */"]}'>foo /* th &amp; td combine */</th></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td align="left" typeof="mw:Transclusion" class="test" about="#mwt4" data-mw='{"parts":["|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"attr":{"wt":"! align=left"}},"i":0}}," /* td &amp; th combine */"]}'>foo /* td &amp; th combine */</td>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td class="test" style="color:red;" typeof="mw:Transclusion" about="#mwt5" data-parsoid='{"pi":[[{"k":"attr","named":true}]]}' data-mw='{"parts":["|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"attr":{"wt":"style=&apos;color:red;&apos;"}},"i":0}}]}'>foo</td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td typeof="mw:Transclusion" class="test" about="#mwt6" data-parsoid='{"pi":[[{"k":"cmt","named":true}]]}' data-mw='{"parts":["|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"cmt":{"wt":"&lt;!--bar-->"}},"i":0}}]}'>foo</td></tr>
</tbody></table>
!! end

# Standalone test generates the right output as well but the attribute order
# is flipped and the test runner doesn't normalize output for attribute order.
!! test
T343874: Templated table that has a templated cell with untemplated attributes
!! options
parsoid=wt2html
!! wikitext
{{tbl-start}}
|-
|class="test"{{table_cell_content}}
|-
|class="test"{{table_cell_content|attr=! align=left}}
{{tbl-end}}
!! html/php
<table>

<tbody><tr>
<td class="test">foo
</td></tr>
<tr>
<td class="test" align="left">foo
</td></tr></tbody></table>
!! html/parsoid+integrated
<table typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"tbl-start","href":"./Template:Tbl-start"},"params":{},"i":0}},"\n|-\n|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{},"i":1}},"\n|-\n|class=\"test\"",{"template":{"target":{"wt":"table_cell_content","href":"./Template:Table_cell_content"},"params":{"attr":{"wt":"! align=left"}},"i":2}},"\n",{"template":{"target":{"wt":"tbl-end","href":"./Template:Tbl-end"},"params":{},"i":3}}]}'>
<tbody>
<tr><td class="test">foo</td></tr>
<tr><td align="left" class="test">foo</td></tr>
</tbody></table>
!! end

!! test
Templated table cell with untemplated attributes: Regression tests
!! wikitext
{|
|class="foo"
{{1x|1={{!}}bar}}
|}
!! html/php
<table>
<tbody><tr>
<td>class="foo"
</td>
<td>bar
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr>
<td>class="foo"</td>
<td about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}bar"}},"i":0}}]}'>bar</td></tr>
</tbody></table>

!! end

!! test
Templated table cell with untemplated attributes: Integrated mode only
!! options
parsoid=wt2html
!! wikitext
{|
|-
|class="foo"{{1x|1= {{!}}bar}}
|-
|class="foo"{{1x|1=&nbsp;{{!}}bar}}
|}
!! html/php
<table>

<tbody><tr>
<td class="foo">bar
</td></tr>
<tr>
<td class="foo">bar
</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":"{{!}}bar"}},"i":0}}]}'>bar</td></tr>
<tr>
<td class="foo" typeof="mw:Transclusion" about="#mwt2" data-mw='{"parts":["|class=\"foo\"",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&amp;nbsp;{{!}}bar"}},"i":0}}]}'>bar</td></tr>
</tbody></table>
!! end

!! test
Templated table cell with untemplated attributes
!! options
parsoid=wt2html
!! wikitext
{|
|-
|class="foo"{{1x|1={{!}}title="fail"{{!}}bar}}
|}
!! html/php
<table>

<tbody><tr>
<td class="foo">title="fail"|bar
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt" typeof="mw:Transclusion" class="foo" data-mw='{"parts":["|class=\"foo\"",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}title=\"fail\"{{!}}bar"}},"i":0}}]}'>title="fail"|bar</td></tr>
</tbody></table>
!! end

!! test
Parsoid: Round-trip tables directly followed by content (T53219)
!! options
parsoid=wt2html,wt2wt
!! wikitext
{|
|foo
|} bar

{|
|baz
|}<b>quux</b>
!! html/php
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table><p> bar
</p><table>
<tbody><tr>
<td>baz
</td></tr></tbody></table><p><b>quux</b></p>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td>foo</td></tr>
</tbody></table><p> bar</p>

<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td>baz</td></tr>
</tbody></table><p><b data-parsoid='{"stx":"html"}'>quux</b></p>
!! end

!! test
Parsoid: Default to a newline after tables in new content (T53219)
!! options
parsoid=html2wt
!! html/parsoid
<table><tbody>
<tr><td>foo</td></tr></tbody></table> bar
<table><tbody>
<tr><td>baz</td></tr></tbody></table><b>quux</b>
!! wikitext
{|
|foo
|}
bar
{|
|baz
|}
'''quux'''
!! end

!! test
Parsoid: Row-syntax table headings followed by comment & table cells
!! options
parsoid=wt2html,wt2wt
!! wikitext
{|
!foo||bar
<!-- foo -->  ||baz||quux
|}
!! html/php
<table>
<tbody><tr>
<th>foo</th>
<th>bar
</th>
<td>baz</td>
<td>quux
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><th>foo</th><th>bar
<!-- foo --></th><td> baz </td><td>quux</td></tr>
</tbody></table>
!! end

!!test
Parsoid: Recover better from broken table attributes
!!options
parsoid=wt2html
!!wikitext
{| class="foo
| class="bar" |
foo
|}
!!html/php
<table class="foo">
<tbody><tr>
<td class="bar">
<p>foo
</p>
</td></tr></tbody></table>
!!html/parsoid
<table class="foo">
<tr>
<td class="bar">
<p>foo</p></td></tr>
</tbody></table>
!!end

# Note: PHP parser omits empty rows
!! test
Tables: Digest broken attributes on table and tr tag
!! options
parsoid=wt2html
!! wikitext
{| || |} ++
|- || || ++ --
|- > [
|}
!! html/php
<table>


</table>
!! html/parsoid
<table>
<tbody class="mw-empty-elt">
<tr class='mw-empty-elt'></tr>
<tr class='mw-empty-elt'></tr>
</tbody></table>
!! end

!! test
Table with missing opening <tr> tag
!! options
parsoid=wt2html,wt2wt
!! wikitext
<table>
<td>foo</td>
</tr>
</table>
!! html
<table>
<tbody><tr><td>foo</td>
</tr>
</tbody></table>
!! end

# T137406: Whitespace in the HTML
!! test
1. Generate correct wikitext for tables with thead/tbody/tfoot
!! options
parsoid=html2wt
!! html/parsoid
<table>
<caption>Test</caption>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
</table>
!! wikitext
{|
|+Test
!Month
!Savings
|-
|January
|$100
|-
|February
|$80
|-
|Sum
|$180
|}
!! html/php
<table>
<caption>Test
</caption>
<tbody><tr>
<th>Month
</th>
<th>Savings
</th></tr>
<tr>
<td>January
</td>
<td>$100
</td></tr>
<tr>
<td>February
</td>
<td>$80
</td></tr>
<tr>
<td>Sum
</td>
<td>$180
</td></tr></tbody></table>
!! end

# T137406: No whitespace in the HTML
!! test
2. Generate correct wikitext for tables with thead/tbody/tfoot
!! options
parsoid=html2wt
!! html/parsoid
<table><thead><tr><th>heading</th></tr></thead><tbody><tr><td>foo</td></tr></tbody></table>
!! wikitext
{|
!heading
|-
|foo
|}
!! end

!! test
Wikitext tables can be nested inside HTML tables
!! options
parsoid=html2wt
!! html/parsoid
<table data-parsoid='{"stx":"html"}'>
<tr><td>
<table>
<tr><td>foo</td></tr>
</table>
</td></tr>
</table>
!! wikitext
<table>
<tr><td>
{|
|foo
|}
</td></tr>
</table>
!! html/php
<table>
<tbody><tr><td>
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
</td></tr>
</tbody></table>
!! end

!! article
Eau
!! text
Dummy article to suppress redlinks in tests
!! end

!! test
T319143 - copy-pasting of cells, before
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td", "before", "<td data-parsoid=\"{}\"><a href=\"./Eau\" rel=\"mw:WikiLink\" title=\"Eau\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Eau\"},\"sa\":{\"href\":\"Eau\"},\"dsr\":[4,11,2,2]}'>Eau</a></td>"]
  ]
}
!! wikitext
{|
|[[Eau]]
|}
!! wikitext/edited
{|
|[[Eau]]
|[[Eau]]
|}
!! end

!! test
T319143 - copy-pasting of cells, after
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td", "after", "<td data-parsoid=\"{}\"><a href=\"./Eau\" rel=\"mw:WikiLink\" title=\"Eau\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Eau\"},\"sa\":{\"href\":\"Eau\"},\"dsr\":[4,11,2,2]}'>Eau</a></td>"]
  ]
}
!! wikitext
{|
|[[Eau]]
|}
!! wikitext/edited
{|
|[[Eau]]
|[[Eau]]
|}
!! end

!! test
T319143 - copy-pasting of cells, before multiple cells
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td:first-child", "before", "<td data-parsoid='{\"stx\":\"row\"}'><a href=\"./Eau\" rel=\"mw:WikiLink\" title=\"Eau\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Eau\"},\"sa\":{\"href\":\"Eau\"},\"dsr\":[4,11,2,2]}'>Eau</a></td>"]
  ]
}
!! wikitext
{|
|[[Eau]]||[[Abc]]
|}
!! wikitext/edited
{|
|[[Eau]]
|[[Eau]]||[[Abc]]
|}
!! end

!! test
T319143 - copy-pasting of cells, before multiple cells, without "row"
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td:first-child", "before", "<td data-parsoid='{}'><a href=\"./Eau\" rel=\"mw:WikiLink\" title=\"Eau\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Eau\"},\"sa\":{\"href\":\"Eau\"},\"dsr\":[4,11,2,2]}'>Eau</a></td>"]
  ]
}
!! wikitext
{|
|[[Eau]]||[[Abc]]
|}
!! wikitext/edited
{|
|[[Eau]]
|[[Eau]]||[[Abc]]
|}
!! end

!! test
T319143 - copy-pasting of cells, between multiple cells
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td:first-child", "after", "<td data-parsoid='{\"stx\":\"row\"}'><a href=\"./Eau\" rel=\"mw:WikiLink\" title=\"Eau\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Eau\"},\"sa\":{\"href\":\"Eau\"},\"dsr\":[4,11,2,2]}'>Eau</a></td>"]
  ]
}
!! wikitext
{|
|[[Eau]]||[[Abc]]
|}
!! wikitext/edited
{|
|[[Eau]]||[[Eau]]||[[Abc]]
|}
!! end

!! test
T319143 - copy-pasting of cells, between multiple cells, without "row"
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td:first-child", "after", "<td data-parsoid='{}'><a href=\"./Eau\" rel=\"mw:WikiLink\" title=\"Eau\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Eau\"},\"sa\":{\"href\":\"Eau\"},\"dsr\":[4,11,2,2]}'>Eau</a></td>"]
  ]
}
!! wikitext
{|
|[[Eau]]||[[Abc]]
|}
!! wikitext/edited
{|
|[[Eau]]
|[[Eau]]||[[Abc]]
|}
!! end

!! test
T319143 - copy-pasting of cells, after multiple cells
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td:last-child", "after", "<td data-parsoid='{\"stx\":\"row\"}'><a href=\"./Eau\" rel=\"mw:WikiLink\" title=\"Eau\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Eau\"},\"sa\":{\"href\":\"Eau\"},\"dsr\":[4,11,2,2]}'>Eau</a></td>"]
  ]
}
!! wikitext
{|
|[[Eau]]||[[Abc]]
|}
!! wikitext/edited
{|
|[[Eau]]||[[Abc]]||[[Eau]]
|}
!! end

!! test
T319143 - copy-pasting of cells, after multiple cells, without "row"
!! options
parsoid={
  "modes": [ "selser" ],
  "changes": [
    ["td:last-child", "after", "<td data-parsoid='{}'><a href=\"./Eau\" rel=\"mw:WikiLink\" title=\"Eau\" data-parsoid='{\"stx\":\"simple\",\"a\":{\"href\":\"./Eau\"},\"sa\":{\"href\":\"Eau\"},\"dsr\":[4,11,2,2]}'>Eau</a></td>"]
  ]
}
!! wikitext
{|
|[[Eau]]||[[Abc]]
|}
!! wikitext/edited
{|
|[[Eau]]||[[Abc]]
|[[Eau]]
|}
!! end

!! test
Spec syntactic differences in parsing of !! compared to ||
!! options
parsoid=wt2html,wt2wt
!! wikitext
{|
<!--cmt-->!!foo
{{1x|!!foo}}
<!--cmt-->!!foo!!bar
{{1x|!!foo}}{{1x|!!bar}}
|}
!! html/php
<table>
<tbody><tr>
<th>!foo
</th>
<th>!foo
</th>
<th>!foo</th>
<th>bar
</th>
<th>!foo</th>
<th>bar
</th></tr></tbody></table>
!! html/parsoid+integrated
<table><!--cmt-->
<tbody>
<tr>
<th>!foo</th>
<th about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"!!foo"}},"i":0}}]}'>!foo</th>
<!--cmt-->
<th>!foo</th>
<th>bar</th>
<th about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"!!foo"}},"i":0}}]}'>!foo</th>
<th about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"!!bar"}},"i":0}}]}'>bar</th>
</tr>
</tbody>
</table>
!! end

!! test
Multiline inline table line in file caption
!! wikitext
[[File:Foobar.jpg|thumb|
{|
|
asdf
|}
]]
!! html/php
<figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Foobar.jpg" class="mw-file-description"><img src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" loading="lazy" width="180" height="20" class="mw-file-element" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a><figcaption> <table> <tbody><tr> <td> asdf </td></tr></tbody></table> </figcaption></figure>
!! html/parsoid
<figure class="mw-default-size" typeof="mw:File/Thumb"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" loading="lazy" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="180" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" class="mw-file-element"/></a><figcaption>
<table>
<tbody><tr><td>
asdf</td></tr>
</tbody></table>
</figcaption></figure>
!! end

###
### Parsoid edge case regression tests
###
!! test
Table lines with multiple newlines, spaces, comments embedded in file caption
!! options
parsoid=wt2html,wt2wt
!! wikitext
[[File:Foobar.jpg|thumb|
  <!--cmt-->   
{|
  
 |test
   <!--cmt-->  
|}]]
!! html/php
<figure class="mw-default-size" typeof="mw:File/Thumb"><a href="/wiki/File:Foobar.jpg" class="mw-file-description"><img src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" loading="lazy" width="180" height="20" class="mw-file-element" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a><figcaption> <table>    <tbody><tr> <td>test </td></tr></tbody></table></figcaption></figure>
!! html/parsoid
<figure class="mw-default-size" typeof="mw:File/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"caption","ak":"\n  &lt;!--cmt-->   \n{|\n  \n |test\n   &lt;!--cmt-->  \n|}"}]}'><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" decoding="async" loading="lazy" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="180" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" class="mw-file-element" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"20","width":"180"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>
  <!--cmt-->   
<table>
  
 <tbody><tr><td>test
   <!--cmt--></td></tr>
</tbody></table></figcaption></figure>
!! end

!! test
First line attributes should be handled by html2wt even without data-parsoid
!! wikitext
{|
|- valign="top"
|Bar
|}
!! html
<table>

<tbody><tr valign="top">
<td>Bar
</td></tr></tbody></table>
!! end

!! test
Don't apply complex line-splitting heuristics in AttributeExpander for non-<table> tokens
!! options
parsoid=wt2html
!! wikitext
{{1x<invalid>
|{{2x<invalid>y}}|
}}

{{1x<invalid>
|{{2x<invalid>
y}}|
}}
!! html/php
<p>{{1x&lt;invalid&gt;
|{{2x&lt;invalid&gt;y}}|
}}
</p><p>{{1x&lt;invalid&gt;
|{{2x&lt;invalid&gt;
y}}|
}}
</p>
!! html/parsoid
<p>{{1x&lt;invalid>
|{{2x&lt;invalid>y}}|
}}</p>

<p>{{1x&lt;invalid>
|{{2x&lt;invalid>
y}}|
}}</p>
!! end

!! test
Autoinserted tr in html table
!! wikitext
<table>
<td>a</td>
</table>
!! html/php
<table>
<tbody><tr><td>a</td>
</tr></tbody></table>
!! html/parsoid
<table data-parsoid='{"stx":"html"}'>
<tbody><tr data-parsoid='{"autoInsertedStart":true,"autoInsertedEnd":true}'><td data-parsoid='{"stx":"html"}'>a</td></tr>
</tbody></table>
!! end

!! test
AttributeExpander regression test: Class attributes should be properly applied
!! wikitext
{| {{1x|1=class="foo {{{class}}} <!--x--> bar" style="font-size: 95%;"}}
|foo
|}
!! html/php
<table class="foo &#123;&#123;&#123;class&#125;&#125;&#125; bar" style="font-size: 95%;">
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! html/parsoid+standalone
<table class="foo {{{class}}}  bar" style="font-size: 95%;" about="#mwt2" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"class","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\",\"named\":true}]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"class=\\\"foo {{{class}}} &amp;lt;!--x--> bar\\\" style=\\\"font-size: 95%;\\\"\"}},\"i\":0}}]}&apos;>class=\"foo {{{class}}} &lt;/span>&lt;span about=\"#mwt1\">&lt;!--x-->&lt;/span>&lt;span about=\"#mwt1\"> bar\" style=\"font-size: 95%;\"&lt;/span>"},{"html":""}]]}'>
<tbody><tr><td>foo</td></tr>
</tbody></table>
!! end

## Note that we are choosing to support this in Parsoid
## The legacy parser output is arbitrary
!! test
Exclamation points in wikilink content in table precedence
!! wikitext
{|
![[Foo|Bar!!]]
|}
!! html/php
<table>
<tbody><tr>
<th><a href="/index.php?title=Foo&amp;action=edit&amp;redlink=1" class="new" title="Foo (page does not exist)">Bar</a></th>
<th>
</th></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><th><a rel="mw:WikiLink" href="./Foo?action=edit&amp;redlink=1" title="Foo" class="new" typeof="mw:LocalizedAttrs" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Foo"]}}'>Bar!!</a></th></tr>
</tbody></table>
!! end

!! test
Multi-line extension tags should not interrupt table-cell parsing in the same row
!! options
parsoid=wt2html,wt2wt
!! wikitext
{|
|-
|a1||b1 <spantag>
{{1x|c1}}</spantag>||d1||e1
|-
|a2||[[Main Page]] <spantag>
{{1x|c2}}</spantag>||d2||e2
|}

{|
|-
!a3!!b3 <spantag>
{{1x|c3}}</spantag>!!d3!!e3
|-
!a4!![[Main Page]] <spantag>
{{1x|c4}}</spantag>!!d4!!e4
|}
!! html/php
<table>

<tbody><tr>
<td>a1</td>
<td>b1 <span>
c1</span></td>
<td>d1</td>
<td>e1
</td></tr>
<tr>
<td>a2</td>
<td><a href="/wiki/Main_Page" title="Main Page">Main Page</a> <span>
c2</span></td>
<td>d2</td>
<td>e2
</td></tr></tbody></table>
<table>

<tbody><tr>
<th>a3</th>
<th>b3 <span>
c3</span></th>
<th>d3</th>
<th>e3
</th></tr>
<tr>
<th>a4</th>
<th><a href="/wiki/Main_Page" title="Main Page">Main Page</a> <span>
c4</span></th>
<th>d4</th>
<th>e4
</th></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr>
<td>a1</td><td data-parsoid='{"stx":"row"}'>b1 <span typeof="mw:Extension/spantag" about="#mwt2" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"\n{{1x|c1}}"}}'>
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"c1"}},"i":0}}]}'>c1</span></span></td><td data-parsoid='{"stx":"row"}'>d1</td><td data-parsoid='{"stx":"row"}'>e1</td></tr>
<tr>
<td>a2</td><td data-parsoid='{"stx":"row"}'><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a> <span typeof="mw:Extension/spantag" about="#mwt4" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"\n{{1x|c2}}"}}'>
<span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"c2"}},"i":0}}]}'>c2</span></span></td><td data-parsoid='{"stx":"row"}'>d2</td><td data-parsoid='{"stx":"row"}'>e2</td></tr>
</tbody></table>

<table>
<tbody><tr>
<th>a3</th><th data-parsoid='{"stx":"row"}'>b3 <span typeof="mw:Extension/spantag" about="#mwt6" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"\n{{1x|c3}}"}}'>
<span about="#mwt5" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"c3"}},"i":0}}]}'>c3</span></span></th><th data-parsoid='{"stx":"row"}'>d3</th><th data-parsoid='{"stx":"row"}'>e3</th></tr>
<tr>
<th>a4</th><th data-parsoid='{"stx":"row"}'><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a> <span typeof="mw:Extension/spantag" about="#mwt8" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"\n{{1x|c4}}"}}'>
<span about="#mwt7" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"c4"}},"i":0}}]}'>c4</span></span></th><th data-parsoid='{"stx":"row"}'>d4</th><th data-parsoid='{"stx":"row"}'>e4</th></tr>
</tbody></table>
!! end

!! test
Multi-line transclusions should not interrupt table-cell parsing in the same row
!! 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
Row syntax td starting with closing curly brace
!! wikitext
{|
|a||}||b
|}
!! html/php
<table>
<tbody><tr>
<td>a</td>
<td>}</td>
<td>b
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>a</td><td data-parsoid='{"stx":"row"}'>}</td><td data-parsoid='{"stx":"row"}'>b</td></tr>
</tbody></table>
!! end

!! article
Template:Content_and_cell
!! text
test
| 123
!! endarticle

!! test
Newline constraint after multi-node template
!! wikitext
{|
| {{content and cell}} || {{content and cell}}
|}
!! html/php
<table>
<tbody><tr>
<td>test
</td>
<td>123</td>
<td>test
</td>
<td>123
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"firstWikitextNode":"TD"}' data-mw='{"parts":["| ",{"template":{"target":{"wt":"content and cell","href":"./Template:Content_and_cell"},"params":{},"i":0}}," "]}'>test</td><td about="#mwt1">123</td><td about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"row","firstWikitextNode":"TD_row"}' data-mw='{"parts":["|| ",{"template":{"target":{"wt":"content and cell","href":"./Template:Content_and_cell"},"params":{},"i":0}}]}'>test</td><td about="#mwt2">123</td></tr>
</tbody></table>
!! end

!! test
Pipe within attribute without quotes
!! options
parsoid=wt2html
!! wikitext
{| style=font-size:85%|0 – 2
|- style=font-size:85%|0 – 2
| style=font-size:85%|0 – 2 hi
|}
!! html/php
<table style="font-size:85%&#124;0">

<tbody><tr style="font-size:85%&#124;0">
<td style="font-size:85%">0 – 2 hi
</td></tr></tbody></table>
!! html/parsoid
<table style="font-size:85%|0">
<tbody>
<tr style="font-size:85%|0">
<td style="font-size:85%">0 – 2 hi</td>
</tr>
</tbody>
</table>
!! end

!! test
Pipe within attribute with single quotes
!! options
parsoid=wt2html
!! wikitext
{| style='font-size:85%|0 – 2'
|- style='font-size:85%|0 – 2'
| style='font-size:85%|0 – 2' hi
|}
!! html/php
<table style="font-size:85%&#124;0 – 2">

<tbody><tr style="font-size:85%&#124;0 – 2">
<td style="font-size:85%">0 – 2' hi
</td></tr></tbody></table>
!! html/parsoid
<table style="font-size:85%|0 – 2">
<tbody>
<tr style="font-size:85%|0 – 2">
<td style="font-size:85%">0 – 2' hi</td>
</tr>
</tbody>
</table>
!! end

!! test
Pipe within attribute with double quotes
!! wikitext
{| style="font-size:85%|0 – 2"
|- style="font-size:85%|0 – 2"
|hi
|}
!! html/php
<table style="font-size:85%&#124;0 – 2">

<tbody><tr style="font-size:85%&#124;0 – 2">
<td>hi
</td></tr></tbody></table>
!! html/parsoid
<table style="font-size:85%|0 – 2">
<tbody>
<tr style="font-size:85%|0 – 2">
<td>hi</td>
</tr>
</tbody>
</table>
!! end

!! article
Template:Asciiart
!! text
 |  |
 |--|
!! end

!! test
Asciiart template should display the right number of spaces
!! wikitext
{{Asciiart}}
!! html/parsoid
<pre data-mw='{"parts":[{"template":{"target":{"wt":"Asciiart","href":"./Template:Asciiart"},"params":{},"i":0}}]}' typeof="mw:Transclusion">|  |
|--|</pre>
!! end
