!! Version 2
# MediaWiki Parser test cases
# Some taken from https://meta.wikimedia.org/wiki/Parser_testing
# All (C) their respective authors and released under the GPL
#
# The syntax should be fairly self-explanatory.
#
# Currently supported test options:
# One of the following three:
#
#  (default)  generate HTML output
#  pst        apply pre-save transform
#  msg        apply message transform
#
# Plus any combination of these:
#
# cat           add category links
#               (ignored by Parsoid, since it emits <link>s)
# ill           add inter-language links
#               (ignored by Parsoid, since it emits <link>s)
# subpage       enable subpages (disabled by default)
# title=[[XXX]] run test using article title XXX
# language=XXX  set content language to XXX for this test
# variant=XXX   set the variant of language for this test (eg zh-tw)
# disabled      do not run test
# parsoid       parsoid-specific options (not run by PHP parser unless
#                 the test includes an html/php section)
# php           php-only test (not run by the parsoid parser unless
#                 the test includes an html/parsoid section)
# showtitle     make the first line the title
# showindicators make the first lines the page status indicators
# comment       run through Linker::formatComment() instead of main parser
# local         format section links in edit comment text as local links
# notoc         disable table of contents
# thumbsize=NNN set the default thumb size to NNNpx for this test
# wrap          include the normal wrapper <div class="mw-parser-output"> (since 1.30)
#
# You can also set the following parser properties via test options:
#  wgEnableUploads, wgAllowExternalImages, wgMaxTocLevel,
#  wgLinkHolderBatchSize, wgRawHtml, wgInterwikiMagic,
#  wgEnableMagicLinks
#
# For testing purposes, temporary articles can created:
# !!article / NAMESPACE:TITLE / !!text / ARTICLE TEXT / !!endarticle
# where '/' denotes a newline.

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

!!article
Foo
!!text
FOO
!!endarticle

!!article
Foo''s bar''s
!!text
Article titles can contain single quotes!
!!endarticle

!!article
Template:Foo
!!text
FOO
!!endarticle

!! article
Template:redirect to foo
!! text
#REDIRECT [[Template:Foo]]
!! endarticle

!! article
Template:Blank
!! text
!! endarticle

!! article
Template:pipe
!! text
|
!! endarticle

!! article
Template:=
!! text
<nowiki>=</nowiki>
!! endarticle

!!article
MediaWiki:bad image list
!!text
* [[File:Bad.jpg]] except [[Nasty page]]
!!endarticle

!! article
Template:inner list
!! text
* item 1
!! endarticle

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

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

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

# For is; localize Template namespace
!! article
Snið:1x
!! text
{{{1}}}
!! endarticle

!! article
Template:3x_on_newline
!! text
{{{1}}}
{{{1}}}
{{{1}}}
!! endarticle

# For Serbian; localize Template namespace
!! article
Шаблон:1x
!! text
{{{1}}}
!! endarticle

!! article
Template:1x_with_span
!! text
<span>{{{1}}}</span>
!! endarticle

!! article
Template:1x_with_div
!! text
<div>{{{1}}}</div>
!! endarticle

!! article
Template:1x with depth
!! text
{{1x|{{{1}}}}}
!! endarticle

!! article
Template:blank_param
!! text
{{{1}}}
{{{}}}
!! 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_3
!! text
<noinclude>
|</noinclude>style{{=}}"background:&#35;f9f9f9;"|Foo
!! 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_attribs_6
!! text
style="background: <nowiki>


red;</nowiki>" |
!! endarticle

!! article
Template:table_attribs_7
!! text
<noinclude>
|</noinclude>style{{=}}"background:&#35;f9f9f9;"|Foo<ref>foo</ref>
!! 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

!! article
Template:table_cell_content_with_leading_spc
!! text
 | foo
!! endarticle

!! article
Template:PartialTable
!! text
{|
|-
!! endarticle

## See T48811 for details
!! article
Template:mixed_attr_content_template
!! text
style="color:red;" title="T48811"
|-
|foo
!! endarticle

## This template has a category in fosterable position. See T249740 for details
!! article
Template:mixed_attr_content_template_2
!! text
style="color:red;" title="T249740"
|-
[[Category:Fostered Content]]
|foo
!! endarticle

!! article
Template:definition_list
!! text
one
::two
!! endarticle

!! article
A?b
!! text
Weirdo titles!
!! endarticle

!!article
Template:Bullet
!!text
*Bar
!!endarticle

!!article
Template:OpenTable
!!text
{|
!!endarticle

!!article
Template:EmptyLITest
!!text
*a
*
*
*b
!!endarticle

!!article
Template:EmptyTRTest
!!text
{|
|-
|-
|foo
|-
|-
|bar
|}
!!endarticle

!!article
Template:EmptyTRWithHTMLAttrTest
!!text
<table>
<tr align="center"></tr>
<tr><td>foo</td></tr>
<tr align="center"></tr>
<tr><td>bar</td></tr>
</table>
!!endarticle

!! article
Template:With: Colon
!! text
Template with colon
!! endarticle

!! article
Template:Template with pagename
!! text
This is {{PAGENAME}}.
!! endarticle

###
### Basic tests
###

!! test
Blank input
!! wikitext
!! html
!! end

!! test
Simple paragraph
!! wikitext
This is a simple paragraph.
!! html
<p>This is a simple paragraph.
</p>
!! end

!! test
Paragraphs with extra newline spacing
!! wikitext
a

b (+2 nls)


c (+3 nls)



d (+4 nls)




e (+5 nls)
!! html
<p>a
</p><p>b (+2 nls)
</p><p><br />
c (+3 nls)
</p><p><br />
</p><p>d (+4 nls)
</p><p><br />
</p><p><br />
e (+5 nls)
</p>
!! end

!! test
Paragraphs with newline spacing with comment lines in between
!! wikitext
----
a
<!--foo-->
b
----
a
<!--foo--><!--More than 1 comment, still stripped-->
b
----
a
 <!--foo--> <!----> <!-- bar --> 
b
----
a
<!--foo-->

b
----
a

<!--foo-->
b
----
a
<!--foo-->


b
----
a


<!--foo-->
b
----
!! html
<hr />
<p>a
b
</p>
<hr />
<p>a
b
</p>
<hr />
<p>a
b
</p>
<hr />
<p>a
</p><p>b
</p>
<hr />
<p>a
</p><p>b
</p>
<hr />
<p>a
</p><p><br />
b
</p>
<hr />
<p>a
</p><p><br />
b
</p>
<hr />
!! end

!! test
Paragraphs with newline spacing with non-empty white-space lines in between
!! wikitext
----
a
 
b
----
a
 
 
b
----
!! html
<hr />
<p>a
</p><p>b
</p>
<hr />
<p>a
</p><p><br /> 
b
</p>
<hr />
!! end

!! test
Paragraphs with newline spacing with non-empty mixed comment and white-space lines in between
!! wikitext
----
a
 <!--foo-->
b
----
a
 <!--foo--><!--More than 1 comment doesn't disable stripping of this line!-->
b
----
a
 
<!--foo-->
 <!--bar-->
b
----
a
 
 <!--foo-->
 <!--bar-->
 
b
----
!! html
<hr />
<p>a
b
</p>
<hr />
<p>a
b
</p>
<hr />
<p>a
</p><p>b
</p>
<hr />
<p>a
</p><p><br /> 
b
</p>
<hr />
!! end

!! test
Extra newlines: More paragraphs with indented comment
!! wikitext
a

   <!--boo-->

b
!! html
<p>a
</p><p><br />
b
</p>
!!end

!! test
Extra newlines followed by heading
!! wikitext
a


=b=
[[a]]


=b=
!! html
<p>a
</p><p><br />
</p>
<h1><span class="mw-headline" id="b">b</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: b">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<p><a href="/index.php?title=A&amp;action=edit&amp;redlink=1" class="new" title="A (page does not exist)">a</a>
</p><p><br />
</p>
<h1><span class="mw-headline" id="b_2">b</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">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
!! end

!! test
Extra newlines between heading and content are swallowed (Parsoid does not)
!! wikitext
=b=



[[a]]
!! html/php+tidy
<h1><span class="mw-headline" id="b">b</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: b">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<p><a href="/index.php?title=A&amp;action=edit&amp;redlink=1" class="new" title="A (page does not exist)">a</a>
</p>
!! html/parsoid
<h1 id="b">b</h1>
<p>
<br></p>

<p><a rel="mw:WikiLink" href="./A" title="A" class="new">a</a></p>
!! end

!! test
Extra new lines before and after lists are preserved
!! wikitext
a


*b


c
!! html/php+tidy
<p>a
</p><p><br />
</p>
<ul><li>b</li></ul>
<p><br />
c
</p>
!! html/parsoid
<p>a</p>
<p>
<br></p>
<ul><li>b</li></ul>
<p>
<br>
c</p>
!! end

# Parsoid regression test
!!test
Multiple newlines after tables are converted to p-br-p tags
!!options
parsoid=wt2html,wt2wt
!!wikitext
{|
|x
|}




=b=
!!html/php+tidy
<table>
<tbody><tr>
<td>x
</td></tr></tbody></table>
<p><br />
</p><p><br />
</p>
<h1><span class="mw-headline" id="b">b</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: b">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
!!html/parsoid
<table>
<tbody>
<tr>
<td>x</td>
</tr>
</tbody>
</table>
<p><br/></p>
<p><br/></p>
<h1 id="b">b</h1>
!!end

!! test
Heading with line break in nowiki
!! options
parsoid=wt2html
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
==A <nowiki>B
C</nowiki>==
!! html/php
<h2><span id="A_B.0AC"></span><span class="mw-headline" id="A_B_C">A B
C</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: A B&#10;C">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<h2 id="A_B_C"><span id="A_B.0AC" typeof="mw:FallbackId"></span>A <span typeof="mw:Nowiki">B
C</span></h2>
!! end

!! test
Heading with nonbreaking space in prefix/suffix (T235684)
!! options
parsoid=wt2html,html2html
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
== &nbsp; A &nbsp; B &nbsp; ==
!! html/php
<h2><span class="mw-headline" id="_A_B">&#160; A &#160; B &#160;</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:   A   B  ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<h2 id="_A_B"><span typeof="mw:Entity"> </span> A <span typeof="mw:Entity"> </span> B <span typeof="mw:Entity"> </span></h2>
!! end

!! test
Parsing an URL
!! wikitext
http://fr.wikipedia.org/wiki/🍺
<!-- EasterEgg we love beer, better be able be able to link to it -->
!! html
<p><a rel="nofollow" class="external free" href="http://fr.wikipedia.org/wiki/🍺">http://fr.wikipedia.org/wiki/🍺</a>
</p>
!! end

!! test
Simple list
!! wikitext
*Item 1
*Item 2
!! html
<ul><li>Item 1</li>
<li>Item 2</li></ul>
!! end

!! test
Italics and bold
!! wikitext
*plain
*plain''italic''plain
*plain''italic''plain''italic''plain
*plain'''bold'''plain
*plain'''bold'''plain'''bold'''plain
*plain''italic''plain'''bold'''plain
*plain'''bold'''plain''italic''plain
*plain''italic'''bold-italic'''italic''plain
*plain'''bold''bold-italic''bold'''plain
*plain'''''bold-italic'''italic''plain
*plain'''''bold-italic''bold'''plain
*plain''italic'''bold-italic'''''plain
*plain'''bold''bold-italic'''''plain
*plain l'''italic''plain
*plain l''''bold''' plain
!! html
<ul><li>plain</li>
<li>plain<i>italic</i>plain</li>
<li>plain<i>italic</i>plain<i>italic</i>plain</li>
<li>plain<b>bold</b>plain</li>
<li>plain<b>bold</b>plain<b>bold</b>plain</li>
<li>plain<i>italic</i>plain<b>bold</b>plain</li>
<li>plain<b>bold</b>plain<i>italic</i>plain</li>
<li>plain<i>italic<b>bold-italic</b>italic</i>plain</li>
<li>plain<b>bold<i>bold-italic</i>bold</b>plain</li>
<li>plain<i><b>bold-italic</b>italic</i>plain</li>
<li>plain<b><i>bold-italic</i>bold</b>plain</li>
<li>plain<i>italic<b>bold-italic</b></i>plain</li>
<li>plain<b>bold<i>bold-italic</i></b>plain</li>
<li>plain l'<i>italic</i>plain</li>
<li>plain l'<b>bold</b> plain</li></ul>
!! end

# this example taken from the [[simple:Moon]] article (T49326)
!! test
Italics and possessives (1)
!! wikitext
obtained by ''[[Lunar Prospector]]'''s gamma-ray spectrometer
!! html
<p>obtained by <i><a href="/index.php?title=Lunar_Prospector&amp;action=edit&amp;redlink=1" class="new" title="Lunar Prospector (page does not exist)">Lunar Prospector</a>'</i>s gamma-ray spectrometer
</p>
!! end

# this example taken from [[en:Flaming Pie]] (T51926)
!! test
Italics and possessives (2)
!! wikitext
'''''Flaming Pie''''' is ... released in 1997. In ''Flaming Pie'''s liner notes
!! html
<p><i><b>Flaming Pie</b></i> is ... released in 1997. In <i>Flaming Pie'</i>s liner notes
</p>
!! end

# this example taken from [[en:Dictionary]] (T51926)
!! test
Italics and possessives (3)
!! wikitext
The first monolingual dictionary written in a Romance language was ''Sebastián Covarrubias''' ''Tesoro de la lengua castellana o española'', published in 1611 in Madrid. In 1612 the first edition of the ''Vocabolario dell'[[Accademia della Crusca]]'', for Italian, was published. In 1690 in Rotterdam was published, posthumously, the ''Dictionnaire Universel''.
!! html
<p>The first monolingual dictionary written in a Romance language was <i>Sebastián Covarrubias'</i> <i>Tesoro de la lengua castellana o española</i>, published in 1611 in Madrid. In 1612 the first edition of the <i>Vocabolario dell'<a href="/index.php?title=Accademia_della_Crusca&amp;action=edit&amp;redlink=1" class="new" title="Accademia della Crusca (page does not exist)">Accademia della Crusca</a></i>, for Italian, was published. In 1690 in Rotterdam was published, posthumously, the <i>Dictionnaire Universel</i>.
</p>
!! end


###
### 2-quote opening sequence tests
###
!! test
Italics and bold: 2-quote opening sequence: (2,2)
!! wikitext
''foo''
!! html
<p><i>foo</i>
</p>
!!end

!! test
Italics and bold: 2-quote opening sequence: (2,3)
!! wikitext
''foo'''
!! html/*
<p><i>foo'</i>
</p>
!!end

!! test
Italics and bold: 2-quote opening sequence: (2,4)
!! options
parsoid=wt2html
!! wikitext
''foo''''
!! html/*
<p><i>foo''</i>
</p>
!!end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: 2-quote opening sequence: (2,4) w/ nowiki
!! wikitext
''foo<nowiki>''</nowiki>''
!! html
<p><i>foo''</i>
</p>
!! end

!! test
Italics and bold: 2-quote opening sequence: (2,5)
!! options
parsoid=wt2html
!! wikitext
''foo'''''
!! html
<p><i>foo</i><b></b>
</p>
!!end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: 2-quote opening sequence: (2,5+3) w/ nowiki
!! wikitext
''foo'''''<nowiki/>'''
!! html
<p><i>foo</i><b></b>
</p>
!! end


###
### 3-quote opening sequence tests
###

!! test
Italics and bold: 3-quote opening sequence: (3,2)
!! wikitext
'''foo''
!! html
<p>'<i>foo</i>
</p>
!!end

!! test
Italics and bold: 3-quote opening sequence: (3,3)
!! wikitext
'''foo'''
!! html
<p><b>foo</b>
</p>
!!end

!! test
Italics and bold: 3-quote opening sequence: (3,4)
!! wikitext
'''foo''''
!! html
<p><b>foo'</b>
</p>
!!end

# The PHP parser strips the empty tags out for giggles; parsoid doesn't.
!! test
Italics and bold: 3-quote opening sequence: (3,5)
!! options
parsoid=wt2html
!! wikitext
'''foo'''''
!! html/php+untidy
<p><b>foo</b>
</p>
!! html+tidy
<p><b>foo</b><i></i>
</p>
!!end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: 3-quote opening sequence: (3,5+2) w/ nowiki
!! wikitext
'''foo'''''<nowiki/>''
!! html/php+untidy
<p><b>foo</b>
</p>
!! html+tidy
<p><b>foo</b><i></i>
</p>
!! end


###
### 4-quote opening sequence tests
###

!! test
Italics and bold: 4-quote opening sequence: (4,2)
!! options
parsoid=wt2html
!! wikitext
''''foo''
!! html/*
<p>''<i>foo</i>
</p>
!!end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: 4-quote opening sequence: (4,2) w/ nowiki
!! wikitext
<nowiki>''</nowiki>''foo''
!! html
<p>''<i>foo</i>
</p>
!! end

!! test
Italics and bold: 4-quote opening sequence: (4,3)
!! wikitext
''''foo'''
!! html/*
<p>'<b>foo</b>
</p>
!!end

!! test
Italics and bold: 4-quote opening sequence: (4,4)
!! options
parsoid=wt2html
!! wikitext
''''foo''''
!! html/*
<p>'<b>foo'</b>
</p>
!!end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: 4-quote opening sequence: (4,4) w/ nowiki
!! wikitext
'<nowiki/>'''foo''''
!! html
<p>'<b>foo'</b>
</p>
!! end

# The PHP parser strips the empty tags out for giggles; parsoid doesn't.
!! test
Italics and bold: 4-quote opening sequence: (4,5)
!! options
parsoid=wt2html
!! wikitext
''''foo'''''
!! html/php+untidy
<p>'<b>foo</b>
</p>
!! html+tidy
<p>'<b>foo</b><i></i>
</p>
!!end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: 4-quote opening sequence: (4,5+2) w/ nowiki
!! wikitext
'<nowiki/>'''foo'''''<nowiki/>''
!! html/php+untidy
<p>'<b>foo</b>
</p>
!! html+tidy
<p>'<b>foo</b><i></i>
</p>
!! end


###
### 5-quote opening sequence tests
###

!! test
Italics and bold: 5-quote opening sequence: (5,2)
!! options
parsoid=wt2html
!! wikitext
'''''foo''
!! html/*
<p><b><i>foo</i></b>
</p>
!!end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: 5-quote opening sequence: (5,2+3)
!! wikitext
'''''foo'''''
!! html/*
<p><i><b>foo</b></i>
</p>
!! end

!! test
Italics and bold: 5-quote opening sequence: (5,3)
!! options
parsoid=wt2html
!! wikitext
'''''foo'''
!! html/*
<p><i><b>foo</b></i>
</p>
!!end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: 5-quote opening sequence: (5,3+2)
!! wikitext
'''''foo'''''
!! html
<p><i><b>foo</b></i>
</p>
!! end

!! test
Italics and bold: 5-quote opening sequence: (5,4)
!! options
parsoid=wt2html
!! wikitext
'''''foo''''
!! html/*
<p><i><b>foo'</b></i>
</p>
!!end

!! test
Italics and bold: 5-quote opening sequence: (5,5)
!! wikitext
'''''foo'''''
!! html
<p><i><b>foo</b></i>
</p>
!!end

!! test
Italics and bold: 5-quote opening sequence: (5,6)
!! wikitext
'''''foo''''''
!! html/*
<p><i><b>foo'</b></i>
</p>
!! end

###
### multiple quote sequences in a line
###

!! test
Italics and bold: multiple quote sequences: (2,4,2)
!! options
parsoid=wt2html
!! wikitext
''foo''''bar''
!! html+untidy
<p><i>foo'<b>bar</b></i>
</p>
!! html+tidy
<p><i>foo'<b>bar</b></i><b></b>
</p>
!! html/parsoid
<p><i>foo'<b>bar</b></i>
</p>
!! end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: multiple quote sequences: (2,4,2+3) w/ nowiki
!! wikitext
''foo'<nowiki/>'''bar'''''
!! html
<p><i>foo'<b>bar</b></i>
</p>
!! end

!! test
Italics and bold: multiple quote sequences: (2,4,3)
!! options
parsoid=wt2html
!! wikitext
''foo''''bar'''
!! html/*
<p><i>foo'<b>bar</b></i>
</p>
!! end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: multiple quote sequences: (2,4,3+2) w/ nowiki
!! wikitext
''foo'<nowiki/>'''bar'''''
!! html
<p><i>foo'<b>bar</b></i>
</p>
!! end

!! test
Italics and bold: multiple quote sequences: (2,4,4)
!! options
parsoid=wt2html
!! wikitext
''foo''''bar''''
!! html/*
<p><i>foo'<b>bar'</b></i>
</p>
!! end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: multiple quote sequences: (2,4,4+2) w/ nowiki
!! wikitext
''foo'<nowiki/>'''bar'<nowiki/>'''''
!! html
<p><i>foo'<b>bar'</b></i>
</p>
!! end

!! test
Italics and bold: multiple quote sequences: (3,4,2)
!! options
parsoid=wt2html
!! wikitext
'''foo''''bar''
!! html
<p><b>foo'</b>bar<i></i>
</p>
!! end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: multiple quote sequences: (3,4,2+2) w/ nowiki
!! wikitext
'''foo''''bar''<nowiki/>''
!! html
<p><b>foo'</b>bar<i></i>
</p>
!! end

!! test
Italics and bold: multiple quote sequences: (3,4,3)
!! options
parsoid=wt2html
!! wikitext
'''foo''''bar'''
!! html
<p><b>foo'</b>bar<b></b>
</p>
!! end

# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: multiple quote sequences: (3,4,3+3) w/ nowiki
!! wikitext
'''foo''''bar'''<nowiki/>'''
!! html
<p><b>foo'</b>bar<b></b>
</p>
!! end

###
### other quote tests
###
!! test
Italics and bold: other quote tests: (2,3,5)
!! wikitext
''this is about '''foo's family'''''
!! html
<p><i>this is about <b>foo's family</b></i>
</p>
!!end


!! test
Italics and bold: other quote tests: (2,(3,3),2)
!! wikitext
''this is about '''foo's''' family''
!! html
<p><i>this is about <b>foo's</b> family</i>
</p>
!!end


!! test
Italics and bold: other quote tests: (3,2,3,2)
!! options
parsoid=wt2html
!! wikitext
'''this is about ''foo'''s family''
!! html/*
<p><b>this is about <i>foo</i></b><i>s family</i>
</p>
!!end


# same html as previous, but wikitext adjusted to match parsoid html2wt
!! test
Italics and bold: other quote tests: (3,2,3+2+2,2)
!! wikitext
'''this is about ''foo'''''<nowiki/>''s family''
!! html
<p><b>this is about <i>foo</i></b><i>s family</i>
</p>
!! end


!! test
Italics and bold: other quote tests: (3,2,3,3)
!! wikitext
'''this is about ''foo'''s family'''
!! html/*
<p>'<i>this is about </i>foo<b>s family</b>
</p>
!!end


!! test
Italics and bold: other quote tests: (3,(2,2),3)
!! wikitext
'''this is about ''foo's'' family'''
!! html
<p><b>this is about <i>foo's</i> family</b>
</p>
!!end


!! test
Italicized possessive
!! wikitext
The ''[[Main Page]]'''s talk page.
!! html/php
<p>The <i><a href="/wiki/Main_Page" title="Main Page">Main Page</a>'</i>s talk page.
</p>
!! html/parsoid
<p>The <i><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a>'</i>s talk page.</p>
!! end

!! test
Quote balancing context should be restricted to td/th cells on the same wikitext line
!! options
parsoid=wt2html,wt2wt
!! wikitext
{|
!''a!!''b
|''a||''b
|}
!! html+tidy
<table>
<tbody><tr>
<th><i>a</i></th>
<th><i>b</i>
</th>
<td><i>a</i></td>
<td><i>b</i>
</td></tr></tbody></table>
!! end

!! test
Bold conversion test
!! wikitext
a b'''c ''d e'''f'' g h'''i ''j
!! options
parsoid=wt2html
!! html+tidy
<p>a b'<i>c </i>d e<b>f<i> g h</i></b><i>i </i>j
</p>
!! end

###
### Non-html5 tags
###

!! test
Non-html5 tags should be accepted
!! wikitext
<center>''foo''</center>
<big>''foo''</big>
<font>''foo''</font>
<strike>''foo''</strike>
<tt>''foo''</tt>
!! html
<center><i>foo</i></center>
<p><big><i>foo</i></big>
<font><i>foo</i></font>
<strike><i>foo</i></strike>
<tt><i>foo</i></tt>
</p>
!! end

!! test
<wbr> is valid wikitext (T54468)
!! wikitext
<wbr>
!! html
<p><wbr />
</p>
!! end

# <strike> is HTML4, <s> is HTML4/5.
!! test
<s> or <strike> for strikethrough
!! wikitext
<strike>strike</strike>

<s>s</s>
!! html
<p><strike>strike</strike>
</p><p><s>s</s>
</p>
!! end

## a not permitted
## i,b,br omitted
!! test
Text-level semantic html elements in wikitext
!! wikitext
<em>text</em>
<strong>text</strong>
<small>text</small>
<s>text</s>
<cite>text</cite>
<q>text</q>
<dfn>text</dfn>
<abbr>text</abbr>
<data>text</data>
<time>text</time>
<code>text</code>
<var>text</var>
<samp>text</samp>
<kbd>text</kbd>
<sub>text</sub>
<u>text</u>
<mark>text</mark>
<ruby><rb>明日</rb><rp>(</rp><rt>Ashita</rt><rp> </rp><rtc>あした</rtc><rp>)</rp></ruby>
<bdi>text</bdi>
<bdo>text</bdo>
<span>text</span>
<wbr />
!! html
<p><em>text</em>
<strong>text</strong>
<small>text</small>
<s>text</s>
<cite>text</cite>
<q>text</q>
<dfn>text</dfn>
<abbr>text</abbr>
<data>text</data>
<time>text</time>
<code>text</code>
<var>text</var>
<samp>text</samp>
<kbd>text</kbd>
<sub>text</sub>
<u>text</u>
<mark>text</mark>
<ruby><rb>明日</rb><rp>(</rp><rt>Ashita</rt><rp> </rp><rtc>あした</rtc><rp>)</rp></ruby>
<bdi>text</bdi>
<bdo>text</bdo>
<span>text</span>
<wbr />
</p>
!! end

# test cases taken from
# https://www.w3.org/TR/html5/text-level-semantics.html#the-ruby-element
!! test
Ruby markup (W3C-style)
!! wikitext
;Mono-ruby for individual base characters
:<ruby>日<rt>に</rt>本<rt>ほん</rt>語<rt>ご</rt></ruby>
;Group ruby
:<ruby>今日<rt>きょう</rt></ruby>
;Jukugo ruby
:<ruby>法<rb>華</rb><rb>経</rb><rt>ほ</rt><rt>け</rt><rt>きょう</rt></ruby>
;Inline ruby
:<ruby>東<rb>京</rb><rp>(</rp><rt>とう</rt><rt>きょう</rt><rp>)</rp></ruby>
;Double-sided ruby
:<ruby><rb>旧</rb><rb>金</rb><rb>山</rb><rt>jiù</rt><rt>jīn</rt><rt>shān</rt><rtc>San Francisco</rtc></ruby>

<ruby>
<rb>♥</rb><rtc><rt>Heart</rt></rtc><rtc lang="fr"><rt>Cœur</rt></rtc>
<rb>☘</rb><rtc><rt>Shamrock</rt></rtc><rtc lang="fr"><rt>Trèfle</rt></rtc>
<rb>✶</rb><rtc><rt>Star</rt></rtc><rtc lang="fr"><rt>Étoile</rt></rtc>
</ruby>
!! html
<dl><dt>Mono-ruby for individual base characters</dt>
<dd><ruby>日<rt>に</rt>本<rt>ほん</rt>語<rt>ご</rt></ruby></dd>
<dt>Group ruby</dt>
<dd><ruby>今日<rt>きょう</rt></ruby></dd>
<dt>Jukugo ruby</dt>
<dd><ruby>法<rb>華</rb><rb>経</rb><rt>ほ</rt><rt>け</rt><rt>きょう</rt></ruby></dd>
<dt>Inline ruby</dt>
<dd><ruby>東<rb>京</rb><rp>(</rp><rt>とう</rt><rt>きょう</rt><rp>)</rp></ruby></dd>
<dt>Double-sided ruby</dt>
<dd><ruby><rb>旧</rb><rb>金</rb><rb>山</rb><rt>jiù</rt><rt>jīn</rt><rt>shān</rt><rtc>San Francisco</rtc></ruby></dd></dl>
<p><ruby>
<rb>♥</rb><rtc><rt>Heart</rt></rtc><rtc lang="fr"><rt>Cœur</rt></rtc>
<rb>☘</rb><rtc><rt>Shamrock</rt></rtc><rtc lang="fr"><rt>Trèfle</rt></rtc>
<rb>✶</rb><rtc><rt>Star</rt></rtc><rtc lang="fr"><rt>Étoile</rt></rtc>
</ruby>
</p>
!! end

# The next two test different paths in the sanitizer.
!! test
Non-word characters don't terminate tag names (T19663, T42670, T54022)
!! wikitext
<blockquote|>a</blockquote>

<b→> doesn't terminate </b→>

<bä> doesn't terminate </bä>

<boo> doesn't terminate </boo>

<s.foo> doesn't terminate </s.foo>

<sub-ID#1>
!! html/php+untidy
<p>&lt;blockquote|&gt;a&lt;/blockquote&gt;
</p><p>&lt;b→&gt; doesn't terminate &lt;/b→&gt;
</p><p>&lt;bä&gt; doesn't terminate &lt;/bä&gt;
</p><p>&lt;boo&gt; doesn't terminate &lt;/boo&gt;
</p><p>&lt;s.foo&gt; doesn't terminate &lt;/s.foo&gt;
</p><p>&lt;sub-ID#1&gt;
</p>
!! html+tidy
<p>&lt;blockquote|&gt;a
</p><p>&lt;b→&gt; doesn't terminate &lt;/b→&gt;
</p><p>&lt;bä&gt; doesn't terminate &lt;/bä&gt;
</p><p>&lt;boo&gt; doesn't terminate &lt;/boo&gt;
</p><p>&lt;s.foo&gt; doesn't terminate &lt;/s.foo&gt;
</p><p>&lt;sub-ID#1&gt;
</p>
!! end

###
### See tests/parser/ParserTestParserHook.php for the <tåg> extension)
### This checks that HTML5 tags (with non-word characters in the tag
### name) make it safely through the parser -- the Sanitizer will
### munge them later, as it should.
###
!! test
Non-word characters are valid in extension tags (T19663)
!! wikitext
<tåg>tåg</tåg>
!! html/php
<pre>'tåg'
array (
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tåg" data-mw='{"name":"tåg","attrs":{},"body":{"extsrc":"tåg"}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

!! test
Isolated close tags should be treated as literal text (T54760)
!! options
parsoid=wt2html
!! wikitext
</b>

<s.foo>s</s>
!! html+tidy
<p class="mw-empty-elt">
</p><p>&lt;s.foo&gt;s
</p>
!! end

!! test
Self-closed tag hooks
!! wikitext
<pre />
<gallery />
<indicator name="something" />
!! html/php
<pre></pre>
<ul class="gallery mw-gallery-traditional">
</ul>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{}}'></pre>
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt5" data-mw='{"name":"gallery","attrs":{},"body":null}'>
</ul>
<p><span typeof="mw:Extension/indicator" about="#mwt7" data-mw='{"name":"indicator","attrs":{"name":"something"}}'>
</span></p>
!! end

###
### Special characters
###

!! test
Bare pipe character (T54363)
!! wikitext
|
!! html
<p>|
</p>
!! end

!! test
Bare pipe character from a template (T54363)
!! wikitext
{{pipe}}
!! html
<p>|
</p>
!! end

!! test
Implicit newline insertion/sol when expanding templates (T241150/T14974/T2529)
!! wikitext
{{1x|#foo}}{{1x|#foo}}
!! html/php+tidy
<ol><li>foo</li>
<li>foo</li></ol>
!! html/parsoid
<ol typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"#foo"}},"i":0}},{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"#foo"}},"i":1}}]}'>
<li>foo</li>
<li>foo</li>
</ol>
!! end

###
### <nowiki> test cases
###

!! test
<nowiki> unordered list
!! wikitext
<nowiki>* This is not an unordered list item.</nowiki>
!! html/php
<p>* This is not an unordered list item.
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">* This is not an unordered list item.</span></p>
!! end

!! test
<nowiki> spacing
!! wikitext
<nowiki>Lorem ipsum dolor

sed abit.
  sed nullum.

:and a colon
</nowiki>
!! html/php
<p>Lorem ipsum dolor

sed abit.
  sed nullum.

:and a colon

</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">Lorem ipsum dolor

sed abit.
  sed nullum.

:and a colon
</span></p>
!! end

!! test
Don't parse <nowiki><span class="error"></nowiki> (T149622)
!! wikitext
<nowiki><span class="error"></nowiki>
!! html/php
<p>&lt;span class="error"&gt;
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">&lt;span class="error"></span></p>
!! end

!! test
nowiki 3
!! wikitext
:There is not nowiki.
:There is <nowiki>nowiki</nowiki>.

#There is not nowiki.
#There is <nowiki>nowiki</nowiki>.

*There is not nowiki.
*There is <nowiki>nowiki</nowiki>.
!! html/php
<dl><dd>There is not nowiki.</dd>
<dd>There is nowiki.</dd></dl>
<ol><li>There is not nowiki.</li>
<li>There is nowiki.</li></ol>
<ul><li>There is not nowiki.</li>
<li>There is nowiki.</li></ul>
!! html/parsoid
<dl><dd data-parsoid='{}'>There is not nowiki.</dd>
<dd data-parsoid='{}'>There is <span typeof="mw:Nowiki">nowiki</span>.</dd></dl>

<ol><li data-parsoid='{}'>There is not nowiki.</li>
<li data-parsoid='{}'>There is <span typeof="mw:Nowiki">nowiki</span>.</li></ol>

<ul><li data-parsoid='{}'>There is not nowiki.</li>
<li data-parsoid='{}'>There is <span typeof="mw:Nowiki">nowiki</span>.</li></ul>
!! end

!! test
Entities inside <nowiki>
!! wikitext
<nowiki>&lt;</nowiki>
!! html/php
<p>&lt;
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki"><span typeof="mw:Entity" data-parsoid='{"src":"&amp;lt;","srcContent":"&lt;"}'>&lt;</span></span></p>
!! end

!! test
Entities inside template parameters
!! wikitext
{{1x|&ndash;}}
!! html/php+tidy
<p>&#8211;
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion mw:Entity" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&amp;ndash;"}},"i":0}}]}'>&ndash;</span></p>
!! end

!! test
Properly escape nowiki when combined with other wiki markup
!! options
parsoid=html2wt
!! html/parsoid
<p>* &lt;/nowiki&gt; tag</p>
!! wikitext
<nowiki>*</nowiki> <nowiki>&lt;/nowiki&gt;</nowiki> tag
!! end

!! test
T93824: Put escaped HTML tags inside nowiki
!! options
parsoid=html2wt
!! html/parsoid
<p>&lt;h2&gt;foo&lt;/h2&gt;</p>
!! wikitext
<nowiki><h2>foo</h2></nowiki>
!! end

!! test
T71950: 1. Put nowiki as close to cause as possible, even with non-quote escapable chars
!! options
parsoid=html2wt
!! 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>
!! wikitext
This text: L'[[Foo]]
This text: L<nowiki>''</nowiki>[[Foo]]
This text: L<nowiki>'''</nowiki>[[Foo]]<nowiki>''</nowiki>
!! end

!! test
T71950: 2. Put nowiki as close to cause as possible, after ' :'
!! options
parsoid=html2wt
!! html/parsoid
<p>This text : L''<a rel="mw:WikiLink" href="./Foo">Foo</a>
</p>
!! wikitext
This text : L<nowiki>''</nowiki>[[Foo]]
!! end

# This test and the next one are html2wt only as they test that incorrect wikitext
# passed in template arguments gets escaped or wrapped in nowikis where required.
!! test
T71482: Use {{!}} instead of nowiki for single pipe in template argument
!! options
parsoid=html2wt
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo|bar&quot;}},&quot;i&quot;:0}}]}" about="#mwt1"></span>
<span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo|bar |[[&quot;}},&quot;i&quot;:0}}]}" about="#mwt2"></p>
!! wikitext
{{1x|foo{{!}}bar}}
{{1x|<nowiki>foo|bar |[[</nowiki>}}
!! end

!! test
T53961: Output correct nowikis in template arguments
!! options
parsoid=html2wt
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;a [ b&quot;}},&quot;i&quot;:0}}]}" about="#mwt1"></span>
<span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;a }} b&quot;}},&quot;i&quot;:0}}]}" about="#mwt2"></span>
<span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;a [[ b&quot;}},&quot;i&quot;:0}}]}" about="#mwt3"></span>
<span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;a | {{ ]]&quot;}},&quot;i&quot;:0}}]}" about="#mwt4"></span>
<span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;a }&quot;}},&quot;i&quot;:0}}]}" about="#mwt5"></span></p>
!! wikitext
{{1x|a [ b}}
{{1x|<nowiki>a }} b</nowiki>}}
{{1x|<nowiki>a [[ b</nowiki>}}
{{1x|<nowiki>a | {{ ]]</nowiki>}}
{{1x|a <nowiki>}</nowiki>}}
!! end

!! test
Cases where "!!" needs nowiki protection
!! options
parsoid=html2wt
!! html/parsoid
<table>
<tr><th>this needs protection !! here</th></tr>
</table>

<table>
<tr><th>this does not need
protection !! here</th></tr>
</table>
!! wikitext
{|
!<nowiki>this needs protection !! here</nowiki>
|}

{|
!this does not need
protection !! here
|}
!! end

!! test
Nowiki with newlines in list
!! wikitext
:<nowiki>test
123</nowiki>
!! html/php
<dl><dd>test
123</dd></dl>
!! html/parsoid
<dl><dd data-parsoid="{}"><span typeof="mw:Nowiki">test
123</span></dd></dl>
!! end

## The output here may change with the outcome of T255007
!! test
Nowiki and french spacing
!! wikitext
<nowiki>test : 123</nowiki>
!! html/php
<p>test&#160;: 123
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">test<span typeof="mw:DisplaySpace"> </span>: 123</span></p>
!! end

!! test
T255007: French spacing in raw text elements
!! options
wgRawHtml=1
!! wikitext
<html>
<script>test ; 123</script>
<style>test : 123</style>
</html>
!! html/php
<p>
<script>test ; 123</script>
<style>test : 123</style>

</p>
!! html/parsoid
<p><span typeof="mw:Extension/html" about="#mwt2" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"\n&lt;script>test ; 123&lt;/script>\n&lt;style>test : 123&lt;/style>\n"}}'>
</span><script about="#mwt2">test ; 123</script><span about="#mwt2">
</span><style about="#mwt2">test : 123</style><span about="#mwt2">
</span></p>
!! end

!! test
French spacing and spans
!! wikitext
[[Test]] : <span>123</span>
« Test »<span>123</span>
!! html/php
<p><a href="/index.php?title=Test&amp;action=edit&amp;redlink=1" class="new" title="Test (page does not exist)">Test</a>&#160;: <span>123</span>
«&#160;Test&#160;»<span>123</span>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Test" title="Test" class="new">Test</a><span typeof="mw:DisplaySpace"> </span>: <span data-parsoid='{"stx":"html"}'>123</span>
«<span typeof="mw:DisplaySpace"> </span>Test<span typeof="mw:DisplaySpace"> </span>»<span data-parsoid='{"stx":"html"}'>123</span></p>
!! end

###
### Comments
###

!! test
Comments and Indent-Pre
!! wikitext
<!-- comment 1 --> asdf

<!-- comment 1 --> asdf
<!-- comment 2 -->

<!-- comment 1 --> asdf
<!-- comment 2 -->xyz

<!-- comment 1 --> asdf
<!-- comment 2 --> xyz
!! html
<pre>asdf
</pre>
<pre>asdf
</pre>
<pre>asdf
</pre>
<p>xyz
</p>
<pre>asdf
xyz
</pre>
!! end

!! test
Comment test 2a
!! wikitext
asdf
<!-- comment 1 -->
jkl
!! html
<p>asdf
jkl
</p>
!! end

!! test
Comment test 2b
!! wikitext
asdf
<!-- comment 1 -->

jkl
!! html
<p>asdf
</p><p>jkl
</p>
!! end

!! test
Comment test 3
!! wikitext
asdf
<!-- comment 1 -->
<!-- comment 2 -->
jkl
!! html
<p>asdf
jkl
</p>
!! end

!! test
Comment test 4
!! wikitext
asdf<!-- comment 1 -->jkl
!! html
<p>asdfjkl
</p>
!! end

!! test
Comment spacing
!! wikitext
a
 <!-- foo --> b <!-- bar -->
c
!! html
<p>a
</p>
<pre> b 
</pre>
<p>c
</p>
!! end

!! test
Comment whitespace
!! wikitext
<!-- returns a single newline, not nothing, since the newline after > is not stripped -->
!! html
!! end

!! test
Comment semantics and delimiters
!! wikitext
<!-- --><!----><!-----><!------>
!! html/php
!! html/parsoid
<!-- --><!----><!--&#x2D;--><!--&#x2D;&#x2D;-->
!! end

!! test
Comment semantics and delimiters, redux
!! wikitext
<!-- In SGML every "foo" here would actually show up in the text -- foo -- bar
-- foo -- funky huh? ... -->
!! html/php
!! html/parsoid
<!-- In SGML every "foo" here would actually show up in the text &#x2D;&#x2D; foo &#x2D;&#x2D; bar
&#x2D;&#x2D; foo &#x2D;&#x2D; funky huh? ... -->
!! end

!! test
Comment semantics and delimiters: directors cut
!! wikitext
<!-- ... However we like to keep things simple and somewhat XML-ish so we eat
everything starting with < followed by !-- until the first -- and > we see,
that wouldn't be valid XML however, since in XML -- has to terminate a comment
-->-->
!! html/php
<p>--&gt;
</p>
!! html/parsoid
<!-- ... However we like to keep things simple and somewhat XML&#x2D;ish so we eat
everything starting with < followed by !&#x2D;&#x2D; until the first &#x2D;&#x2D; and &#x3E; we see,
that wouldn't be valid XML however, since in XML &#x2D;&#x2D; has to terminate a comment
--><p>--></p>
!! end

!! test
Comment semantics: nesting
!! wikitext
<!--<!-- no, we're not going to do anything fancy here -->-->
!! html/php
<p>--&gt;
</p>
!! html/parsoid
<!--<!&#x2D;&#x2D; no, we're not going to do anything fancy here --><p>--></p>
!! end

# Parsoid closes the unclosed comment, even if it means a slight
# round-trip diff.
!! test
Comment semantics: unclosed comment at end
!! options
parsoid=wt2html,html2html
!! wikitext
<!--This comment will run out to the end of the document
!! html/php
!! html/parsoid
<!--This comment will run out to the end of the document-->
!! end

!! test
Comment semantics: normalize comments to play nice with XML and browsers
!! wikitext
<!-- Browsers --!> think this is closed -->
<!--> This would normally be text -->
<!---> As would this -->
<!-- XML doesn't like trailing dashes -------->
<!-- Nor doubled hyphens -- anywhere in the data -->
But this is not a comment.
!! html/php
<p>But this is not a comment.
</p>
!! html/parsoid
<!-- Browsers &#x2D;&#x2D;!&#x3E; think this is closed -->
<!--&#x3E; This would normally be text -->
<!--&#x2D;&#x3E; As would this -->
<!-- XML doesn't like trailing dashes &#x2D;&#x2D;&#x2D;&#x2D;&#x2D;&#x2D;-->
<!-- Nor doubled hyphens &#x2D;&#x2D; anywhere in the data -->
<p>But this is not a comment.</p>
!! end

!! test
Comment semantics: round-trip even text which contains encoded -->
!! wikitext
<!-- hello & goodbye - > --&gt; --&amp;gt; --&xx -->
!! html/parsoid
<!-- hello &#x26; goodbye &#x2D; &#x3E; &#x2D;&#x2D;&#x3E; &#x2D;&#x2D;&#x26;gt; &#x2D;&#x2D;&#x26;xx -->
!! end

!! test
Comment in template title
!! wikitext
{{f<!---->oo}}
!! html
<p>FOO
</p>
!! end

!! test
Comment on its own line post-expand
!! wikitext
a
{{blank}}<!---->
b
!! html
<p>a
</p><p>b
</p>
!! end

!! test
Comment on its own line post-expand with non-significant whitespace
!! wikitext
a
 {{blank}} <!----> 
b
!! html
<p>a
</p><p>b
</p>
!! end

!! test
post-expand include size being exceeded
!! options
maxincludesize=30
!! wikitext
{{3x_on_newline|1234567890}}
!! html
<p><a href="/wiki/Template:3x_on_newline" title="Template:3x on newline">Template:3x on newline</a><!-- WARNING: template omitted, post-expand include size too large -->
</p>
!! end

!! test
max template depth being reached
!! options
maxtemplatedepth=1
!! wikitext
{{1x with depth|too deep!}}
!! html
<p><span class="error">Template recursion depth limit exceeded (1)</span>
</p>
!! end

!! test
multiple templates that are redirects
!! wikitext
{{redirect to foo}}
{{redirect to foo}}
!! html
<p>FOO
FOO
</p>
!! end

!! test
Multiple comments should still parse as SOL-transparent
!! options
parsoid=wt2html,wt2wt
!! wikitext
<!--c1-->*a
<!--c2--><!--c3--><!--c4-->*b
!! html/php
<ul><li>a</li>
<li>b</li></ul>
!! html/parsoid
<!--c1--><ul>
<li>a
</li>
<!--c2--><!--c3--><!--c4-->
<li>b
</li>
</ul>
!! end

## Make sure ">" gets escaped in comments to avoid XSS
!! test
IE conditional comments
!! wikitext
<!--[if lt IE 9]>
	<script>alert('hi');</script>
<![endif]-->
!! html/parsoid
<!--[if lt IE 9]&#x3E;
	<script&#x3E;alert('hi');</script&#x3E;
<![endif]-->
!! end

## Regession test for Parsoid
!! test
Comment with valid json
!! wikitext
hi <!--{"hi":"ho"}--> ho
!! html/php
<p>hi  ho
</p>
!! html/parsoid
<p>hi <!--{"hi":"ho"}--> ho</p>
!! end

###
### paragraph wrapping tests
###

!! test
No block tags
!! wikitext
a

b
!! html
<p>a
</p><p>b
</p>
!! end

!! test
Block tag on one line (<div>)
!! wikitext
a <div>foo</div>

b
!! html+untidy
a <div>foo</div>
<p>b
</p>
!! html+tidy
<p>a </p><div>foo</div>
<p>b
</p>
!! end

!! test
No p-wrappable content
!! options
parsoid=wt2html,html2html
!! wikitext
<span><div>x</div></span>
<span><s><div>x</div></s></span>
<small><em></em></small><span><s><div>x</div></s></span>
!! html+tidy
<span><div>x</div></span>
<span><s><div>x</div></s></span>
<p><small><em></em></small></p><span><s><div>x</div></s></span>
!! end

# T177612: Parsoid-only test
!! test
Transclusion meta tags shouldn't trip Parsoid's useless p-wrapper stripping code
!! wikitext
{{1x|<span><div>x</div></span>}}
x
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;span>&lt;div>x&lt;/div>&lt;/span>"}},"i":0}}]}'><div>x</div></span>
<p>x</p>
!! end

!! test
Block tag on one line (<blockquote>)
!! wikitext
a <blockquote>foo</blockquote>

b
!! html+untidy
a <blockquote>foo</blockquote>
<p>b
</p>
!! html+tidy
<p>a </p><blockquote><p>foo</p></blockquote>
<p>b
</p>
!! end

!! test
Block tag on both lines (<div>)
!! wikitext
a <div>foo</div>

b <div>foo</div>
!! html+untidy
a <div>foo</div>
b <div>foo</div>
!! html+tidy
<p>a </p><div>foo</div><p>
b </p><div>foo</div>
!! end

!! test
Block tag on both lines (<blockquote>)
!! wikitext
a <blockquote>foo</blockquote>

b <blockquote>foo</blockquote>
!! html+untidy
a <blockquote>foo</blockquote>
b <blockquote>foo</blockquote>
!! html+tidy
<p>a </p><blockquote><p>foo</p></blockquote><p>
b </p><blockquote><p>foo</p></blockquote>
!! end

!! test
Multiple lines without block tags
!! wikitext
<div>foo</div> a
b
c
d<!--foo--> e
x <div>foo</div> z
!! html+untidy
<div>foo</div> a
<p>b
c
d e
</p>
x <div>foo</div> z
!! html+tidy
<div>foo</div><p> a
</p><p>b
c
d e
</p><p>
x </p><div>foo</div><p> z</p>
!! html/parsoid
<div data-parsoid='{"stx":"html"}'>foo</div><p> a</p>
<p>b
c
d<!--foo--> e</p>
<p>x </p><div data-parsoid='{"stx":"html"}'>foo</div><p> z</p>
!! end

!! test
Empty lines between lines with block tags
!! wikitext
<div></div>


<div></div>a

b
<div>a</div>b

<div>b</div>d


<div>e</div>
!! html+untidy
<div></div>
<p><br />
</p>
<div></div>a
<p>b
</p>
<div>a</div>b
<div>b</div>d
<p><br />
</p>
<div>e</div>
!! html+tidy
<div></div>
<p><br />
</p>
<div></div><p>a
</p><p>b
</p>
<div>a</div><p>b
</p><div>b</div><p>d
</p><p><br />
</p>
<div>e</div>
!! html/parsoid
<div data-parsoid='{"stx":"html"}'></div>

<p><br /></p>
<div data-parsoid='{"stx":"html"}'></div><p>a</p>

<p>b</p>
<div data-parsoid='{"stx":"html"}'>a</div><p>b</p>

<div data-parsoid='{"stx":"html"}'>b</div><p>d</p>

<p><br /></p>
<div data-parsoid='{"stx":"html"}'>e</div>
!! end

!! test
Unclosed HTML p-tags should be handled properly
!! wikitext
<div><p>foo</div>
a

b
!! html/php+tidy
<div><p>foo</p></div>
<p>a
</p><p>b
</p>
!! html/parsoid
<div data-parsoid='{"stx":"html"}'><p data-parsoid='{"stx":"html", "autoInsertedEnd":true}'>foo</p></div>
<p>a</p>
<p>b</p>
!! end

## SSS FIXME: I can come up with other scenarios where this doesn't work because
## of eager output of buffered tokens in the p-wrapper. But, I'm going to ignore
## them for now.
!! test
1. P-wrapping should leave sol-transparent tags outside p-tags where possible
!! options
parsoid=wt2html
!! wikitext
a [[Category:A1]] [[Category:A2]]
[[Category:A3]]
[[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"/>
!! end

!! test
2. P-wrapping should leave sol-transparent tags outside p-tags where possible
!! options
parsoid=wt2html
!! wikitext
[[Category:A1]]a
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:A1"/><p>a</p>
!! end

!! test
No paragraph necessary for SOL transparent template
!! wikitext
<span><div>foo</div></span>
[[Category:Foo]]

<span><div>foo</div></span>
{{1x|[[Category:Foo]]}}
!! html/php
<span><div>foo</div></span>
<span><div>foo</div></span>
!! html/parsoid
<span data-parsoid='{"stx":"html"}'><div data-parsoid='{"stx":"html"}'>foo</div></span>
<link rel="mw:PageProp/Category" href="./Category:Foo"/>

<span data-parsoid='{"stx":"html"}'><div data-parsoid='{"stx":"html"}'>foo</div></span>
<link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Category:Foo]]"}},"i":0}}]}'/>
!! end

!! test
Avoid expanding multiline sol transparent template ranges unnecessarily
!! wikitext
hi


{{1x|<br/>
}}

[[Category:Ho]]
!! html/php
<p>hi
</p><p><br />
<br />
</p>
!! html/parsoid
<p>hi</p>

<p><br />
<br about="#mwt1" typeof="mw:Transclusion" data-parsoid='{}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;br/>\n"}},"i":0}}]}'/><span about="#mwt1">
</span></p>

<link rel="mw:PageProp/Category" href="./Category:Ho" />
!! end

!! test
Paragraph wrapping following unclosed table
!! options
parsoid=wt2html,html2html
!! wikitext
{|
|-

{|
| x
|}

a

b

c
!! html/php+tidy
<table>


</table><table>
<tbody><tr>
<td>x
</td></tr></tbody></table>
<p>a
</p><p>b
</p><p>c
</p>
!! html/parsoid
<table data-parsoid='{"autoInsertedEnd":true}'>
<tbody><tr class="mw-empty-elt" data-parsoid='{"startTagSrc":"|-"}'></tr>

</tbody></table><table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td>x</td></tr>
</tbody></table>

<p>a</p>

<p>b</p>

<p>c</p>
!! end

!! test
Paragraph wrapping suppressed in html p
!! options
parsoid=wt2html,html2html
!! wikitext
<p>


hi



</p>
!! html/php+tidy
<p>


hi



</p>
!! html/parsoid
<p data-parsoid='{"stx":"html"}'>


hi



</p>
!! end

!! test
Dangling table row doesn't prevent p-wrapping
!! options
parsoid=wt2html,html2html
!! wikitext
{|
| hi
|-
|} ho
!! html/parsoid
<table>
<tbody><tr><td>hi</td></tr>
<tr class="mw-empty-elt"></tr>
</tbody></table><p> ho</p>
!! end

!! test
P-wrapping non-breaking spaces
!! wikitext
 
!! html/php+tidy
<p>&#160;
</p>
!! html/parsoid
<p> </p>
!! end

!! test
Paragraph wrapping suppressed in table captions
!! wikitext
{|
|+hi
|ho
|}

{|
|hi
|+ho
|}

it's off to work we go
!! html/php
<table>
<caption>hi
</caption>
<tbody><tr>
<td>ho
</td></tr></tbody></table>
<table>
<tbody><tr>
<td>hi
</td>
</tr></tbody><caption>ho
</caption></table>
<p>it's off to work we go
</p>
!! html/parsoid
<table>
<caption>hi</caption>
<tbody><tr><td>ho</td></tr>
</tbody></table>

<table>
<tbody><tr><td>hi</td></tr>
</tbody><caption>ho</caption>
</table>

<p>it's off to work we go</p>
!! end

###
### Preformatted text
###

!! test
Preformatted text
!! wikitext
 This is some
 Preformatted text
 With ''italic''
 And '''bold'''
 And a [[Main Page|link]]
!! html
<pre>This is some
Preformatted text
With <i>italic</i>
And <b>bold</b>
And a <a href="/wiki/Main_Page" title="Main Page">link</a>
</pre>
!! end

!! test
Tabs don't trigger preformatted text
!! wikitext
	This is not
	 preformatted text.
 This is preformatted text.
 	So is this.
!! 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
Ident preformatting with inline content
!! wikitext
 a
 ''b''
!! html
<pre>a
<i>b</i>
</pre>
!! end

!! test
<pre> with <nowiki> inside (compatibility with 1.6 and earlier)
!! wikitext
<pre><nowiki>
<b>
<cite>
<em>
</nowiki></pre>
!! html
<pre>&lt;b&gt;
&lt;cite&gt;
&lt;em&gt;
</pre>
!! end

!! test
Regression with preformatted in <center>
!! wikitext
<center>
 Blah
</center>
!! html
<center>
<pre>Blah
</pre>
</center>
!! end

!! test
T54763: Preformatted in <blockquote>
!! wikitext
<blockquote>
 Blah
{|
|
 indented cell (no pre-wrapping!)
|}
</blockquote>
!! html
<blockquote>
<p> Blah
</p>
<table>
<tbody><tr>
<td>
<p> indented cell (no pre-wrapping!)
</p>
</td></tr></tbody></table>
</blockquote>
!! end

!! test
T53086: Double newlines in blockquotes should be turned into paragraphs
!! wikitext
<blockquote>
Foo

Bar
</blockquote>
!! html
<blockquote>
<p>Foo
</p><p>Bar
</p>
</blockquote>
!! end

!! test
T17491: <ins>/<del> in blockquote
!! wikitext
<blockquote>
Foo <del>bar</del> <ins>baz</ins> quux
</blockquote>
!! html+untidy
<blockquote>
<p>Foo <del>bar</del> <ins>baz</ins> quux
</p>
</blockquote>
!! html+tidy
<blockquote>
<p>Foo <del>bar</del> <ins>baz</ins> quux
</p>
</blockquote>
!! end

!! test
T17491: <ins>/<del> in blockquote (2)
!! wikitext
<blockquote>Foo <del>bar</del> <ins>baz</ins> quux
</blockquote>
!! html+untidy
<blockquote>Foo <del>bar</del> <ins>baz</ins> quux
</blockquote>
!! html+tidy
<blockquote><p>Foo <del>bar</del> <ins>baz</ins> quux
</p></blockquote>
!! end

!! test
<pre> with attributes (T5202)
!! wikitext
<pre style="background: blue; color:white">Bluescreen of WikiDeath</pre>
!! html
<pre style="background: blue; color:white">Bluescreen of WikiDeath</pre>
!! end

!! test
<pre> with width attribute (T5202)
!! wikitext
<pre width="8">Narrow screen goodies</pre>
!! html
<pre width="8">Narrow screen goodies</pre>
!! end

!! test
<pre> with forbidden attribute (T5202)
!! wikitext
<pre width="8" onmouseover="alert(document.cookie)">Narrow screen goodies</pre>
!! html
<pre width="8">Narrow screen goodies</pre>
!! end

!! test
Entities inside <pre>
!! wikitext
<pre>&lt;</pre>
!! html
<pre>&lt;</pre>
!! end

!! test
<pre> with forbidden attribute values (T5202)
!! wikitext
<pre width="8" style="border-width: expression(alert(document.cookie))">Narrow screen goodies</pre>
!! html
<pre width="8" style="/* insecure input */">Narrow screen goodies</pre>
!! end

!! test
<nowiki> inside <pre> (T15238)
!! wikitext
<pre>
<nowiki>
</pre>
<pre>
<nowiki></nowiki>
</pre>
<pre><nowiki><nowiki></nowiki>Foo<nowiki></nowiki></nowiki></pre>
!! html
<pre>&lt;nowiki&gt;
</pre>
<pre>

</pre>
<pre>&lt;nowiki&gt;Foo&lt;/nowiki&gt;</pre>
!! end

!! test
<nowiki> inside of #tag:pre
!! wikitext
{{#tag:pre|Foo <nowiki>&rarr;bar</nowiki>}}
!! html/php
<pre>Foo &#8594;bar</pre>
!! html/parsoid
<pre about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#tag:pre","function":"tag"},"params":{"1":{"wt":"Foo &lt;nowiki>&amp;rarr;bar&lt;/nowiki>"}},"i":0}}]}'>Foo <span typeof="mw:Entity">→</span>bar</pre>
!! end

## Don't expect this to rt, Parsoid drops the unmatched closing pre tags that
## aren't enclosed in nowikis.
!! test
<nowiki> and <pre> preference (first one wins)
!! options
parsoid=wt2html
!! wikitext
<pre>
<nowiki>
</pre>
</nowiki>
</pre>

<nowiki>
<pre>
<nowiki>
</pre>
</nowiki>
</pre>

!! html/php
<pre>&lt;nowiki&gt;
</pre>
<p>&lt;/nowiki&gt;
</p>

<p>
&lt;pre&gt;
&lt;nowiki&gt;
&lt;/pre&gt;

</p>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\n&lt;nowiki>\n"}}'>&lt;nowiki>
</pre>
<p>&lt;/nowiki></p>


<p><span typeof="mw:Nowiki">
&lt;pre>
&lt;nowiki>
&lt;/pre>
</span></p>
!! end

!! test
</pre> inside nowiki
!! wikitext
<nowiki></pre></nowiki>
!! html
<p>&lt;/pre&gt;
</p>
!! end

!! test
Empty pre; pre inside other HTML tags (T56946)
!! wikitext
a

<div><pre>
foo
</pre></div>
<pre></pre>
!! html/php+tidy
<p>a
</p>
<div><pre>foo
</pre></div>
<pre></pre>
!! html/parsoid
<p>a</p>

<div data-parsoid='{"stx":"html"}'><pre typeof="mw:Extension/pre" about="#mwt2" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\nfoo\n"}}'>foo
</pre></div>
<pre typeof="mw:Extension/pre" about="#mwt4" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{},"body":{"extsrc":""}}'></pre>
!! end

!! test
HTML pre followed by indent-pre
!! wikitext
<pre>foo</pre>
 bar
!! html
<pre>foo</pre>
<pre>bar
</pre>
!! end

!! test
Block tag pre
!! wikitext
<p><pre>foo</pre></p>
!! html/php+tidy
<p class="mw-empty-elt"></p><pre>foo</pre><p class="mw-empty-elt"></p>
!! html/parsoid
<p class='mw-empty-elt' data-parsoid='{"stx":"html","autoInsertedEnd":true}'></p><pre typeof="mw:Extension/pre" about="#mwt2" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"foo"}}'>foo</pre><p class='mw-empty-elt' data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p>
!! end

!!test
Templates: Indent-Pre: 1a. Templates that break a line should suppress <pre>
!! wikitext
 {{1x|}}
!! html
!! end

!!test
Templates: Indent-Pre: 1b. Templates that break a line should suppress <pre>
!! wikitext
 {{1x|
foo}}
!! html
<p>foo
</p>
!!end

!! test
Templates: Indent-Pre: 1c: Wrapping should be based on expanded content
!! wikitext
 {{1x|a
b}}
!! html
<pre>a
</pre>
<p>b
</p>
!!end

!! test
Templates: Indent-Pre: 1d: Wrapping should be based on expanded content
!! wikitext
 {{1x|a
b
c
 d
e
}}
!! html
<pre>a
</pre>
<p>b
c
</p>
<pre>d
</pre>
<p>e
</p>
!!end

!!test
Templates: Indent-Pre: 1e. Wrapping should be based on expanded content
!! wikitext
{{1x| foo}}

{{1x| foo}}{{1x| bar}}

{{1x| foo}}
{{1x| bar}}

{{1x|<!--cmt--> foo}}

<!--cmt-->{{1x| foo}}

{{1x|{{1x| }}bar}}
!! html
<pre>foo
</pre>
<pre>foo bar
</pre>
<pre>foo
bar
</pre>
<pre>foo
</pre>
<pre>foo
</pre>
<pre>bar
</pre>
!!end

!! test
Templates: Indent-Pre: 1f: Wrapping should be based on expanded content
!! wikitext
{{1x| }}a

{{1x|
 }}a

{{1x|
 b}}

{{1x|a
 }}b

{{1x|a
}} b
!! html
<pre>a
</pre>
<p><br />
</p>
<pre>a
</pre>
<p><br />
</p>
<pre>b
</pre>
<p>a
</p>
<pre>b
</pre>
<p>a
</p>
<pre>b
</pre>
!!end

## Hmm, should Parsoid rt this?
!! test
Pres with newline attributes
!! options
parsoid=wt2html,html2html
!! wikitext
<pre class="one
two">hi</pre>
!! html/php
<pre class="one two">hi</pre>
!! html/parsoid
<pre class="one two" typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{"class":"one two"},"body":{"extsrc":"hi"}}'>hi</pre>
!! end

!! test
Things that look like <pre> tags aren't treated as such
!! wikitext
Barack Obama <President> of the United States
<President></President>
!! html
<p>Barack Obama &lt;President&gt; of the United States
&lt;President&gt;&lt;/President&gt;
</p>
!! end

## Remex doesn't account for fostered content.
## The difference between Parsoid and the PHP parser can be attributed to core
## commit 674e8388cba and 710618f89af in Parsoid's repo.  Parsoid doesn't
## tokenize unmatched extension tags that shadow html tags as strings to ease
## an escaping mechanism.  See the comment in `maybeExtensionTag`.
!! test
Handle broken pre-like tags (T66025)
!! options
parsoid=wt2html
!! wikitext
{{1x|<pre <pre>x</pre>}}

<table><pre </table>
!! html/php+untidy
<pre>x</pre>
<table>&lt;pre </table>
!! html/php+tidy
<pre>x</pre>
&lt;pre <table></table>
!! html/parsoid
<pre typeof="mw:Extension/pre mw:Transclusion" about="#mwt2" data-parsoid='{"stx":"html","a":{"&lt;pre":null},"sa":{"&lt;pre":""},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;pre &lt;pre>x&lt;/pre>"}},"i":0}}]}'>x</pre>

<pre data-parsoid='{"stx":"html","src":"&lt;pre &lt;/table>","tagWidths":[13,0],"a":{"&lt;":null,"table":null},"sa":{"&lt;":"","table":""},"fostered":true,"autoInsertedEnd":true}'></pre><table data-parsoid='{"stx":"html","autoInsertedEnd":true}'></table>
!! end

## Similar to the above, but shows the difference between extension and html tags
!! test
Less than in attribute position
!! wikitext
<pre <pre>123</pre>

<div <div>123</div>
!! html/php+tidy
<pre>123</pre><p>
&lt;div </p><div>123</div>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{"&lt;pre":""},"body":{"extsrc":"123"}}'>123</pre><p>

&lt;div </p><div>123</div>
!! end

!! test
Parsoid: handle pre with space after attribute
!! options
parsoid=wt2html
!! wikitext
<pre style="width:50%;" >{{1x|foo}}</pre>
!! html/php
<pre style="width:50%;">{{1x|foo}}</pre>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" style="width:50%;" data-mw='{"name":"pre","attrs":{"style":"width:50%;"},"body":{"extsrc":"{{1x|foo}}"}}'>{{1x|foo}}</pre>
!! end

!! test
Self-closed pre
!! wikitext
<pre />
!! html/php
<pre></pre>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{}}'></pre>
!! end

!! test
Newline before table-close generates empty table row: T208619
!! wikitext
{|

|}
!! html/php+tidy
<table>

<tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<table data-parsoid='{}'>

</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+tidy
<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

# Regression test to prevent problematic simplifications of parser tests
!! test
Don't paragraph-wrap empty newlines between HTML list items
!! options
parsoid=wt2html
!! wikitext
<ol>
<li>foo</li>



<li>foo</li>
</ol>
!! html/php+tidy
<ol>
<li>foo</li>



<li>foo</li>
</ol>
!! html/parsoid
<ol data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html"}'>foo</li>



<li data-parsoid='{"stx":"html"}'>foo</li>
</ol>
!! end

#--------------------------------------------------------------------
# Transclusion parameter whitespace stripping tests
# Behavior is different for positional and named parameters
#--------------------------------------------------------------------
!! test
Templates: Strip leading and trailing whitespace from named-param values
!! wikitext
{{1x|1= a }}

{{1x|1= {{1x|b}} }}

{{1x| 1 =
 c }}

{{1x| 1 =
* d
}}
!! html
<p>a
</p><p>b
</p><p>c
</p>
<ul><li>d</li></ul>
!! end

!! test
Templates: Don't strip whitespace from positional-param values
!! wikitext
{{1x|a }}

{{1x|{{1x|b}} }}

{{1x| c 
}}

{{1x| {{1x|d}}
}}

{{1x|
 e}}

{{1x|
*f}}

{{1x|
 }}g
!! html
<p>a 
</p><p>b 
</p>
<pre>c 
</pre>
<p><br />
</p>
<pre>d
</pre>
<p><br />
</p>
<pre>e
</pre>
<p><br />
</p>
<ul><li>f</li></ul>
<p><br />
</p>
<pre>g
</pre>
!! end

!! test
Templates: Don't recognize targets split by newlines
!! options
parsoid=wt2html
!! wikitext
{{ech
o|foo}}
!! html/php
<p>{{ech
o|foo}}
</p>
!! html/parsoid
<p>{{ech
o|foo}}</p>
!! end

!! test
Templates: Recognize targets when newlines and comments don't split the target
!! options
parsoid=wt2html
!! wikitext
{{  
 <!--X--> 1<!--X-->x<!--X-->  
   <!--X-->   <!--X-->

 |foo}}
!! html/php
<p>foo
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1&lt;!--X-->x&lt;!--X-->  \n   &lt;!--X-->   &lt;!--X-->\n\n ","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
!! end

## NOTE: Parsoid is punting on this edge case for now and just returning
## something that will roundtrip.
!! test
Templates: Target with an extension tag
!! wikitext
{{{{1x|1x}}<nowiki>hi</nowiki>|ho}}
!! html/php
<p>{{1xhi|ho}}
</p>
!! html/parsoid
<p><span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|1x}}&lt;nowiki>hi&lt;/nowiki>"},"params":{"1":{"wt":"ho"}},"i":0}}]}'>{{{{1x|1x}}&lt;nowiki>hi&lt;/nowiki>|ho}}</span></p>
!! end

!! test
Templates: Handle empty comment-and-ws-only lines correctly
!! wikitext
{{1x|foo
<!--should be ignored-->
 <!--should be ignored as well-->
bar}}
!! html/php
<p>foo
bar
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo\n&lt;!--should be ignored-->\n &lt;!--should be ignored as well-->\nbar"}},"i":0}}]}'>foo
</span><span about="#mwt1"><!--should be ignored--></span><span about="#mwt1">
 </span><span about="#mwt1"><!--should be ignored as well--></span><span about="#mwt1">
bar</span></p>
!! end

!! test
Templates: Handle comments in the target
!! wikitext
{{1x
<!-- should be ignored -->
|foo}}

{{1x
<!-- should be ignored and spaces on next line should not trip us up (T147742) -->
  |foo}}

{{1x<!-- should be ignored -->
|foo}}

{{1x<!-- should be ignored -->|foo}}

{{<!-- should be ignored -->1x|foo}}
!! html/php
<p>foo
</p><p>foo
</p><p>foo
</p><p>foo
</p><p>foo
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x\n&lt;!-- should be ignored -->\n","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>

<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x\n&lt;!-- should be ignored and spaces on next line should not trip us up (T147742) -->\n  ","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>

<p><span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x&lt;!-- should be ignored -->\n","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>

<p><span about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x&lt;!-- should be ignored -->","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>

<p><span about="#mwt5" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
!! end

!! test
Templates: Handle comments in parameter names (T69657)
!! wikitext
{{1x|1
<!-- should be ignored -->
=foo}}

{{1x|
<!-- should be ignored -->
1 = foo}}

{{1x|1<!-- should be ignored -->=foo}}

{{1x|<!-- should be ignored -->1=foo}}
!! html/php
<p>foo
</p><p>foo
</p><p>foo
</p><p>foo
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo","key":{"wt":"1\n&lt;!-- should be ignored -->"}}},"i":0}}]}'>foo</span></p>

<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo","key":{"wt":"&lt;!-- should be ignored -->\n1"}}},"i":0}}]}'>foo</span></p>

<p><span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo","key":{"wt":"1&lt;!-- should be ignored -->"}}},"i":0}}]}'>foo</span></p>

<p><span about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo","key":{"wt":"&lt;!-- should be ignored -->1"}}},"i":0}}]}'>foo</span></p>
!! end

!! test
Templates: Other wikitext in parameter names (T69657)
!! wikitext
{{1x|''1''=foo}}
!! html/php
<p>{{{1}}}
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"&#39;&#39;1&#39;&#39;":{"wt":"foo"}},"i":0}}]}'>{{{1}}}</span></p>
!! end

!! test
Templates: With colons
!! wikitext
{{With: Colon}}
!! html/php
<p>Template with colon
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"With: Colon","href":"./Template:With:_Colon"},"params":{},"i":0}}]}'>Template with colon</span></p>
!! end

#--------------------------------------------------------------------
# Transclusion parameter escaping tests
#--------------------------------------------------------------------

!! test
Templates: Parsoid parameter escaping test 1
!! wikitext
{{1x|[foo]|{{1x|[bar]}}}}
!! html/php+tidy
<p>[foo]
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[foo]"},"2":{"wt":"{{1x|[bar]}}"}},"i":0}}]}'>[foo]</span></p>
!! end

!! test
Parsoid: Pipes in external links in template parameter
!! wikitext
{{1x|[{{1x|http://example.com}} link]}}
!! 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" class="external text" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[{{1x|http://example.com}} link]"}},"i":0}}]}'>link</a></p>
!! end

!! test
Parsoid: pipe in transclusion parameter
!! wikitext
{{1x|http://foo.com/a&#124;b}}
!! 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%7Cb" about="#mwt1" typeof="mw:Transclusion" class="external free" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"http://foo.com/a&amp;#124;b"}},"i":0}}]}'>http://foo.com/a%7Cb</a></p>
!! end

!! test
Parsoid: Pipe in external link target and content in template parameter
!! options
parsoid=html2wt,wt2wt
!! wikitext
{{1x|[http://foo.com/a&#124;b a&#124;b]}}
!! html/php+tidy
<p><a rel="nofollow" class="external text" href="http://foo.com/a%7Cb">a&#124;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":"1x","href":"./Template:1x"},
"params":{"1":{"wt":"[http://foo.com/a|b a|b]"}},"i":0}}]}'>a|b</a></p>
!! end

!! test
Parsoid: Pipe in template with nested template in external link target in template parameter (seriously)
!! wikitext
{{1x|[{{fullurl:{{FULLPAGENAME}}|action=edit}} bar]}}
!! html/php+tidy
<p><a rel="nofollow" class="external text" href="http://example.org/index.php?title=Parser_test&amp;action=edit">bar</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.org/index.php?title=Parser_test&amp;action=edit" typeof="mw:Transclusion" class="external text" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[{{fullurl:{{FULLPAGENAME}}|action=edit}} bar]"}},"i":0}}]}'>bar</a></p>
!! end

!! test
Templates: Don't escape already nowiki-escaped text in template parameters
!! options
parsoid=html2wt,wt2wt
!! wikitext
{{1x|foo<nowiki>|</nowiki>bar}}
{{1x|<nowiki>&lt;div&gt;</nowiki>}}
{{1x|<nowiki></nowiki>}}
!! 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":"1x","href":"./Template:1x"},"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":"1x","href":"./Template:1x"},"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":"1x","href":"./Template:1x"},"params":{"1":{"wt":"<nowiki></nowiki>"}},"i":0}}]}'></span>
</p>
!! end

## T54824
!! test
Templates: '=' char in nested transclusions should not trigger nowiki escapes or conversion to named param
!! options
parsoid=html2wt,wt2wt
!! wikitext
{{1x|{{1x|1=bar}}}}
!! html/php+tidy
<p>bar
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{1x|1=bar}}"}},"i":0}}]}'>bar</span></p>
!! end

## T58733
!! test
Templates parameters with special tokenizing behavior dont get modified because of arg escaping
!! wikitext
{{1x|a : b}}
!! html/php+tidy
<p>a&#160;: b
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a : b"}},"i":0}}]}'>a<span typeof="mw:DisplaySpace"> </span>: b</span></p>
!! end

## T73412
!! test
Templates: Preserve blank parameter names
!! wikitext
{{1x|=foo}}
!! html/php+tidy
<p>{{{1}}}
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"":{"wt":"foo"}},"i":0}}]}'>{{{1}}}</span></p>
!! end

!! test
Templates: Preserve blank parameter names in other positions
!! wikitext
{{blank_param|bar|=foo}}
!! html/php+tidy
<p>bar
foo
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"},{"k":"","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"blank_param","href":"./Template:Blank_param"},"params":{"1":{"wt":"bar"},"":{"wt":"foo"}},"i":0}}]}'>bar
foo</span></p>
!! end

###
### Parsoid-centric tests for testing RT edge cases for pre
###

!!test
1a. Indent-Pre and Comments
!! wikitext
 a
<!--a-->
c
!! html
<pre>a
</pre>
<p>c
</p>
!!end

!!test
1b. Indent-Pre and Comments
!! wikitext
 a
 <!--a-->
c
!! html
<pre>a
</pre>
<p>c
</p>
!!end

!!test
1c. Indent-Pre and Comments
!! wikitext
<!--a-->  a

 <!--a--> a
!! html
<pre> a
</pre>
<pre> a
</pre>
!!end

!!test
1d. Indent-Pre and Comments
(Pre-handler currently cannot distinguish between comment/ws order and normalizes them to [comment,ws] order)
!! wikitext
<!--a--> a

 <!--b-->b
!! html
<pre>a
</pre>
<pre>b
</pre>
!!end

!!test
2a. Indent-Pre and tables
!! wikitext
 {|
 |-
 !h1!!h2
 |foo||bar
 |}
!! html
<table>

<tbody><tr>
<th>h1</th>
<th>h2
</th>
<td>foo</td>
<td>bar
</td></tr></tbody></table>
!!end

!!test
2b. Indent-Pre and tables
!! wikitext
  {|
 |-
|foo
|}
!! html
<table>

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

!!test
2c. Indent-Pre and tables (T44252)
!! wikitext
{|
 |+foo
 !  |bar
|}
!! html
<table>
<caption>foo
</caption>
<tbody><tr>
<th>bar
</th></tr></tbody></table>
!!end

!!test
2d. Indent-Pre and tables
!! wikitext
 a
 {|
 |b
 |}
!! html/php
<pre>a
</pre>
<table>
<tbody><tr>
<td>b
</td></tr></tbody></table>
!! html/parsoid
<pre>a</pre>
 <table>
 <tbody><tr><td> b</td></tr>
 </tbody></table>
!!end

!!test
2e. Indent-Pre and table-line syntax
!! wikitext
 a
 | b
 | c
!! html/php
<pre>a
| b
| c
</pre>
!!end

!!test
2f. Indent-pre started by table-line syntax
!! wikitext
a
 | b
 | c
!! html/php
<p>a
</p>
<pre>| b
| c
</pre>
!! html/parsoid
<p>a</p>
<pre>
| b
| c</pre>
!!end

!! test
2g. Indented table markup mixed with indented pre content (proposed in T8200)
!! wikitext
 <table>
 <tr>
 <td>
 Text that should be rendered preformatted
 </td>
 </tr>
 </table>
!! html
 <table>
 <tbody><tr>
 <td>
<pre>Text that should be rendered preformatted
</pre>
 </td>
 </tr>
 </tbody></table>
!! end

!! test
2h. Indent pre in tables
!! options
parsoid=wt2html,html2html
!! wikitext
{|
 !
 foo
 !
 bar
 |-
 |
 baz
 {{!}}
 bam
 |}
!! html/php
<table>
<tbody><tr>
<th>
<pre>foo
</pre>
</th>
<th>
<pre>bar
</pre>
</th></tr>
<tr>
<td>
<pre>baz
</pre>
</td>
<td>
<pre>bam
</pre>
</td></tr></tbody></table>
!! html/parsoid
<table>
 <tbody><tr><th>
<pre>foo</pre>
</th><th>
<pre>bar</pre>
</th></tr><tr>
 <td>
<pre>baz</pre>
</td><td data-parsoid='{"startTagSrc":"{{!}}"}'>
<pre>bam</pre>
</td></tr></tbody></table>
!! end

!! test
3a. Indent-Pre and block tags (single-line html)
!! wikitext
 a <p> foo </p>
 b <div> foo </div>
 c <blockquote> foo </blockquote>
 <span> foo </span>
!! html+untidy
 a <p> foo </p>
 b <div> foo </div>
 c <blockquote> foo </blockquote>
<pre><span> foo </span>
</pre>
!! html/php+tidy
<p> a </p><p> foo </p><p>
 b </p><div> foo </div><p>
 c </p><blockquote><p> foo </p></blockquote>
<pre><span> foo </span>
</pre>
!! html/parsoid
<p> a </p><p data-parsoid='{"stx":"html"}'> foo </p><p>
 b </p><div data-parsoid='{"stx":"html"}'> foo </div><p>
 c </p><blockquote data-parsoid='{"stx":"html"}'><p> foo </p></blockquote>
<pre><span data-parsoid='{"stx":"html"}'> foo </span></pre>
!! end

!! test
3b. Indent-Pre and block tags (multi-line html)
!! wikitext
 a <span>foo</span>
<!-- comment --> b <div> foo </div>
!! html/php+untidy
<pre>a <span>foo</span>
</pre>
 b <div> foo </div>
!! html/parsoid
<pre>a <span data-parsoid='{"stx":"html"}'>foo</span></pre>
<!-- comment --> <p>b </p><div data-parsoid='{"stx":"html"}'> foo </div>
!! html/php+tidy
<pre>a <span>foo</span>
</pre><p>
 b </p><div> foo </div>
!! end

!! test
3c. Indent-Pre and block tags (pre-content on separate line)
!! wikitext
<p>
 foo
</p>

<div>
 foo
</div>

<center>
 foo
</center>

<blockquote>
 foo
</blockquote>

<blockquote>
<pre>
foo
</pre>
</blockquote>

<table><tr><td>
 foo
</td></tr></table>

<ul><li>
  foo
</li></ul>
!! html/php
<p>
 foo
</p>
<div>
<pre>foo
</pre>
</div>
<center>
<pre>foo
</pre>
</center>
<blockquote>
<p> foo
</p>
</blockquote>
<blockquote>
<pre>foo
</pre>
</blockquote>
<table><tbody><tr><td>
<pre>foo
</pre>
</td></tr></tbody></table>
<ul><li>
  foo
</li></ul>
!! html/parsoid
<p data-parsoid='{"stx":"html"}'>
 foo
</p>

<div>
<pre>foo</pre>
</div>

<center>
<pre>foo</pre>
</center>

<blockquote>
<p> foo</p>
</blockquote>

<blockquote>
<pre typeof="mw:Extension/pre" about="#mwt3" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\nfoo\n"}}'>foo
</pre>
</blockquote>

<table data-parsoid='{"stx":"html"}'><tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'>
<pre>foo</pre>
</td></tr></tbody></table>

<ul data-parsoid='{"stx":"html"}'><li data-parsoid='{"stx":"html"}'>
  foo
</li></ul>
!! end

!! test
4. Indent-Pre and extension tags
!! options
parsoid=wt2html,html2html
!! wikitext
 a <tag />
!! html/php+tidy
<p> a </p><pre>NULL
array (
)
</pre>
!! html/parsoid
<p> a </p><pre typeof="mw:Extension/tag" about="#mwt2" data-mw='{"name":"tag","attrs":{}}'></pre>
!! end

!! test
5. Indent-Pre and html pre
!! wikitext
 <pre class="123">hi</pre>
!! html/php
 <pre class="123">hi</pre>
!! html/parsoid
 <pre class="123" typeof="mw:Extension/pre" about="#mwt2" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{"class":"123"},"body":{"extsrc":"hi"}}'>hi</pre>
!! end

!! test
Serializing indent pre at sol
!! html/parsoid
 <pre>hi</pre>
!! html/php
<pre>hi
</pre>
!! wikitext
 hi
!! end

!!test
Render paragraphs when indent-pre is suppressed in blocklevels
!! wikitext
<blockquote>
 foo

 bar
</blockquote>
!! html
<blockquote>
<p> foo
</p><p> bar
</p>
</blockquote>
!!end

!!test
4. Multiple spaces at start-of-line
!! wikitext
    <p> foo </p>
    foo
	{|
|foo
|}
!! html
    <p> foo </p>
<pre>   foo
</pre>
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!!end

## NOTE: the leading white-space chars on empty line are significant
!! test
5a. White-space in indent-pre
!! wikitext
 a<br />
 
 b
!! html
<pre>a<br />

b
</pre>
!! end

## NOTE: the leading white-space chars on empty line are significant
!! test
5b. White-space in indent-pre
!! wikitext
 a
 
 b
 
 
 c
!! html
<pre>a

b


c
</pre>
!! end

!! test
5c. White-space in indent-pre
!! wikitext
 ''a''
  ''b''
   ''c''
!! html
<pre><i>a</i>
 <i>b</i>
  <i>c</i>
</pre>
!! end

!! test
6. Pre-blocks should extend across lines with leading WS even when there is no wrappable content
!! wikitext
 a
 
 <!-- continue -->
 b

 c
 
d
!! html
<pre>a

b
</pre>
<pre>c

</pre>
<p>d
</p>
!! end

!! test
7a. Indent-pre and category links
!! options
parsoid=wt2html,wt2wt
!! wikitext
 [[Category:foo]] <!-- No pre-wrapping -->
{{1x| [[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":"1x","href":"./Template:1x"},"params":{"1":{"wt":" [[Category:foo]]"}},"i":0}}]}'> </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1"> <!-- No pre&#x2D;wrapping -->
!! end

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
!! test
7b. Indent-pre and category links
!! options
parsoid=wt2html
!! wikitext
 [[Category:foo]] a
 [[Category:foo]] {{1x|b}}
!! html/parsoid
<pre><link rel="mw:PageProp/Category" href="./Category:Foo"> a
 <link rel="mw:PageProp/Category" href="./Category:Foo"> <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b"}},"i":0}}]}'>b</span></pre>
!! end

!! test
Indent-Pre: Newlines in comments shouldn't affect sol state
!! wikitext
a <!--
foo
--> b
!! html/php+tidy
<p>a  b
</p>
!! html/parsoid
<p>a <!--
foo
--> b</p>
!! end

!! test
Indent pre with leading colon
!! wikitext
 :foo
!! html/php
<pre>:foo
</pre>
!! html/parsoid
<pre>:foo</pre>
!! end

!! test
Preserving leading whitespace in indent-pre suppressing contexts
!! wikitext
<ol>
<li>
 foo
 bar
</li>
</ol>
!! html/php
<ol>
<li>
 foo
 bar
</li>
</ol>
!! html/parsoid
<ol data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html"}'>
 foo
 bar
</li>
</ol>
!! end

###
### HTML-pre (some to spec PHP parser behavior and some Parsoid-RT-centric)
###

!!test
HTML-pre: 1. embedded newlines
!! wikitext
<pre>foo</pre>

<pre>
foo
</pre>

<pre>

foo
</pre>

<pre>


foo
</pre>
!! html/php+tidy
<pre>foo</pre>
<pre>foo
</pre>
<pre>

foo
</pre>
<pre>


foo
</pre>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"foo"}}'>foo</pre>

<pre typeof="mw:Extension/pre" about="#mwt4" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\nfoo\n"}}'>foo
</pre>

<pre typeof="mw:Extension/pre" about="#mwt6" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\n\nfoo\n"}}'>

foo
</pre>

<pre typeof="mw:Extension/pre" about="#mwt8" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\n\n\nfoo\n"}}'>


foo
</pre>
!!end

!! test
HTML-pre: big spaces
!! wikitext
<pre>




haha




haha




</pre>
!! html/php+tidy
<pre>




haha




haha




</pre>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\n\n\n\n\nhaha\n\n\n\n\nhaha\n\n\n\n\n"}}'>




haha




haha




</pre>
!! end

!!test
HTML-pre: 2: indented text
!! wikitext
<pre>
 foo
</pre>
!! html
<pre> foo
</pre>
!!end

!!test
HTML-pre: 3: other wikitext
!! wikitext
<pre>
* foo
# bar
= no-h =
'' no-italic ''
[[ NoLink ]]
</pre>
!! html/php
<pre>* foo
# bar
= no-h =
'' no-italic ''
[[ NoLink ]]
</pre>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\n* foo\n# bar\n= no-h =\n&#39;&#39; no-italic &#39;&#39;\n[[ NoLink ]]\n"}}'>* foo
# bar
= no-h =
'' no-italic ''
[[ NoLink ]]
</pre>
!!end

###
### Definition lists
###

!! test
Simple definition
!! options
parsoid=wt2html,html2html
!! wikitext
;name :Definition
!! html
<dl><dt>name</dt>
<dd>Definition</dd></dl>
!! end

!! test
Definition list for indentation only
!! wikitext
:Indented text
!! html
<dl><dd>Indented text</dd></dl>
!! end

!! test
Definition list with no space
!! wikitext
;name:Definition
!! html
<dl><dt>name</dt>
<dd>Definition</dd></dl>
!!end

!! test
Definition list with URL link
!! options
parsoid=wt2html,html2html
!! wikitext
;http://example.com/ :definition
!! html/php
<dl><dt><a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a></dt>
<dd>definition</dd></dl>
!! html/parsoid
<dl><dt><a rel="mw:ExtLink" href="http://example.com/" class="external free">http://example.com/</a></dt><dd data-parsoid='{"stx":"row"}'>definition</dd></dl>
!! end

!! test
Definition list with bracketed URL link
!! wikitext
;[http://www.example.com/ Example]:Something about it
!! html
<dl><dt><a rel="nofollow" class="external text" href="http://www.example.com/">Example</a></dt>
<dd>Something about it</dd></dl>
!! end

!! test
Definition list with wikilink containing colon
!! wikitext
;[[Help:FAQ]]:The least-read page on Wikipedia
!! html
<dl><dt><a href="/index.php?title=Help:FAQ&amp;action=edit&amp;redlink=1" class="new" title="Help:FAQ (page does not exist)">Help:FAQ</a></dt>
<dd>The least-read page on Wikipedia</dd></dl>
!! end

# At Brion's and JeLuF's insistence... :)
!! test
Definition list with news link containing colon
!! options
parsoid=wt2html,html2html
!! wikitext
;news:alt.wikipedia.rox :This isn't even a real newsgroup!
!! html/php
<dl><dt><a rel="nofollow" class="external free" href="news:alt.wikipedia.rox">news:alt.wikipedia.rox</a></dt>
<dd>This isn't even a real newsgroup!</dd></dl>
!! html/parsoid
<dl><dt><a rel="mw:ExtLink" href="news:alt.wikipedia.rox" class="external free" data-parsoid='{"stx":"url"}'>news:alt.wikipedia.rox</a></dt><dd data-parsoid='{"stx":"row"}'>This isn't even a real newsgroup!</dd></dl>
!! end

!! test
Malformed definition list with colon
!! wikitext
;news:alt.wikipedia.rox -- don't crash or enter an infinite loop
!! html
<dl><dt><a rel="nofollow" class="external free" href="news:alt.wikipedia.rox">news:alt.wikipedia.rox</a> -- don't crash or enter an infinite loop</dt></dl>
!! end

!! test
Definition lists: colon in external link text
!! options
parsoid=wt2html,html2html
!! wikitext
;[http://www.wikipedia2.org/ Wikipedia :The Next Generation] :OK, I made that up
!! html/php
<dl><dt><a rel="nofollow" class="external text" href="http://www.wikipedia2.org/">Wikipedia :The Next Generation</a></dt>
<dd>OK, I made that up</dd></dl>
!! html/parsoid
<dl><dt><a rel="mw:ExtLink" href="http://www.wikipedia2.org/" class="external text">Wikipedia :The Next Generation</a></dt><dd data-parsoid='{"stx":"row"}'>OK, I made that up</dd></dl>
!! end

!! test
Definition lists: colon in HTML attribute
!! wikitext
;<b style="display: inline">bold</b>
!! html
<dl><dt><b style="display: inline">bold</b></dt></dl>
!! end

!! test
Definition lists: self-closed tag
!! options
parsoid=wt2html,html2html
!! wikitext
;one<br/>two :two-line fun
!! html
<dl><dt>one<br />two</dt>
<dd>two-line fun</dd></dl>
!! end

!! test
Definition lists: ignore colons inside tags
!! wikitext
;one <b>two : tag <i>fun:</i>:</b>:def
!! html
<dl><dt>one <b>two&#160;: tag <i>fun:</i>:</b></dt>
<dd>def</dd></dl>
!! end

!! test
Definition lists: excess closed tags
!! options
parsoid=wt2html,html2html
!! wikitext
;one</b>two :bad tag fun
!! html/php+tidy
<dl><dt>onetwo</dt>
<dd>bad tag fun</dd></dl>
!! html/parsoid
<dl><dt>one<meta typeof="mw:Placeholder/StrippedTag" data-parsoid='{"src":"&lt;/b>","name":"b"}'/>two</dt><dd data-parsoid='{"stx":"row"}'>bad tag fun</dd></dl>
!! end

!! test
T13748: Literal closing tags
!! wikitext
<dl>
<dt>test 1</dt>
<dd>test test test test test</dd>
<dt>test 2</dt>
<dd>test test test test test</dd>
</dl>
!! html
<dl>
<dt>test 1</dt>
<dd>test test test test test</dd>
<dt>test 2</dt>
<dd>test test test test test</dd>
</dl>
!! end

!! test
Definition and unordered list using wiki syntax nested in unordered list using html tags.
!! options
parsoid=wt2html,html2html
!! wikitext
<ul><li>
;term :description
*unordered
</li></ul>
!! html
<ul><li>
<dl><dt>term</dt>
<dd>description</dd></dl>
<ul><li>unordered</li></ul>
</li></ul>
!! end

!! test
Definition list with empty definition and following paragraph
!! wikitext
;term:

Paragraph text
!! html
<dl><dt>term</dt>
<dd></dd></dl>
<p>Paragraph text
</p>
!! end

!! test
Nested definition lists using html syntax
!! wikitext
<dl><dt>x</dt>
<dd>a</dd>
<dd>b</dd></dl>
!! html
<dl><dt>x</dt>
<dd>a</dd>
<dd>b</dd></dl>
!! end

!! test
Definition Lists: No nesting: Multiple dd's
!! wikitext
;x
:a
:b
!! html
<dl><dt>x</dt>
<dd>a</dd>
<dd>b</dd></dl>
!! end

!! test
Definition Lists: Indentation: Regular
!! wikitext
:i1
::i2
:::i3
!! html
<dl><dd>i1
<dl><dd>i2
<dl><dd>i3</dd></dl></dd></dl></dd></dl>
!! end

!! test
Definition Lists: Indentation: Missing 1st level
!! wikitext
::i2
:::i3
!! html
<dl><dd><dl><dd>i2
<dl><dd>i3</dd></dl></dd></dl></dd></dl>
!! end

!! test
Definition Lists: Indentation: Multi-level indent
!! wikitext
:::i3
!! html
<dl><dd><dl><dd><dl><dd>i3</dd></dl></dd></dl></dd></dl>
!! end

!! test
Definition Lists: Hacky use to indent tables
!! wikitext
::{|
|foo
|bar
|}
this text
should be left alone
!! html
<dl><dd><dl><dd><table>
<tbody><tr>
<td>foo
</td>
<td>bar
</td></tr></tbody></table></dd></dl></dd></dl>
<p>this text
should be left alone
</p>
!! end

!! test
Definition Lists: Hacky use to indent tables (with content following table)
!! wikitext
:{|
|foo
|bar
|} <!--c1--> this text should be part of the dl
!! html/php+tidy
<dl><dd><table>
<tbody><tr>
<td>foo
</td>
<td>bar
</td></tr></tbody></table>  this text should be part of the dl</dd></dl>
!! html/parsoid
<dl><dd><table>
<tbody><tr>
<td>foo
</td>
<td>bar
</td></tr></tbody></table> <!--c1--> this text should be part of the dl</dd></dl>
!! end

!! test
Definition Lists: Hacky use to indent tables, with comments (T65979)
!! wikitext
<!-- foo -->
::{|
|foo
|bar
|}<!-- bar -->
this text
should be left alone
!! html/parsoid
<!-- foo -->
<dl><dd><dl><dd><table><tr>
<td>foo</td>
<td>bar</td>
</tr></table><!-- bar --></dd></dl></dd></dl>
<p>this text
should be left alone</p>
!! end

!! test
Definition Lists: Hacky use to indent tables, with comment before table
!!options
parsoid=wt2html
!! wikitext
::<!-- foo -->{|
|foo
|}
!! html/parsoid
<dl><dd><dl><dd><!-- foo --><table><tr>
<td>foo</td>
</tr></table></dd></dl></dd></dl>
!! end

# Note that the legacy parser closes the list completely for the
# hacky-indent table and then reopens it; Parsoid emits the "expected"
# output.  Parsoid team regards this as a bug in the legacy parser.
!! test
Definition Lists: Hack use to indent tables, in a nested list context (T262943)
!! wikitext
This is a discussion thread.

:Parent comment.
::Child comment
::{|
|With a
|Table!
|}
!! html/php
<p>This is a discussion thread.
</p>
<dl><dd>Parent comment.
<dl><dd>Child comment</dd></dl></dd></dl>
<dl><dd><dl><dd><table>
<tbody><tr>
<td>With a
</td>
<td>Table!
</td></tr></tbody></table></dd></dl></dd></dl>
!! html/parsoid
<p>This is a discussion thread.</p>

<dl><dd data-parsoid='{}'>Parent comment.
<dl><dd data-parsoid='{}'>Child comment</dd>
<dd data-parsoid='{}'><table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td>With a</td>
<td>Table!</td></tr>
</tbody></table></dd></dl></dd></dl>
!! end


# The trailing whitespace in this test is to catch a regression in
# Parsoid after T54473.
!! test
Definition Lists: Hacky use to indent tables (WS-insensitive)
!! wikitext
:{|
|a
|} 
!! html/php
<dl><dd><table>
<tbody><tr>
<td>a
</td></tr></tbody></table></dd></dl>
!! html/parsoid
<dl><dd><table>
<tbody><tr><td>a</td></tr>
</tbody></table></dd></dl>
!! end

## The PHP parser treats : items (dd) without a corresponding ; item (dt)
## as an empty dt item.  It also ignores all but the last ";" when followed
## by ":" later on.  So, ";" are not ignored in ";;;t3" but are ignored  in
## ";;;t3 :d1".  So, PHP parser behavior is a little inconsistent wrt multiple
## ";"s.
##
## Ex: ";;t2 ::d2" is transformed into:
##
## <dl>
##   <dt>t2 </dt>
##   <dd>
##     <dl>
##       <dt></dt>
##       <dd>d2</dd>
##     </dl>
##   </dd>
## </dl>
##
## But, Parsoid treats "; :" as a tight atomic unit and excess ":" as plain text
## So, the same wikitext above (;;t2 ::d2) is transformed into:
##
## <dl>
##   <dt>
##     <dl>
##       <dt>t2 </dt>
##       <dd>:d2</dd>
##     </dl>
##    </dt>
## </dl>
##
## All Parsoid only definition list tests have this difference.
##
## See also: https://phabricator.wikimedia.org/T8569
## and https://lists.wikimedia.org/pipermail/wikitext-l/2011-November/000483.html

!! test
Table / list interaction: indented table with lists in table contents
!! wikitext
:{|
|-
|a

*b
|-
|c

*d
|}
!! html
<dl><dd><table>

<tbody><tr>
<td>a
<ul><li>b</li></ul>
</td></tr>
<tr>
<td>c
<ul><li>d</li></ul>
</td></tr></tbody></table></dd></dl>
!! end

!!test
Table / list interaction: lists nested in tables nested in indented lists
!! wikitext
:{|
|
:a
:b
|
*c
*d
|}

*e
*f
!! html
<dl><dd><table>
<tbody><tr>
<td>
<dl><dd>a</dd>
<dd>b</dd></dl>
</td>
<td>
<ul><li>c</li>
<li>d</li></ul>
</td></tr></tbody></table></dd></dl>
<ul><li>e</li>
<li>f</li></ul>
!!end

!! test
Definition Lists: Nesting: Multi-level (Parsoid only)
!! wikitext
;t1:d1
;;t2::d2
;;;t3:::d3
!! html/parsoid
<dl>
  <dt>t1 </dt>
  <dd>d1</dd>
  <dt>
    <dl>
      <dt>t2 </dt>
      <dd>:d2</dd>
      <dt>
        <dl>
          <dt>t3 </dt>
          <dd>::d3</dd>
        </dl>
      </dt>
    </dl>
  </dt>
</dl>
!! end


!! test
Definition Lists: Nesting: Test 2
!! wikitext
;t1
::d2
!! html+tidy
<dl><dt>t1</dt>
<dd>
<dl><dd>d2</dd></dl></dd></dl>
!! end


!! test
Definition Lists: Nesting: Test 3
!! wikitext
:;t1
::::d2
!! html+tidy
<dl><dd><dl><dt>t1</dt>
<dd>
<dl><dd><dl><dd>d2</dd></dl></dd></dl></dd></dl></dd></dl>
!! end


!! test
Definition Lists: Nesting: Test 4
!! wikitext
::;t3
:::d3
!! html
<dl><dd><dl><dd><dl><dt>t3</dt>
<dd>d3</dd></dl></dd></dl></dd></dl>
!! end


## The Parsoid team believes the following three test exposes a
## bug in the PHP parser.  (Parsoid team thinks the PHP parser is
## wrong to close the <dl> after the <dt> containing the <ul>.)
## It also exposes a "misfeature" in tidy, which doesn't like
## <dl> tags with a single <dt> child; it converts the <dt> into
## a <dd> in that case.  (Parsoid leaves the <dt> alone!)
!! test
Definition Lists: Mixed Lists: Test 1
!! wikitext
:;*foo
::*bar
:;baz
!! html/php+untidy
<dl><dd><dl><dt><ul><li>foo</li>
<li>bar</li></ul></dt></dl>
<dl><dt>baz</dt></dl></dd></dl>
!! html/php+tidy
<dl><dd><dl><dt><ul><li>foo</li>
<li>bar</li></ul></dt></dl>
<dl><dt>baz</dt></dl></dd></dl>
!! html/parsoid
<dl>
<dd><dl>
<dt><ul>
<li>foo
</li>
</ul></dt>
<dd><ul>
<li>bar
</li>
</ul></dd>
<dt>baz</dt>
</dl></dd>
</dl>
!! end

!! test
Definition Lists: Mixed Lists: Test 2
!! wikitext
*:d1
*:d2
!! html
<ul><li><dl><dd>d1</dd>
<dd>d2</dd></dl></li></ul>
!! end


!! test
Definition Lists: Mixed Lists: Test 3
!! wikitext
*:::d1
*:::d2
!! html
<ul><li><dl><dd><dl><dd><dl><dd>d1</dd>
<dd>d2</dd></dl></dd></dl></dd></dl></li></ul>
!! end


!! test
Definition Lists: Mixed Lists: Test 4
!! options
parsoid=wt2html,html2html
!! wikitext
*;d1 :d2
*;d3 :d4
!! html
<ul><li><dl><dt>d1</dt>
<dd>d2</dd>
<dt>d3</dt>
<dd>d4</dd></dl></li></ul>
!! end


!! test
Definition Lists: Mixed Lists: Test 5
!! wikitext
*:d1
*::d2
!! html
<ul><li><dl><dd>d1
<dl><dd>d2</dd></dl></dd></dl></li></ul>
!! end


!! test
Definition Lists: Mixed Lists: Test 6
!! wikitext
#*:d1
#*:::d3
!! html
<ol><li><ul><li><dl><dd>d1
<dl><dd><dl><dd>d3</dd></dl></dd></dl></dd></dl></li></ul></li></ol>
!! end


!! test
Definition Lists: Mixed Lists: Test 7
!! wikitext
:*d1
:*d2
!! html
<dl><dd><ul><li>d1</li>
<li>d2</li></ul></dd></dl>
!! end


!! test
Definition Lists: Mixed Lists: Test 8
!! wikitext
:*d1
::*d2
!! html
<dl><dd><ul><li>d1</li></ul>
<dl><dd><ul><li>d2</li></ul></dd></dl></dd></dl>
!! end


!! test
Definition Lists: Mixed Lists: Test 9
!! options
parsoid=wt2html,html2html
!! wikitext
*;foo :bar
!! html
<ul><li><dl><dt>foo</dt>
<dd>bar</dd></dl></li></ul>
!! end


!! test
Definition Lists: Mixed Lists: Test 10
!! options
parsoid=wt2html,html2html
!! wikitext
*#;foo :bar
!! html
<ul><li><ol><li><dl><dt>foo</dt>
<dd>bar</dd></dl></li></ol></li></ul>
!! end

# The Parsoid team disagrees with the PHP parser's seemingly-random
# rules regarding dd/dt on the next few tests.  Parsoid is more
# consistent, and recognizes the shared nesting and keeps the
# still-open tags around until the nesting is complete.

# This is a regression test for T175099
!! test
Definition Lists: Mixed Lists: Test 11
!! wikitext
;a
:*b
!! html/php
<dl><dt>a</dt>
<dd>
<ul><li>b</li></ul></dd></dl>
!! html/parsoid
<dl><dt>a
<dd><ul><li>b</li></ul></dd></dl>
!! end

# FIXME: Maybe get rid of this test?
!! test
Definition Lists: Mixed Lists: Test 12
!! options
parsoid=wt2html,html2html
!! wikitext
*#*#;*;;foo :bar
*#*#;boo :baz
!! html/php+untidy
<ul><li><ol><li><ul><li><ol><li><dl><dt>foo</dt>
<dd><ul><li><dl><dt><dl><dt>bar</dt></dl></dd></dl></li></ul></dd></dl>
<dl><dt>boo</dt>
<dd>baz</dd></dl></li></ol></li></ul></li></ol></li></ul>
!! html/php+tidy
<ul><li><ol><li><ul><li><ol><li><dl><dt>foo</dt>
<dd><ul><li><dl><dt><dl><dt>bar</dt></dl></dt></dl></li></ul></dd></dl></li></ol></li></ul>
<dl><dt>boo</dt>
<dd>baz</dd></dl></li></ol></li></ul>
!! html/parsoid
<ul>
<li>
<ol>
<li>
<ul>
<li>
<ol>
<li>
<dl>
<dt>
<ul>
<li>
<dl>
<dt>
<dl>
<dt>foo</dt>
<dd data-parsoid='{"stx":"row"}'>bar</dd>
</dl></dt>
</dl></li>
</ul></dt>
<dt>boo</dt>
<dd data-parsoid='{"stx":"row"}'>baz</dd>
</dl></li>
</ol></li>
</ul></li>
</ol></li>
</ul>
!! end

!! test
Definition Lists: Mixed Lists: Test 13
!! options
parsoid=wt2html,html2html
!! wikitext
*#*#;*;;foo : bar
*#*#;boo : baz
!! html+tidy
<ul><li><ol><li><ul><li><ol><li><dl><dt>foo</dt>
<dd><ul><li><dl><dt><dl><dt>bar</dt></dl></dt></dl></li></ul></dd></dl></li></ol></li></ul>
<dl><dt>boo</dt>
<dd>baz</dd></dl></li></ol></li></ul>
!! end

# FIXME: Maybe get rid of this test?
# From an old description in the Parsoid codebase:
# * The test is wrong, there are two colons where there should be :;
# * The PHP parser is wrong to close the <dl> after the <dt> containing the <ul>.
!! test
Definition Lists: Weird Ones: Test 1
!! options
parsoid=wt2html,html2html
!! wikitext
*#;*::;;foo :bar (who uses this?)
!! html/php+tidy
<ul><li><ol><li><dl><dt>foo</dt>
<dd><ul><li><dl><dd><dl><dd><dl><dt><dl><dt>bar (who uses this?)</dt></dl></dt></dl></dd></dl></dd></dl></li></ul></dd></dl></li></ol></li></ul>
!! html/parsoid
<ul>
<li>
<ol>
<li>
<dl>
<dt>
<ul>
<li>
<dl>
<dd>
<dl>
<dd>
<dl>
<dt>
<dl>
<dt>foo</dt>
<dd data-parsoid='{"stx":"row"}'>bar (who uses this?)</dd>
</dl></dt>
</dl></dd>
</dl></dd>
</dl></li>
</ul></dt>
</dl></li>
</ol></li>
</ul>
!! end

!! test
Definition Lists: colons occurring in tags
!! wikitext
;a:b
;'''a:b'''
;<i>a:b</i>
;<span>a:b</span>
;<div>a:b</div>
;<div>a
:b</div>
;{{1x|a:b}}
;{{1x|''a:b''}}
;;;''a:b''
!! html+tidy
<dl><dt>a</dt>
<dd>b</dd>
<dt><b>a:b</b></dt>
<dt><i>a:b</i></dt>
<dt><span>a:b</span></dt>
<dt><div>a:b</div></dt>
<dt><div>a</div></dt>
<dd>b</dd>
<dt>a</dt>
<dd>b</dd>
<dt><i>a:b</i></dt></dl>
<dl><dt><dl><dt><dl><dt><i>a:b</i></dt></dl></dt></dl></dt></dl>
!! html/parsoid
<dl><dt>a</dt><dd data-parsoid='{"stx":"row"}'>b</dd>
<dt><b>a:b</b></dt>
<dt><i data-parsoid='{"stx":"html"}'>a:b</i></dt>
<dt><span data-parsoid='{"stx":"html"}'>a:b</span></dt>
<dt><div data-parsoid='{"stx":"html"}'>a:b</div></dt>
<dt><div data-parsoid='{"stx":"html","autoInsertedEnd":true}'>a</div></dt>
<dd>b<meta typeof="mw:Placeholder/StrippedTag" data-parsoid='{"src":"&lt;/div>","name":"div"}'/></dd>
<dt><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a:b"}},"i":0}}]}'>a:b</span></dt>
<dt><i about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&#39;&#39;a:b&#39;&#39;"}},"i":0}}]}'>a:b</i>
<dl><dt><dl><dt><i>a:b</i></dt></dl></dt></dl></dt></dl>
!! end

# Parsoid's output differs here again because it shares
# nesting between the two lists unlike the PHP parser.
# Unsure which is more desirable.
!! test
Definition Lists: colons and tables 1
!! wikitext
:{|
|x
|}
:{|
|y
|}
!! html/php
<dl><dd><table>
<tbody><tr>
<td>x
</td></tr></tbody></table></dd></dl>
<dl><dd><table>
<tbody><tr>
<td>y
</td></tr></tbody></table></dd></dl>
!! html/parsoid
<dl><dd><table>
<tr>
<td>x
</td></tr></table></dd>
<dd><table>
<tr>
<td>y
</td></tr></table></dd></dl>
!! end

# FIXME: Does this need a html/php section?
!! test
Definition Lists: template interaction
!! wikitext
::{{definition_list}}

:one
::{{definition_list}}
:::two
:::three
::four
!! html/parsoid
<dl><dd><dl data-parsoid='{}'><dd about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[":",{"template":{"target":{"wt":"definition_list","href":"./Template:Definition_list"},"params":{},"i":0}}]}'>one</dd><span about="#mwt1">
</span><dd about="#mwt1">two</dd></dl></dd></dl>

<dl><dd data-parsoid='{}'>one
<dl><dd about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":["::",{"template":{"target":{"wt":"definition_list","href":"./Template:Definition_list"},"params":{},"i":0}},"\n:::two\n:::three"]}'>one</dd><span about="#mwt2">
</span><dd about="#mwt2">two
<dl><dd>two</dd>
<dd>three</dd></dl></dd>
<dd data-parsoid='{}'>four</dd></dl></dd></dl>
!! end


###
### External links
###
!! test
External links: non-bracketed
!! wikitext
Non-bracketed: http://example.com
!! html
<p>Non-bracketed: <a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
</p>
!! end

# parsoid doesn't explicitly mark autonumbered links, see T55505
!! test
External links: numbered
!! wikitext
Numbered: [http://example.com]
Numbered: [http://example.net]
Numbered: [http://example.com]
!! html/php
<p>Numbered: <a rel="nofollow" class="external autonumber" href="http://example.com">[1]</a>
Numbered: <a rel="nofollow" class="external autonumber" href="http://example.net">[2]</a>
Numbered: <a rel="nofollow" class="external autonumber" href="http://example.com">[3]</a>
</p>
!! html/parsoid
<p>Numbered: <a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a>
Numbered: <a rel="mw:ExtLink" href="http://example.net" class="external autonumber"></a>
Numbered: <a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a></p>
!!end

!! test
External links: specified text
!! wikitext
Specified text: [http://example.com link]
!! html
<p>Specified text: <a rel="nofollow" class="external text" href="http://example.com">link</a>
</p>
!!end

!! test
External links: trail
!! wikitext
Linktrails should not work for external links: [http://example.com link]s
!! html
<p>Linktrails should not work for external links: <a rel="nofollow" class="external text" href="http://example.com">link</a>s
</p>
!! end

!! test
External links: dollar sign in URL
!! wikitext
http://example.com/1$2345
!! html
<p><a rel="nofollow" class="external free" href="http://example.com/1$2345">http://example.com/1$2345</a>
</p>
!! end

# parsoid doesn't explicitly mark autonumbered links, see T55505
!! test
External links: dollar sign in URL (autonumber)
!! wikitext
[http://example.com/1$2345]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://example.com/1$2345">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/1$2345" class="external autonumber"></a></p>
!!end

!! test
External links: open square bracket forbidden in URL (T6377)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
http://example.com/1[2345
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com/1">http://example.com/1</a>[2345
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/1" class="external free">http://example.com/1</a>[2345</p>
!! end

!! test
External links: open square bracket forbidden in URL (named) (T6377)
!! options
parsoid=wt2html,html2html
!! wikitext
[http://example.com/1[2345]
!! html/php
<p><a rel="nofollow" class="external text" href="http://example.com/1">[2345</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/1" class="external text">[2345</a></p>
!!end

# parsoid adds a space before the link name
!! test
External links: open square bracket forbidden in URL (named) (T6377)
Parsoid variant.
!! wikitext
[http://example.com/1 [2345]
!! html
<p><a rel="nofollow" class="external text" href="http://example.com/1">[2345</a>
</p>
!!end

!! test
External links: nowiki in URL link text (T8230)
!! wikitext
[http://example.com/ <nowiki>''example site''</nowiki>]
!! html
<p><a rel="nofollow" class="external text" href="http://example.com/">''example site''</a>
</p>
!! end

!! test
External links: newline forbidden in text (T8230 regression check)
!! wikitext
[http://example.com/ first
second]
!! html
<p>[<a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a> first
second]
</p>
!!end

!! test
External links: Pipe char between url and text
!! wikitext
[http://example.com | link]
!! html
<p><a rel="nofollow" class="external text" href="http://example.com">| link</a>
</p>
!!end

!! test
External links: protocol-relative URL in brackets
!! wikitext
[//example.com/ Test]
!! html
<p><a rel="nofollow" class="external text" href="//example.com/">Test</a>
</p>
!! end

# parsoid doesn't explicitly mark autonumbered links, see T55505
!! test
External links: protocol-relative URL in brackets without text
!! wikitext
[//example.com]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="//example.com">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="//example.com" class="external autonumber"></a></p>
!! end

!! test
External links: protocol-relative URL in free text is left alone
!! wikitext
//example.com/Foo
!! html
<p>//example.com/Foo
</p>
!!end

!! test
External links: protocol-relative URL in the middle of a word is left alone (T32269)
!! wikitext
foo//example.com/Foo
!! html
<p>foo//example.com/Foo
</p>
!! end

## html2wt and html2html will fail because we will prefer the :en: interwiki prefix over wikipedia:
!! test
External links: with no contents
!! options
parsoid=wt2html,wt2wt
!! wikitext
[http://en.wikipedia.org/wiki/Foo]

[[wikipedia:Foo|Bar]]

[[wikipedia:Foo|<span>Bar</span>]]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://en.wikipedia.org/wiki/Foo">[1]</a>
</p><p><a href="http://en.wikipedia.org/wiki/Foo" class="extiw" title="wikipedia:Foo">Bar</a>
</p><p><a href="http://en.wikipedia.org/wiki/Foo" class="extiw" title="wikipedia:Foo"><span>Bar</span></a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/Foo" class="external autonumber"></a></p>
<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo" title="wikipedia:Foo">Bar</a></p>
<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo" title="wikipedia:Foo"><span>Bar</span></a></p>
!! end

!! test
External links: Free with trailing punctuation
!! wikitext
http://example.com,
http://example.com;
http://example.com\
http://example.com.
http://example.com:
http://example.com!
http://example.com?
http://example.com)
http://example.com/url_with_(brackets)
(http://example.com/url_without_brackets)
http://example.com/url_with_entity&amp;
http://example.com/url_with_entity&#x26;
http://example.com/url_with_entity&#038;
http://example.com/url_with_entity&nbsp;
http://example.com/url_with_entity&#xA0;
http://example.com/url_with_entity&#160;
http://example.com/url_with_entity&lt;
http://example.com/url_with_entity&#x3C;
http://example.com/url_with_entity&#60;
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>,
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>;
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>\
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>.
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>:
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>!
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>?
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>)
<a rel="nofollow" class="external free" href="http://example.com/url_with_(brackets)">http://example.com/url_with_(brackets)</a>
(<a rel="nofollow" class="external free" href="http://example.com/url_without_brackets">http://example.com/url_without_brackets</a>)
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity&amp;">http://example.com/url_with_entity&amp;</a>
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity&amp;">http://example.com/url_with_entity&amp;</a>
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity&amp;">http://example.com/url_with_entity&amp;</a>
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a>&#160;
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a>&#xa0;
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a>&#160;
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a>&lt;
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a>&#x3c;
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a>&#60;
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>,
<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>;
<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>\
<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>.
<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>:
<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>!
<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>?
<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>)
<a rel="mw:ExtLink" href="http://example.com/url_with_(brackets)" class="external free">http://example.com/url_with_(brackets)</a>
(<a rel="mw:ExtLink" href="http://example.com/url_without_brackets" class="external free">http://example.com/url_without_brackets</a>)
<a rel="mw:ExtLink" href="http://example.com/url_with_entity&amp;" class="external free">http://example.com/url_with_entity&amp;</a>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity&amp;" class="external free">http://example.com/url_with_entity&amp;</a>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity&amp;" class="external free">http://example.com/url_with_entity&amp;</a>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;lt;","srcContent":"&lt;"}'>&lt;</span>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#x3C;","srcContent":"&lt;"}'>&lt;</span>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity" class="external free">http://example.com/url_with_entity</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#60;","srcContent":"&lt;"}'>&lt;</span></p>
!! end

!! test
External links: tricky Parsoid html2html case
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
http://example.com/url_with_entity&amp;amp;
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com/url_with_entity&amp;amp">http://example.com/url_with_entity&amp;amp</a>;
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/url_with_entity&amp;amp" class="external free">http://example.com/url_with_entity&amp;amp</a>;</p>
!! end

!! test
External links: Free with trailing quotes (T113666)
!! wikitext
'''News:''' Stuff here

news:'a'b''c''d e
!! html/php
<p><b>News:</b> Stuff here
</p><p><a rel="nofollow" class="external free" href="news:&#39;a&#39;b">news:'a'b</a><i>c</i>d e
</p>
!! html/parsoid
<p><b>News:</b> Stuff here</p>
<p><a rel="mw:ExtLink" href="news:'a'b" class="external free">news:'a'b</a><i>c</i>d e</p>
!! end

!! test
External links: with entity
!! wikitext
[http://&#x20;www.librarieswithoutborders.org Libraries without borders]
!! html/php
<p><a rel="nofollow" class="external text" href="http://+www.librarieswithoutborders.org">Libraries without borders</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://+www.librarieswithoutborders.org" class="external text" data-parsoid='{"a":{"href":"http://+www.librarieswithoutborders.org"},"sa":{"href":"http://&amp;#x20;www.librarieswithoutborders.org"}}'>Libraries without borders</a></p>
!! end

!! test
External links: Lone protocols are never linked (T105697)
!! wikitext
http://
http://;
(http://)
bitcoin:
bitcoin:;
(bitcoin:)
!! html
<p>http://
http://;
(http://)
bitcoin:
bitcoin:;
(bitcoin:)
</p>
!! end

!! test
External links: No preceding word characters allowed (T67278)
!! wikitext
NOPEhttp://example.com
N0http://example.com
ok:http://example.com
ok-http://example.com
!! html
<p>NOPEhttp://example.com
N0http://example.com
ok:<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
ok-<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
</p>
!! end

!! test
External links: nofollow domain exception
!! wikitext
A [https://no-nofollow.org/foobar link], and another [https://example.org link].
!! html
<p>A <a class="external text" href="https://no-nofollow.org/foobar">link</a>, and another <a rel="nofollow" class="external text" href="https://example.org">link</a>.
</p>
!!end

!! test
External image
!! wikitext
External image: http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png
!! html
<p>External image: <img src="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png" />
</p>
!! end

!! test
External image from https
!! wikitext
External image from https: https://meta.wikimedia.org/upload/f/f1/Ncwikicol.png
!! html
<p>External image from https: <img src="https://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png" />
</p>
!! end

!! test
External image (when not allowed)
!! options
wgAllowExternalImages=0
!! wikitext
External image: http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png
!! html
<p>External image: <a rel="nofollow" class="external free" href="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png">http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png</a>
</p>
!! end

!! test
Link to non-http image, no img tag
!! wikitext
Link to non-http image, no img tag: ftp://example.com/test.jpg
!! html
<p>Link to non-http image, no img tag: <a rel="nofollow" class="external free" href="ftp://example.com/test.jpg">ftp://example.com/test.jpg</a>
</p>
!! end

!! test
External links: terminating separator
!! wikitext
Terminating separator: http://example.com/thing,
!! html
<p>Terminating separator: <a rel="nofollow" class="external free" href="http://example.com/thing">http://example.com/thing</a>,
</p>
!! end

!! test
External links: intervening separator
!! wikitext
Intervening separator: http://example.com/1,2,3
!! html
<p>Intervening separator: <a rel="nofollow" class="external free" href="http://example.com/1,2,3">http://example.com/1,2,3</a>
</p>
!! end

!! test
External links: old bug with URL in query
!! wikitext
Old bug with URL in query: [http://example.com/thing?url=http://example.com link]
!! html
<p>Old bug with URL in query: <a rel="nofollow" class="external text" href="http://example.com/thing?url=http://example.com">link</a>
</p>
!! end

!! test
External links: old URL-in-URL bug, mixed protocols
!! wikitext
And again with mixed protocols: [ftp://example.com?url=http://example.com link]
!! html
<p>And again with mixed protocols: <a rel="nofollow" class="external text" href="ftp://example.com?url=http://example.com">link</a>
</p>
!!end

# Since Parsoid is starting to emit canonical wikitext for links,
# [http://example.com http://example.com] will not RT back to that
# form anymore.
!! test
External links: URL in text
!! options
parsoid=wt2html
!! wikitext
URL in text: [http://example.com http://example.com]
!! html/php
<p>URL in text: <a rel="nofollow" class="external text" href="http://example.com">http://example.com</a>
</p>
!! html/parsoid
<p>URL in text: <a rel="mw:ExtLink" href="http://example.com" class="external text">http://example.com</a></p>
!! end

!! test
External links: Clickable images
!! wikitext
ja-style clickable images: [http://example.com http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png]
!! html/php
<p>ja-style clickable images: <a rel="nofollow" class="external text" href="http://example.com"><img src="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png" /></a>
</p>
!! html/parsoid
<p>ja-style clickable images: <a rel="mw:ExtLink" href="http://example.com" class="external text"><img src="http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png" alt="Ncwikicol.png" data-parsoid='{"type":"extlink"}'/></a></p>
!! end

!! test
External links: raw ampersand
!! wikitext
Old &amp; use: http://x&y
!! html
<p>Old &amp; use: <a rel="nofollow" class="external free" href="http://x&amp;y">http://x&amp;y</a>
</p>
!! end

!! test
External links: encoded ampersand
!! wikitext
Old &amp; use: http://x&amp;y
!! html/php
<p>Old &amp; use: <a rel="nofollow" class="external free" href="http://x&amp;y">http://x&amp;y</a>
</p>
!! html/parsoid
<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" href="http://x&amp;y" class="external free">http://x&amp;y</a></p>
!! end

!! test
External links: encoded equals (T8102)
!! wikitext
http://example.com/?foo&#61;bar
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com/?foo=bar">http://example.com/?foo=bar</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/?foo=bar" class="external free">http://example.com/?foo=bar</a></p>
!! end

##
## Note that parsoid doesn't explicit mark autonumbered links, nor
## does it number them.  As discussed in T55505, we can identify
## autonumbered links via CSS.
##

!! test
External links: [raw ampersand]
!! wikitext
Old &amp; use: [http://x&y]
!! html/php
<p>Old &amp; use: <a rel="nofollow" class="external autonumber" href="http://x&amp;y">[1]</a>
</p>
!! html/parsoid
<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" href="http://x&amp;y" class="external autonumber"></a></p>
!! end

# note that parsoid html is identical to [raw ampersand] case; so html2wt
# mode will return the [raw ampersand] wikitext
!! test
External links: [encoded ampersand]
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
Old &amp; use: [http://x&amp;y]
!! html/php
<p>Old &amp; use: <a rel="nofollow" class="external autonumber" href="http://x&amp;y">[1]</a>
</p>
!! html/parsoid
<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" href="http://x&amp;y" class="external autonumber"></a></p>
!! end

!! test
External links: [raw equals]
!! wikitext
[http://example.com/?foo=bar]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://example.com/?foo=bar">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/?foo=bar" class="external autonumber"></a></p>
!! end

# note that parsoid html is identical to [raw equals] case; so html2wt
# mode will return the [raw equals] wikitext
!! test
External links: [encoded equals] (T8102)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[http://example.com/?foo&#61;bar]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://example.com/?foo=bar">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/?foo=bar" class="external autonumber"></a></p>
!! end

# xxx parsoid strips the IDN character, so the round-trip tests will
#     obviously fail and are disabled. --cscott
!! test
External links: [IDN ignored character reference in hostname; strip it right off]
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[http://e&zwnj;xample.com/]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://example.com/">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/" class="external autonumber"></a></p>
!! end

# FIXME: This test (the IDN characters in the text of a link) is an inconsistency.
# Where an external link could easily circumvent the sanitization of the text of
# a link like this (where an IDN-ignore character is in the URL somewhere), this
# test demands a higher standard. That's a bit strange.
#
# Example:
#
# http://e‌xample.com -> [http://example.com|http://example.com]
# [http://example.com|http://e‌xample.com] -> [http://example.com|http://e‌xample.com]
#
# The first example is sanitized, but the second is not. Any security benefits
# from this production are trivial to circumvent. Either remove this test and
# let the parser(s) do their thing unaccosted, or fix the inconsistency and change
# the test accordingly.
#
# All our love,
# The Parsoid team.
# xxx parsoid strips the IDN character, so the round-trip tests will
#     obviously fail and are disabled. --cscott
!! test
External links: IDN ignored character reference in hostname; strip it right off
!! options
parsoid=wt2html,html2html
!! wikitext
http://e&zwnj;xample.com/
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/" class="external free">http://example.com/</a></p>
!! end

!! test
External links: www.jpeg.org (T2554)
!! wikitext
http://www.jpeg.org
!! html
<p><a rel="nofollow" class="external free" href="http://www.jpeg.org">http://www.jpeg.org</a>
</p>
!! end

# parsoid doesn't explicitly mark autonumbered links, see T55505
!! test
External links: URL within URL (T2002)
!! wikitext
[http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.unausa.org/newindex.asp?place=http://www.unausa.org/programs/mun.asp" class="external autonumber"></a></p>
!! end

!! test
T2361: URL inside bracketed URL
!! wikitext
[http://www.example.com/foo http://www.example.com/bar]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.com/foo">http://www.example.com/bar</a>
</p>
!! end

!! test
T2361: URL within URL, not bracketed
!! wikitext
http://www.example.com/foo?=http://www.example.com/bar
!! html
<p><a rel="nofollow" class="external free" href="http://www.example.com/foo?=http://www.example.com/bar">http://www.example.com/foo?=http://www.example.com/bar</a>
</p>
!! end

!! test
T2289: ">"-token in URL-tail
!! wikitext
http://www.example.com/<hello>
!! html
<p><a rel="nofollow" class="external free" href="http://www.example.com/">http://www.example.com/</a>&lt;hello&gt;
</p>
!!end

!! test
T2289: literal ">"-token in URL-tail
!! wikitext
http://www.example.com/<b>html</b>
!! html/php
<p><a rel="nofollow" class="external free" href="http://www.example.com/">http://www.example.com/</a><b>html</b>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/" class="external free" data-parsoid='{"stx":"url"}'>http://www.example.com/</a><b data-parsoid='{"stx":"html"}'>html</b></p>
!! end

!! test
T2289: ">"-token in bracketed URL
!! wikitext
[http://www.example.com/<hello> stuff]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.com/">&lt;hello&gt; stuff</a>
</p>
!!end

!! test
T2289: literal ">"-token in bracketed URL
!! wikitext
[http://www.example.com/<b>html</b> stuff]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.com/"><b>html</b> stuff</a>
</p>
!!end

!! test
T2289: literal double quote at end of URL
!! wikitext
http://www.example.com/"hello"
!! html
<p><a rel="nofollow" class="external free" href="http://www.example.com/">http://www.example.com/</a>"hello"
</p>
!!end

!! test
T2289: literal double quote in bracketed URL
!! wikitext
[http://www.example.com/"hello" stuff]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.com/">"hello" stuff</a>
</p>
!!end

!! test
External links: multiple legal whitespace is fine, Magnus. Don't break it please. (T7081)
!! wikitext
[http://www.example.com  test]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.com">test</a>
</p>
!! end

!! test
External links: link text with spaces
!! wikitext
[http://www.example.com a b c]
[http://www.example.com ''a'' ''b'']
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.com">a b c</a>
<a rel="nofollow" class="external text" href="http://www.example.com"><i>a</i> <i>b</i></a>
</p>
!! end

# Note edge case difference between PHP and Parsoid here.
!! test
External links: wiki links within external link (T5695)
!! options
parsoid=wt2html,html2html
!! wikitext
[http://example.com [[wikilink]] embedded in ext link]

[http://example.com test [[wikilink]] embedded in ext link]
!! html/php
<p><a rel="nofollow" class="external text" href="http://example.com"></a><a href="/index.php?title=Wikilink&amp;action=edit&amp;redlink=1" class="new" title="Wikilink (page does not exist)">wikilink</a> embedded in ext link
</p><p><a rel="nofollow" class="external text" href="http://example.com">test </a><a href="/index.php?title=Wikilink&amp;action=edit&amp;redlink=1" class="new" title="Wikilink (page does not exist)">wikilink</a> embedded in ext link
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a><a rel="mw:WikiLink" href="./Wikilink" title="Wikilink" class="new">wikilink</a><span> embedded in ext link</span></p>
<p><a rel="mw:ExtLink" href="http://example.com" class="external text">test </a><a rel="mw:WikiLink" href="./Wikilink" title="Wikilink" class="new">wikilink</a><span> embedded in ext link</span></p>
!! end

!! test
T2787: Links with one slash after the url protocol are invalid
!! wikitext
http:/example.com

[http:/example.com title]
!! html
<p>http:/example.com
</p><p>[http:/example.com title]
</p>
!! end

!! test
Bracketed external links with template-generated invalid target
!! wikitext
[{{1x|http:/example.com}} title]
!! html
<p>[http:/example.com title]
</p>
!! end

# wt2html only because Parsoid would want to add <nowiki>s coming from html
!! test
Broken wikilinks (but not external links) prevent templates from closing
!! options
parsoid=wt2html
!! wikitext
[http://example.com x

{{1x|[http://example.com x}}

[[Foo

{{1x|[[Foo}}
!! html/php
<p>[<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a> x
</p><p>[<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a> x
</p><p>[[Foo
</p><p>{{1x|[[Foo}}
</p>
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a> x</p>
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[http://example.com x"}},"i":0}}]}'>[</span><a about="#mwt1" rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a><span about="#mwt1"> x</span></p>
<p>[[Foo</p>
<p>{{1x|[[Foo}}</p>
!! end

!! test
Wikilinks with embedded newlines are not broken
!! wikitext
{{1x|[[ Foo
B
C]]}}
!! html/php
<p>[[ Foo
B
C]]
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[ Foo\nB\nC]]"}},"i":0}}]}'>[[ Foo B C]]</span></p>
!! end

!! test
Broken templates
!! options
parsoid=wt2html
!! wikitext
{{1x|[[Foo|}}]]

[[Foo|{{1x|]]}}
!! html/php
<p>{{1x|<a href="/wiki/Foo" title="Foo">}}</a>
</p><p>[[Foo|]]
</p>
!! html/parsoid
<p>{{1x|<a rel="mw:WikiLink" href="./Foo" title="Foo">}}</a></p>
<p>[[Foo|<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"]]"}},"i":0}}]}'>]]</span></p>
!! end

!! article
Template:pipe page
!! text
Main|Page
!! endarticle

## FIXME: Parsoid doesn't support this and may never.  See T226523
!! test
Template returning pipe used in wikilink target
!! wikitext
[[{{pipe page}}]]
!! html/php+tidy
<p><a href="/index.php?title=Main&amp;action=edit&amp;redlink=1" class="new" title="Main (page does not exist)">Page</a>
</p>
!! html/parsoid
<p>[[<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"pipe page","href":"./Template:Pipe_page"},"params":{},"i":0}}]}'>Main|Page</span>]]</p>
!! end

# Italic/link nesting is changed in this test, but the rendered result is the
# same. Currently the Parsoid result is actually an improvement over
# the legacy parser output.
!! test
T4702: Mismatched <i>, <b> and <a> tags are invalid
!! wikitext
''[http://example.com text'']
[http://example.com '''text]'''
''Something [http://example.com in italic'']
''Something [http://example.com mixed''''', even bold]'''
'''''Now [http://example.com both''''']
!! html/php
<p><i><a rel="nofollow" class="external text" href="http://example.com">text</a></i>
<a rel="nofollow" class="external text" href="http://example.com"><b>text</b></a>
<i>Something <a rel="nofollow" class="external text" href="http://example.com">in italic</a></i>
<i>Something <a rel="nofollow" class="external text" href="http://example.com">mixed</a></i><a rel="nofollow" class="external text" href="http://example.com"><b>, even bold</b></a>
<i><b>Now <a rel="nofollow" class="external text" href="http://example.com">both</a></b></i>
</p>
!! html/parsoid
<p><i data-parsoid='{"autoInsertedEnd":true}'><a rel="mw:ExtLink" href="http://example.com" class="external text">text<i data-parsoid='{"autoInsertedEnd":true}'></i></a></i>
<a rel="mw:ExtLink" href="http://example.com" class="external text"><b data-parsoid='{"autoInsertedEnd":true}'>text</b></a><b data-parsoid='{"autoInsertedEnd":true}'></b>
<i data-parsoid='{"autoInsertedEnd":true}'>Something <a rel="mw:ExtLink" href="http://example.com" class="external text">in italic<i data-parsoid='{"autoInsertedEnd":true}'></i></a></i>
<i>Something <a rel="mw:ExtLink" href="http://example.com" class="external text">mixed<b data-parsoid='{"autoInsertedEnd":true}'><i data-parsoid='{"autoInsertedEnd":true}'>, even bold</i></b></a>'</i>
<b data-parsoid='{"autoInsertedEnd":true}'><i data-parsoid='{"autoInsertedEnd":true}'>Now <a rel="mw:ExtLink" href="http://example.com" class="external text">both<b data-parsoid='{"autoInsertedEnd":true}'><i data-parsoid='{"autoInsertedEnd":true}'></i></b></a></i></b></p>
!! end


!! test
T6781: %26 in URL
!! wikitext
http://www.example.com/?title=AT%26T
!! html/php
<p><a rel="nofollow" class="external free" href="http://www.example.com/?title=AT%26T">http://www.example.com/?title=AT%26T</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=AT%26T" class="external free">http://www.example.com/?title=AT%26T</a></p>
!! end

# According to https://www.w3.org/TR/2011/WD-html5-20110525/Overview.html#parsing-urls a plain
# % is actually legal in HTML5. Any change in output would need testing though.
!! test
T6781, T7267: %25 in URL
!! wikitext
http://www.example.com/?title=100%25_Bran
!! html/php
<p><a rel="nofollow" class="external free" href="http://www.example.com/?title=100%25_Bran">http://www.example.com/?title=100%25_Bran</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=100%25_Bran" class="external free">http://www.example.com/?title=100%25_Bran</a></p>
!! end

!! test
T6781, T7267: %28, %29 in URL
!! wikitext
http://www.example.com/?title=Ben-Hur_%281959_film%29
!! html/php
<p><a rel="nofollow" class="external free" href="http://www.example.com/?title=Ben-Hur_%281959_film%29">http://www.example.com/?title=Ben-Hur_%281959_film%29</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=Ben-Hur_%281959_film%29" class="external free">http://www.example.com/?title=Ben-Hur_%281959_film%29</a></p>
!! end


!! test
T6781: %26 in autonumber URL
!! wikitext
[http://www.example.com/?title=AT%26T]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://www.example.com/?title=AT%26T">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=AT%26T" class="external autonumber"></a></p>
!! end

!! test
T6781, T7267: %26 in autonumber URL
!! wikitext
[http://www.example.com/?title=100%25_Bran]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://www.example.com/?title=100%25_Bran">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=100%25_Bran" class="external autonumber"></a></p>
!! end

!! test
T6781, T7267: %28, %29 in autonumber URL
!! wikitext
[http://www.example.com/?title=Ben-Hur_%281959_film%29]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://www.example.com/?title=Ben-Hur_%281959_film%29">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=Ben-Hur_%281959_film%29" class="external autonumber"></a></p>
!! end


!! test
T6781: %26 in bracketed URL
!! wikitext
[http://www.example.com/?title=AT%26T link]
!! html/php
<p><a rel="nofollow" class="external text" href="http://www.example.com/?title=AT%26T">link</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=AT%26T" class="external text">link</a></p>
!! end

!! test
T6781, T7267: %25 in bracketed URL
!! wikitext
[http://www.example.com/?title=100%25_Bran link]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.com/?title=100%25_Bran">link</a>
</p>
!! end

!! test
T6781, T7267: %28, %29 in bracketed URL
!! wikitext
[http://www.example.com/?title=Ben-Hur_%281959_film%29 link]
!! html/php
<p><a rel="nofollow" class="external text" href="http://www.example.com/?title=Ben-Hur_%281959_film%29">link</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=Ben-Hur_%281959_film%29" class="external text">link</a></p>
!! end

!! test
External link containing a period in the anchor. (T65947)
!! 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." class="external text">bang</a></p>
<p><a rel="mw:ExtLink" href="//foo.org/bar." class="external text">bang</a></p>
!! end

!! test
External link containing a single quote. (T65947)
!! wikitext
[//foo.org/bar'baz]

[//foo.org/bar'baz bang]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="//foo.org/bar&#39;baz">[1]</a>
</p><p><a rel="nofollow" class="external text" href="//foo.org/bar&#39;baz">bang</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="//foo.org/bar'baz" class="external autonumber"></a></p>
<p><a rel="mw:ExtLink" href="//foo.org/bar'baz" class="external text">bang</a></p>
!! end

!! test
External link containing double-single-quotes in text '' (T6598 sanity check)
!! wikitext
Some [http://example.com/ pretty ''italics'' and stuff]!
!! html
<p>Some <a rel="nofollow" class="external text" href="http://example.com/">pretty <i>italics</i> and stuff</a>!
</p>
!! end

# Note different rendering by Parsoid here compared to the legacy parser.
!! test
External link containing double-single-quotes in text embedded in italics (T6598 sanity check)
!! wikitext
''Some [http://example.com/ pretty ''italics'' and stuff]!''
!! html+untidy
<p><i>Some </i><a rel="nofollow" class="external text" href="http://example.com/"><i>pretty </i>italics<i> and stuff</i></a><i>!</i>
</p>
!! html+tidy
<p><i>Some <a rel="nofollow" class="external text" href="http://example.com/">pretty </a></i><a rel="nofollow" class="external text" href="http://example.com/">italics<i> and stuff</i></a><i>!</i>
</p>
!! html/parsoid
<p><i>Some <a rel="mw:ExtLink" href="http://example.com/" class="external text">pretty <i>italics</i> and stuff</a>!</i></p>
!! end

# Don't add the html/php section since the output is broken and there isn't any reason to spec it
!! test
External link containing double-single-quotes with no space separating the url from text in italics
!! wikitext
[http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm''La muerte de Casagemas'' (1901) en el sitio de [[Museo Picasso (París)|Museo Picasso]].]
!! html/php+tidy
<p><a rel="nofollow" class="external text" href="http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a href="/index.php?title=Museo_Picasso_(Par%C3%ADs)&amp;action=edit&amp;redlink=1" class="new" title="Museo Picasso (París) (page does not exist)">Museo Picasso</a>.
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.musee-picasso.fr/pages/page_id18528_u1l2.htm" class="external text"><i>La muerte de Casagemas</i> (1901) en el sitio de </a><a rel="mw:WikiLink" href="./Museo_Picasso_(París)" title="Museo Picasso (París)" class="new">Museo Picasso</a><span>.</span></p>
!! end

!! test
External link with comments in link text
!! wikitext
[http://www.google.com Google <!-- comment -->]
!! 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" class="external text">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" class="external text">Link</a></p>
!! end

!! test
URL-encoding in URL functions (single parameter)
!! wikitext
{{localurl:Some page|amp=&}}
!! html
<p>/index.php?title=Some_page&amp;amp=&amp;
</p>
!! end

!! test
URL-encoding in URL functions (multiple parameters)
!! wikitext
{{localurl:Some page|q=?&amp=&}}
!! html
<p>/index.php?title=Some_page&amp;q=?&amp;amp=&amp;
</p>
!! end

!! test
Brackets in urls
!! wikitext
http://example.com/index.php?foozoid%5B%5D=bar

http://example.com/index.php?foozoid&#x5B;&#x5D;=bar
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com/index.php?foozoid%5B%5D=bar">http://example.com/index.php?foozoid%5B%5D=bar</a>
</p><p><a rel="nofollow" class="external free" href="http://example.com/index.php?foozoid%5B%5D=bar">http://example.com/index.php?foozoid%5B%5D=bar</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/index.php?foozoid%5B%5D=bar" class="external free">http://example.com/index.php?foozoid%5B%5D=bar</a></p>

<p><a rel="mw:ExtLink" href="http://example.com/index.php?foozoid%5B%5D=bar" class="external free" data-parsoid='{"stx":"url","a":{"href":"http://example.com/index.php?foozoid%5B%5D=bar"},"sa":{"href":"http://example.com/index.php?foozoid&amp;#x5B;&amp;#x5D;=bar"}}'>http://example.com/index.php?foozoid%5B%5D=bar</a></p>
!! end

!! test
IPv6 urls, autolink format (T23261)
!! wikitext
http://[2404:130:0:1000::187:2]/index.php

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>Examples from <a class="external mw-magiclink-rfc" rel="nofollow" href="https://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="https://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" class="external free">http://[2404:130:0:1000::187:2]/index.php</a></p>

<p>Examples from <a href="https://tools.ietf.org/html/rfc2373" rel="mw:ExtLink" class="external mw-magiclink">RFC 2373</a>, section 2.2:</p>
<ul><li><a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/unicast" class="external free">http://[1080::8:800:200C:417A]/unicast</a></li>
<li><a rel="mw:ExtLink" href="http://[FF01::101]/multicast" class="external free">http://[FF01::101]/multicast</a></li>
<li><a rel="mw:ExtLink" href="http://[::1]/loopback" class="external free">http://[::1]/loopback</a></li>
<li><a rel="mw:ExtLink" href="http://[::]/unspecified" class="external free">http://[::]/unspecified</a></li>
<li><a rel="mw:ExtLink" href="http://[::13.1.68.3]/ipv4compat" class="external free">http://[::13.1.68.3]/ipv4compat</a></li>
<li><a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]/ipv4compat" class="external free">http://[::FFFF:129.144.52.38]/ipv4compat</a></li></ul>

<p>Examples from <a href="https://tools.ietf.org/html/rfc2732" rel="mw:ExtLink" class="external mw-magiclink">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" class="external free">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" class="external free">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]" class="external free">http://[3ffe:2a00:100:7031::1]</a></li>
<li><a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/foo" class="external free">http://[1080::8:800:200C:417A]/foo</a></li>
<li><a rel="mw:ExtLink" href="http://[::192.9.5.5]/ipng" class="external free">http://[::192.9.5.5]/ipng</a></li>
<li><a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]:80/index.html" class="external free">http://[::FFFF:129.144.52.38]:80/index.html</a></li>
<li><a rel="mw:ExtLink" href="http://[2010:836B:4179::836B:4179]" class="external free">http://[2010:836B:4179::836B:4179]</a></li></ul>
!! end

# It might make sense to change this behavior; see
# See https://phabricator.wikimedia.org/T238022#5665580
!! test
Unicode text around autolinks
!! wikitext
größhttps://foo.org

größ https://foo.org

아들 고건 사진https://foo.org

💩https://foo.org
!! html/php+tidy
<p>größhttps://foo.org
</p><p>größ <a rel="nofollow" class="external free" href="https://foo.org">https://foo.org</a>
</p><p>아들 고건 사진https://foo.org
</p><p>💩<a rel="nofollow" class="external free" href="https://foo.org">https://foo.org</a>
</p>
!! html/parsoid
<p>größhttps://foo.org</p>

<p>größ <a rel="mw:ExtLink" href="https://foo.org" class="external free" data-parsoid='{"stx":"url"}'>https://foo.org</a></p>

<p>아들 고건 사진https://foo.org</p>

<p>💩<a rel="mw:ExtLink" href="https://foo.org" class="external free" data-parsoid='{"stx":"url"}'>https://foo.org</a></p>
!! 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="https://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="https://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" class="external text">test</a></p>

<p>Examples from <a href="https://tools.ietf.org/html/rfc2373" rel="mw:ExtLink" class="external mw-magiclink">RFC 2373</a>, section 2.2:</p>
<ul><li><a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]" class="external text">unicast</a></li>
<li><a rel="mw:ExtLink" href="http://[FF01::101]" class="external text">multicast</a></li>
<li><a rel="mw:ExtLink" href="http://[::1]/" class="external text">loopback</a></li>
<li><a rel="mw:ExtLink" href="http://[::]" class="external text">unspecified</a></li>
<li><a rel="mw:ExtLink" href="http://[::13.1.68.3]" class="external text">ipv4compat</a></li>
<li><a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]" class="external text">ipv4compat</a></li></ul>

<p>Examples from <a href="https://tools.ietf.org/html/rfc2732" rel="mw:ExtLink" class="external mw-magiclink">RFC 2732</a>, section 2:</p>
<ul><li><a rel="mw:ExtLink" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html" class="external text">1</a></li>
<li><a rel="mw:ExtLink" href="http://[1080:0:0:0:8:800:200C:417A]/index.html" class="external text">2</a></li>
<li><a rel="mw:ExtLink" href="http://[3ffe:2a00:100:7031::1]" class="external text">3</a></li>
<li><a rel="mw:ExtLink" href="http://[1080::8:800:200C:417A]/foo" class="external text">4</a></li>
<li><a rel="mw:ExtLink" href="http://[::192.9.5.5]/ipng" class="external text">5</a></li>
<li><a rel="mw:ExtLink" href="http://[::FFFF:129.144.52.38]:80/index.html" class="external text">6</a></li>
<li><a rel="mw:ExtLink" href="http://[2010:836B:4179::836B:4179]" class="external text">7</a></li></ul>
!! end

!! test
Non-extlinks in brackets
!! wikitext
[foo]
[foo bar]
[foo ''bar'']
[fool's] errand
[fool's errand]
[{{1x|foo}}]
[{{1x|foo}} bar]
[{{1x|foo}} ''bar'']
[{{1x|foo}}l's] errand
[{{1x|foo}}l's errand]
[url={{1x|foo}}]
[url=http://example.com]
[http:// bare protocols don't count]
!! html/php
<p>[foo]
[foo bar]
[foo <i>bar</i>]
[fool's] errand
[fool's errand]
[foo]
[foo bar]
[foo <i>bar</i>]
[fool's] errand
[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 about="#mwt19" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>]
[<span about="#mwt20" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span> bar]
[<span about="#mwt21" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span> <i>bar</i>]
[<span about="#mwt22" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>l's] errand
[<span about="#mwt23" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>l's errand]
[url=<span about="#mwt24" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>]
[url=<a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>]
[http:// bare protocols don't count]</p>
!! end

!! test
Percent encoding in external links
!! wikitext
[https://github.com/search?l=&q=ResourceLoader+%40wikimedia Search]
!! html/php
<p><a rel="nofollow" class="external text" href="https://github.com/search?l=&amp;q=ResourceLoader+%40wikimedia">Search</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="https://github.com/search?l=&amp;q=ResourceLoader+%40wikimedia" class="external text">Search</a></p>
!! end

!! test
Use url link syntax for links where the content is equal the link target
!! wikitext
http://example.com
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a></p>
!! end

!! test
Parenthesis in external links, especially URL links
!! wikitext
http://example.com)

http://example.com/test)

http://example.com/(test)

http://example.com/((test)

(http://example.com/(test))

(http://example.com/(test)))))

http://example.com/a)b

[http://example.com) foo]
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>)
</p><p><a rel="nofollow" class="external free" href="http://example.com/test">http://example.com/test</a>)
</p><p><a rel="nofollow" class="external free" href="http://example.com/(test)">http://example.com/(test)</a>
</p><p><a rel="nofollow" class="external free" href="http://example.com/((test)">http://example.com/((test)</a>
</p><p>(<a rel="nofollow" class="external free" href="http://example.com/(test))">http://example.com/(test))</a>
</p><p>(<a rel="nofollow" class="external free" href="http://example.com/(test)))))">http://example.com/(test)))))</a>
</p><p><a rel="nofollow" class="external free" href="http://example.com/a)b">http://example.com/a)b</a>
</p><p><a rel="nofollow" class="external text" href="http://example.com)">foo</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free">http://example.com</a>)</p>
<p><a rel="mw:ExtLink" href="http://example.com/test" class="external free">http://example.com/test</a>)</p>
<p><a rel="mw:ExtLink" href="http://example.com/(test)" class="external free">http://example.com/(test)</a></p>
<p><a rel="mw:ExtLink" href="http://example.com/((test)" class="external free">http://example.com/((test)</a></p>
<p>(<a rel="mw:ExtLink" href="http://example.com/(test))" class="external free">http://example.com/(test))</a></p>
<p>(<a rel="mw:ExtLink" href="http://example.com/(test)))))" class="external free">http://example.com/(test)))))</a></p>
<p><a rel="mw:ExtLink" href="http://example.com/a)b" class="external free">http://example.com/a)b</a></p>
<p><a rel="mw:ExtLink" href="http://example.com)" class="external text">foo</a></p>
!! end

!! test
Parenthesis in external links, w/ transclusion or comment
!! wikitext
(http://example.com/{{1x|hi}})

(http://example.com<!-- hi -->)
!! html/php
<p>(<a rel="nofollow" class="external free" href="http://example.com/hi">http://example.com/hi</a>)
</p><p>(<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>)
</p>
!! html/parsoid
<p>(<a typeof="mw:ExpandedAttrs" about="#mwt2" rel="mw:ExtLink" href="http://example.com/hi" class="external free" data-parsoid='{"stx":"url","a":{"href":"http://example.com/hi"},"sa":{"href":"http://example.com/{{1x|hi}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"http://example.com/&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"hi\"}},\"i\":0}}]}&#39;>hi&lt;/span>"}]]}'>http://example.com/hi</a>)</p>

<p>(<a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url","a":{"href":"http://example.com"},"sa":{"href":"http://example.com&lt;!-- hi -->"}}'>http://example.com</a>)</p>
!! end

!! test
Serialize <a> tags with invalid link targets as plain text
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! 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>
<a rel="mw:WikiLink" href="[[foo]]">*a [[foo]]</a>
!! wikitext
text
<nowiki>*</nowiki>text
<nowiki>[[foo]]</nowiki>
<nowiki>*</nowiki>a <nowiki>[[foo]]</nowiki>
!! end

!! test
mw:ExtLink -vs- mw:WikiLink (T94723)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"piped","a":{"href":"./Foo"},"sa":{"href":"Foo"}}'>Bar</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">Bar</a>
<a rel="mw:WikiLink" href="http://en.wikipedia.org/wiki/Foo" title="Foo">Bar</a>
<a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/Foo" title="Foo">Bar</a>
<p>
<a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/European_Robin">European Robin</a>
<a rel="mw:WikiLink" href="http://en.wikipedia.org/wiki/European_Robin">European Robin</a>
</p>
!! wikitext
[[Foo|Bar]]
[[Foo|Bar]]
[[:en:Foo|Bar]]
[[:en:Foo|Bar]]

[[:en:European_Robin|European Robin]]
[[:en:European_Robin|European Robin]]
!! end

!! test
mw:ExtLink linking to a interwiki URL can be round-tripped losslessly (T94723)
!! options
parsoid=wt2wt
!! wikitext
[http://en.wikipedia.org/wiki/European_Robin European Robin]
!! html/parsoid
THIS SECTION IS NOT USED (but Parsoid won't run the test without it)
!! end


###
### Quotes
###

!! test
Quotes
!! wikitext
Normal text. '''Bold text.''' Normal text. ''Italic text.''

Normal text. '''''Bold italic text.''''' Normal text.
!! html
<p>Normal text. <b>Bold text.</b> Normal text. <i>Italic text.</i>
</p><p>Normal text. <i><b>Bold italic text.</b></i> Normal text.
</p>
!! end

!! test
Quotes wrapping HTML table
!! wikitext
'''<table><tr><td>hi</td></tr></table>'''
!! html/php+tidy
<b><table><tbody><tr><td>hi</td></tr></tbody></table></b>
!! html/parsoid
<b><table data-parsoid='{"stx":"html"}'><tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'>hi</td></tr></tbody></table></b>
!! end

# Parsoid inserts an empty bold tag pair at the end of the line.
# The wikitext contains just the first half of the bold
# quote pair.
!! test
Unclosed and unmatched quotes
!! wikitext
'''''Bold italic text '''with bold deactivated''' in between.'''''

'''''Bold italic text ''with italic deactivated'' in between.'''''

'''Bold text..

..spanning two paragraphs (should not work).'''

'''Bold tag left open

''Italic tag left open

Normal text.

<!-- Unmatching number of opening, closing tags: -->
'''This year''''s election ''should'' beat '''last year''''s.

''Tom'''s car is bigger than ''Susan'''s.

Plain ''italic'''s plain
!! html/php
<p><i><b>Bold italic text </b>with bold deactivated<b> in between.</b></i>
</p><p><b><i>Bold italic text </i>with italic deactivated<i> in between.</i></b>
</p><p><b>Bold text..</b>
</p><p>..spanning two paragraphs (should not work).<b></b>
</p><p><b>Bold tag left open</b>
</p><p><i>Italic tag left open</i>
</p><p>Normal text.
</p><p><b>This year'</b>s election <i>should</i> beat <b>last year'</b>s.
</p><p><i>Tom<b>s car is bigger than </b></i><b>Susan</b>s.
</p><p>Plain <i>italic'</i>s plain
</p>
!! html/parsoid
<p><i><b>Bold italic text </b>with bold deactivated<b> in between.</b></i>
</p><p><b><i>Bold italic text </i>with italic deactivated<i> in between.</i></b>
</p><p><b>Bold text..</b>
</p><p>..spanning two paragraphs (should not work).<b></b>
</p><p><b>Bold tag left open</b>
</p><p><i>Italic tag left open</i>
</p><p>Normal text.
</p>
<!-- Unmatching number of opening, closing tags: -->
<p><b>This year'</b>s election <i>should</i> beat <b>last year'</b>s.
</p><p><i>Tom<b>s car is bigger than </b></i><b>Susan</b>s.
</p><p>Plain <i>italic'</i>s plain
</p>
!! end

###
### Tables
###
### 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 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+tidy
<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

!! test
A table with no data (take 2)
!! wikitext
{|
|}
!! html/parsoid
<table></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
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

!! 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+tidy
<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><tbody>
<tr>
<td data-parsoid='{"startTagSrc":"| ","attrSepSrc":"|"}'>[<a rel="mw:ExtLink" href="ftp://%7Cx" class="external free" data-parsoid='{"stx":"url","a":{"href":"ftp://%7Cx"},"sa":{"href":"ftp://|x"}}'>ftp://%7Cx</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

!! test
Break on | in element attribute in template
!! options
parsoid=wt2html,html2html
!! wikitext
{{1x|1=<div class="hi|ho">ha</div>}}
!! html/php+untidy
<p>ho"&gt;ha&lt;/div&gt;
</p>
!! html/php+tidy
<p>ho"&gt;ha</p>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"ho\">ha&lt;/div>"}},"i":0}}]}'>ho">ha</p>
!! end

!! test
Break on | in element attribute name in template
!! wikitext
{{1x|<div cla|ss="hiho">ha</div>}}
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"},{"k":"ss","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div cla"},"ss":{"wt":"\"hiho\">ha&lt;/div>"}},"i":0}}]}'>&lt;div cla</span></p>
!! end

!! test
Don't break on | in extension attribute in template
!! wikitext
{{1x|<ref name="hi|ho">ha</ref>}}

<references />
!! html/parsoid
<p><sup about="#mwt2" class="mw-ref reference" id="cite_ref-hi|ho_1-0" rel="dc:references" typeof="mw:Transclusion  mw:Extension/ref" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;ref name=\"hi|ho\">ha&lt;/ref>"}},"i":0}}]}'><a href="./Parser_test#cite_note-hi|ho-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup></p>

<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-hi|ho-1" id="cite_note-hi|ho-1"><a href="./Parser_test#cite_ref-hi|ho_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-hi|ho-1" class="mw-reference-text">ha</span></li></ol>
!! 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

!! test
2. 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
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

## Edge case fix to prevent future regressions
!! test
T107652: <ref>s in templates that also generate table cell attributes should be rendered properly
!! wikitext
{|
|{{table_attribs_7}}
|}
<references />
!! html/parsoid
<table>
<tbody><tr><td style="background:#f9f9f9;" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["|",{"template":{"target":{"wt":"table_attribs_7","href":"./Template:Table_attribs_7"},"params":{},"i":0}}]}'>Foo<sup class="mw-ref reference" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-1"}}'><a href="./Parser_test#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></s></td></tr>
</tbody></table>
<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="./Parser_test#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
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+tidy
<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</td>
<!--c1-->
<!--c2--><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
{{!}}}
!! 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></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+untidy
<table>

a
</table>
!! html/php+tidy


a
<table></table>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>
a</p>
<table>
<tbody><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+untidy
<table>

<ul><li>a</li>
<li>b</li></ul>
</table>
!! html/php+tidy
<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><tr data-parsoid='{"startTagSrc":"|-"}'>

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

!! test
Template generated table cell with attributes
!! wikitext
{|
|-
{{table_attribs_4}} ||a||b
|}
!! html/php+tidy
<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-parsoid='{"pi":[[]]}' 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

!! test
Templated table cell with untemplated attributes: Common use cases
!! wikitext
{|
|-
!class="test"{{table_cell_content}} /* th & td combine */
|-
|class="test"{{table_cell_content}} /* td & td 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">foo /* th &amp; td combine */
</th></tr>
<tr>
<td class="test">foo /* td &amp; td combine */
</td>
<td>
</td>
<td class="test" style="color:red;">foo
</td>
<td>
</td>
<td class="test">foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
<th class="test" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"pi":[[]]}' 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" typeof="mw:Transclusion" about="#mwt2" data-parsoid='{"pi":[[]]}' 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>
<td></td>
<td class="test" style="color:red;" typeof="mw:Transclusion" about="#mwt3" 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>
<td></td>
<td class="test" typeof="mw:Transclusion" about="#mwt4" 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

!! 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: Unsupported Scenarios
!! options
parsoid=wt2html
!! wikitext
{|
|-
|class="foo"{{1x|1= {{!}}bar}}
|-
|class="foo"{{1x|1=&nbsp;{{!}}bar}}
|-
|class="foo"{{1x|1={{!}}title="fail"{{!}}bar}}
|}
!! html/php
<table>

<tbody><tr>
<td class="foo">bar
</td></tr>
<tr>
<td class="foo">bar
</td></tr>
<tr>
<td class="foo">title="fail"|bar
</td></tr></tbody></table>
!! html/parsoid
This test fails each of the three table cell scenarios for different reasons.
For now, we are deliberately not support these use cases in Parsoid unless
required or we find a simpler solution that covers everything uniformly.
!! end

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

{|
|baz
|}<b>quux</b>
!! html+tidy
<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
|}
<nowiki> </nowiki>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+tidy
<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+tidy
<table>


</table>
!! html/parsoid
<table>
<tbody>
<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+tidy
<table>
<tbody><tr><td>foo</td>
</tr>
</tbody></table>
!! end

# T137406: Whitespace in the HTML
!! test
1. Generate correct wikitext for tables with thead/tbody/tfoot
!! options
parsoid=html2wt
!! html/parsoid
<table>
<caption>Test</caption>
<thead>
<tr>
<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+tidy
<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+tidy
<table>
<tbody><tr><td>
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
</td></tr>
</tbody></table>
!! end

###
### Internal links
###
!! test
Plain link, capitalized
!! wikitext
[[Main Page]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p>
!! end

!! test
Plain link, uncapitalized
!! wikitext
[[main Page]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">main Page</a>
</p>
!! end

!! test
Piped link
!! wikitext
[[Main Page|The Main Page]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">The Main Page</a>
</p>
!! end

!! test
Piped link with comment in link text
!! wikitext
[[Main Page|The Main<!--front--> Page]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">The Main Page</a>
</p>
!! end

!! test
Piped link with multiple pipe characters in link text
!! wikitext
[[Main Page||The|Main|Page|]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">|The|Main|Page|</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">|The|Main|Page|</a></p>
!! end

!! test
Piped link with no link text
!! wikitext
[[Thomas Bek (bishop of St David's)|]]
!! html/php
<p>[[Thomas Bek (bishop of St David's)|]]
</p>
!! html/parsoid
<p>[[Thomas Bek (bishop of St David's)|]]</p>
!! end

!! test
Piped link with empty link text
!! wikitext
[[Main Page|<nowiki/>]] - empty nowiki
[[Main Page| ]] - empty space
[[Main Page|&nbsp;]] - empty non breaking space
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page"></a> - empty nowiki
<a href="/wiki/Main_Page" title="Main Page"> </a> - empty space
<a href="/wiki/Main_Page" title="Main Page">&#160;</a> - empty non breaking space
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page"><span typeof="mw:Nowiki"></span></a> - empty nowiki
<a rel="mw:WikiLink" href="./Main_Page" title="Main Page"> </a> - empty space
<a rel="mw:WikiLink" href="./Main_Page" title="Main Page"><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span></a> - empty non breaking space</p>
!! end

!! test
Broken link
!! wikitext
[[Zigzagzogzagzig]]
!! html
<p><a href="/index.php?title=Zigzagzogzagzig&amp;action=edit&amp;redlink=1" class="new" title="Zigzagzogzagzig (page does not exist)">Zigzagzogzagzig</a>
</p>
!! end

# The PHP parser strips the hash fragment for non-existent pages, but
# Parsoid does not. (T227693)
!! test
Broken link with fragment
!! wikitext
[[Zigzagzogzagzig#zug]]
!! html/php
<p><a href="/index.php?title=Zigzagzogzagzig&amp;action=edit&amp;redlink=1" class="new" title="Zigzagzogzagzig (page does not exist)">Zigzagzogzagzig#zug</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Zigzagzogzagzig#zug" title="Zigzagzogzagzig" class="new">Zigzagzogzagzig#zug</a></p>
!! end

!! test
Special page link with fragment
!! wikitext
[[Special:Version#anchor]]
!! html
<p><a href="/wiki/Special:Version#anchor" title="Special:Version">Special:Version#anchor</a>
</p>
!! end

# Parsoid does not strip fragment from red links: T227693
!! test
Nonexistent special page link with fragment
!! wikitext
[[Special:ThisNameWillHopefullyNeverBeUsed#anchor]]
!! html/php
<p><a href="/wiki/Special:ThisNameWillHopefullyNeverBeUsed" class="new" title="Special:ThisNameWillHopefullyNeverBeUsed (page does not exist)">Special:ThisNameWillHopefullyNeverBeUsed#anchor</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Special:ThisNameWillHopefullyNeverBeUsed#anchor" title="Special:ThisNameWillHopefullyNeverBeUsed" class="new">Special:ThisNameWillHopefullyNeverBeUsed#anchor</a></p>
!! end

!! test
Link with prefix
!! wikitext
xxx[[main Page]], xxx[[Main Page]], Xxx[[main Page]] XXX[[main Page]], XXX[[Main Page]]
!! html
<p>xxx<a href="/wiki/Main_Page" title="Main Page">main Page</a>, xxx<a href="/wiki/Main_Page" title="Main Page">Main Page</a>, Xxx<a href="/wiki/Main_Page" title="Main Page">main Page</a> XXX<a href="/wiki/Main_Page" title="Main Page">main Page</a>, XXX<a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p>
!! end

!! test
Link with suffix
!! wikitext
[[Main Page]]xxx, [[Main Page]]XXX, [[Main Page]]!!!
!! html
<p><a href="/wiki/Main_Page" title="Main Page">Main Pagexxx</a>, <a href="/wiki/Main_Page" title="Main Page">Main Page</a>XXX, <a href="/wiki/Main_Page" title="Main Page">Main Page</a>!!!
</p>
!! end

!! article
prefixed article
!! text
Some text
!! endarticle

!! test
T45661: Piped links with identical prefixes
!! wikitext
[[prefixed article|prefixed articles with spaces]]

[[prefixed article|prefixed articlesaoeu]]

[[Main Page|Main Page test]]
!! html
<p><a href="/wiki/Prefixed_article" title="Prefixed article">prefixed articles with spaces</a>
</p><p><a href="/wiki/Prefixed_article" title="Prefixed article">prefixed articlesaoeu</a>
</p><p><a href="/wiki/Main_Page" title="Main Page">Main Page test</a>
</p>
!! end


!! test
Link with HTML entity in suffix / tail
!! wikitext
[[Main Page]]&quot;, [[Main Page]]&#97;
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>&quot;, <a href="/wiki/Main_Page" title="Main Page">Main Page</a>&#97;
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;quot;","srcContent":"\""}'>"</span>, <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#97;","srcContent":"a"}'>a</span></p>
!! end

!! test
Link with 3 brackets
!! wikitext
[[[Main Page]]]
Foo [[[Main Page]]]
!! html
<p>[[[Main Page]]]
Foo [[[Main Page]]]
</p>
!! end

!! test
Link with 4 brackets
!! wikitext
[[[[Main Page]]]]
!! html
<p>[[<a href="/wiki/Main_Page" title="Main Page">Main Page</a>]]
</p>
!! end

!! test
Piped link with 3 brackets
!! wikitext
[[[main page|the main page]]]
!! html
<p>[[[main page|the main page]]]
</p>
!! end

!! test
Piped link with extlink-like text
!! wikitext
[[Main Page|[bar]]]
[[Main Page|This is a [bar]]]
[[Main Page|[bar]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">[bar]</a>
<a href="/wiki/Main_Page" title="Main Page">This is a [bar]</a>
<a href="/wiki/Main_Page" title="Main Page">[bar</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page" data-parsoid='{"stx":"piped"}'>[bar]</a>
<a rel="mw:WikiLink" href="./Main_Page" title="Main Page" data-parsoid='{"stx":"piped"}'>This is a [bar]</a>
<a rel="mw:WikiLink" href="./Main_Page" title="Main Page" data-parsoid='{"stx":"piped"}'>[bar</a></p>
!! end

!! test
Link with multiple pipes
!! wikitext
[[Main Page|The|Main|Page]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">The|Main|Page</a>
</p>
!! end

!! test
Anchor containing a #. (T65430)
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
[[Main Page#And#Link]]
!! html/php
<p><a href="/wiki/Main_Page#And#Link" title="Main Page">Main Page#And#Link</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page#And#Link" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#And#Link"},"sa":{"href":"Main Page#And#Link"}}'>Main Page#And#Link</a></p>
!! end

!! test
Link to namespaces
!! wikitext
[[Talk:Parser testing]], [[Meta:Disclaimers]]
!! html
<p><a href="/index.php?title=Talk:Parser_testing&amp;action=edit&amp;redlink=1" class="new" title="Talk:Parser testing (page does not exist)">Talk:Parser testing</a>, <a href="/index.php?title=Meta:Disclaimers&amp;action=edit&amp;redlink=1" class="new" title="Meta:Disclaimers (page does not exist)">Meta:Disclaimers</a>
</p>
!! end

!! test
Link with space in namespace
!! wikitext
[[User talk:Foo bar]]
!! html
<p><a href="/index.php?title=User_talk:Foo_bar&amp;action=edit&amp;redlink=1" class="new" title="User talk:Foo bar (page does not exist)">User talk:Foo bar</a>
</p>
!! end

!! article
MemoryAlpha:AlphaTest
!! text
This is an article in the MemoryAlpha namespace
(which shadows the memoryalpha interwiki link).
!! endarticle

!! test
Namespace takes precedence over interwiki link (T53680)
!! wikitext
[[MemoryAlpha:AlphaTest]]
!! html
<p><a href="/wiki/MemoryAlpha:AlphaTest" title="MemoryAlpha:AlphaTest">MemoryAlpha:AlphaTest</a>
</p>
!! end

# The previous test doesn't work correctly in html2*, due to not recognizing the
# link as an internal one. This one checks for the correct behavior.
!! test
Link to namespace preferred over interwiki with correct rel attribute
!! options
parsoid=html2wt,html2html
!! html/parsoid
<p><a rel="mw:WikiLink" href="./MemoryAlpha:AlphaTest" title="MemoryAlpha:AlphaTest">MemoryAlpha:AlphaTest</a></p>
!! wikitext
[[MemoryAlpha:AlphaTest]]
!! end

!! test
Piped link to namespace
!! wikitext
[[Meta:Disclaimers|The disclaimers]]
!! html
<p><a href="/index.php?title=Meta:Disclaimers&amp;action=edit&amp;redlink=1" class="new" title="Meta:Disclaimers (page does not exist)">The disclaimers</a>
</p>
!! end

!! test
Link containing }
!! wikitext
[[Usually caused by a typo (oops}]]
!! html
<p>[[Usually caused by a typo (oops}]]
</p>
!! end

!! article
7% Solution
!! text
Just a test of an article title containing a percent.
!! endarticle

!! test
Link containing % (not as a hex sequence)
!! wikitext
[[7% Solution]]
[[7% Solution|7%25 Solution]]
!! html/php
<p><a href="/wiki/7%25_Solution" title="7% Solution">7% Solution</a>
<a href="/wiki/7%25_Solution" title="7% Solution">7%25 Solution</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./7%25_Solution" title="7% Solution">7% Solution</a>
<a rel="mw:WikiLink" href="./7%25_Solution" title="7% Solution">7%25 Solution</a></p>
!! end

# note that the parsoid HTML is identical to the previous test output,
# so the previous test ensures that the html2wt mode will generate the
# "not as a hex sequence" wikitext.
!! test
Link containing % as a single hex sequence interpreted to char
!! options
parsoid=wt2wt,wt2html,html2html
!! wikitext
[[7%25 Solution]]
[[7%25 Solution|7%25 Solution]]
!! html/php
<p><a href="/wiki/7%25_Solution" title="7% Solution">7% Solution</a>
<a href="/wiki/7%25_Solution" title="7% Solution">7%25 Solution</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./7%25_Solution" title="7% Solution">7% Solution</a>
<a rel="mw:WikiLink" href="./7%25_Solution" title="7% Solution">7%25 Solution</a></p>
!!end

!! test
Link containing % as a double hex sequence interpreted to hex sequence
!! wikitext
[[7%2525 Solution]]
!! html
<p>[[7%2525 Solution]]
</p>
!!end

## Example for such a section: == < ==
!! test
Link containing "#<" and "#>" % as a hex sequences- these are valid section anchors
!! options
title=[[Main Page]]
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
[[%23%3c]][[%23%3e]]
!! html/php
<p><a href="#&lt;">#&lt;</a><a href="#&gt;">#&gt;</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page#&lt;" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#&lt;"},"sa":{"href":"%23%3c"}}'>#&lt;</a><a rel="mw:WikiLink" href="./Main_Page#>" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#>"},"sa":{"href":"%23%3e"}}'>#></a></p>
!! end

## Example for such a section: == < ==
!! test
Link containing "#<" and "#>" % as a hex sequences- these are valid section anchors (legacy)
!! config
wgFragmentMode=[ 'legacy' ]
!! wikitext
[[%23%3c]][[%23%3e]]
!! html/php
<p><a href="#.3C">#&lt;</a><a href="#.3E">#&gt;</a>
</p>
!! end

!! test
Link containing "<#" and ">#" as a hex sequences
!! wikitext
[[%3c%23]][[%3e%23]]
!! html
<p>[[%3c%23]][[%3e%23]]
</p>
!! end

!! test
Link containing an equals sign
!! wikitext
[[Special:BookSources/isbn=4-00-026157-6]]
!! html/php
<p><a href="/wiki/Special:BookSources/isbn%3D4-00-026157-6" title="Special:BookSources/isbn=4-00-026157-6">Special:BookSources/isbn=4-00-026157-6</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Special:BookSources/isbn=4-00-026157-6" title="Special:BookSources/isbn=4-00-026157-6">Special:BookSources/isbn=4-00-026157-6</a></p>
!! end

!! article
Foo & bar
!! text
Just a test of an article title containing an ampersand
!! endarticle

!! test
Link containing an ampersand
!! wikitext
[[Foo & bar]]

[[Foo &amp; bar]]

[[Foo &amp;amp; bar]]
!! html/php+tidy
<p><a href="/wiki/Foo_%26_bar" title="Foo &amp; bar">Foo &amp; bar</a>
</p><p><a href="/wiki/Foo_%26_bar" title="Foo &amp; bar">Foo &amp; bar</a>
</p><p>[[Foo &amp;amp; bar]]
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo_&amp;_bar" title="Foo &amp; bar">Foo &amp; bar</a></p>
<p><a rel="mw:WikiLink" href="./Foo_&amp;_bar" title="Foo &amp; bar" data-parsoid='{"stx":"simple","a":{"href":"./Foo_&amp;_bar"},"sa":{"href":"Foo &amp;amp; bar"}}'>Foo &amp; bar</a></p>
<p>[[Foo <span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>amp; bar]]</p>
!! end

!! article
Foo~bar
!! text
Just a test of an article title containing a tilde.
!! endarticle

# note that links containing signatures, like [[Foo~~~~]], are
# massaged by the pre-save transform (PST) and so the tildes are never
# seen by the parser.
!! test
Link containing a tilde
!! wikitext
[[Foo~bar]]
!! html/php
<p><a href="/wiki/Foo~bar" title="Foo~bar">Foo~bar</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo~bar" title="Foo~bar">Foo~bar</a></p>
!! end

!! test
Link containing double-single-quotes '' (T6598)
!! 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&#39;&#39;e paise d&#39;&#39;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" class="new">Lista d''e paise d''o munno</a></p>
!! end

!! test
Link containing double quotes and spaces
!! wikitext
[[Cool "Gator"]]
!! html/php
<p><a href="/index.php?title=Cool_%22Gator%22&amp;action=edit&amp;redlink=1" class="new" title="Cool &quot;Gator&quot; (page does not exist)">Cool "Gator"</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href='./Cool_"Gator"' title='Cool "Gator"' class="new">Cool "Gator"</a></p>
!! end

!! test
Redirect containing double quotes and spaces
!! wikitext
#REDIRECT [[Cool "Gator"]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Cool_%22Gator%22" data-parsoid='{"src":"#REDIRECT ","a":{"href":"./Cool_%22Gator%22"},"sa":{"href":"Cool \"Gator\""}}'/>
!! end

!! test
Link containing double-single-quotes '' in text (T6598 sanity check)
!! wikitext
Some [[Link|pretty ''italics'' and stuff]]!
!! html/php
<p>Some <a href="/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">pretty <i>italics</i> and stuff</a>!
</p>
!! html/parsoid
<p>Some <a rel="mw:WikiLink" href="./Link" title="Link" class="new">pretty <i>italics</i> and stuff</a>!</p>
!! end

!! test
Link containing double-single-quotes '' in text embedded in italics (T6598 sanity check)
!! wikitext
''Some [[Link|pretty ''italics'' and stuff]]!''
!! html
<p><i>Some <a href="/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">pretty <i>italics</i> and stuff</a>!</i>
</p>
!! end

## FIXME: Title part of filename is interpreted in php
!! test
Link with double quotes in title part (literal) and alternate part (interpreted)
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
[[File:Denys_Savchenko_''Pentecoste''.jpg]]

[[''Pentecoste'']]

[[''Pentecoste''|Pentecoste]]

[[''Pentecoste''|''Pentecoste'']]
!! html/php
<p><span class="mw-default-size" typeof="mw:Error mw:Image"><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"><span>File:Denys Savchenko <i>Pentecoste</i>.jpg</span></a></span>
</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="&#39;&#39;Pentecoste&#39;&#39; (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="&#39;&#39;Pentecoste&#39;&#39; (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="&#39;&#39;Pentecoste&#39;&#39; (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":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Denys_Savchenko_''Pentecoste''.jpg"><span resource="./File:Denys_Savchenko_''Pentecoste''.jpg" data-parsoid='{"a":{"resource":"./File:Denys_Savchenko_&apos;&apos;Pentecoste&apos;&apos;.jpg"},"sa":{"resource":"File:Denys_Savchenko_&apos;&apos;Pentecoste&apos;&apos;.jpg"}}'>File:Denys Savchenko ''Pentecoste''.jpg</span></a></span></p>
<p><a rel="mw:WikiLink" href="./''Pentecoste''" title="''Pentecoste''" class="new">''Pentecoste''</a></p>
<p><a rel="mw:WikiLink" href="./''Pentecoste''" title="''Pentecoste''" class="new">Pentecoste</a></p>
<p><a rel="mw:WikiLink" href="./''Pentecoste''" title="''Pentecoste''" class="new"><i>Pentecoste</i></a></p>
!! end

!! test
Plain link to URL
!! wikitext
[[http://www.example.com]]
!! html/php
<p>[<a rel="nofollow" class="external autonumber" href="http://www.example.com">[1]</a>]
</p>
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="http://www.example.com" class="external autonumber"></a>]</p>
!! end

!! test
Plain link to URL with link text
!! wikitext
[[http://www.example.com Link text]]
!! html
<p>[<a rel="nofollow" class="external text" href="http://www.example.com">Link text</a>]
</p>
!! end

!! test
Plain link to URL containing special characters, with link text (see T213950).
!! wikitext
[[http://www.example.com/?q=%7Babc%7D Link text]]
!! html
<p>[<a rel="nofollow" class="external text" href="http://www.example.com/?q=%7Babc%7D">Link text</a>]
</p>
!! end

!! test
Plain link to protocol-relative URL
!! wikitext
[[//www.example.com]]
!! html/php
<p>[<a rel="nofollow" class="external autonumber" href="//www.example.com">[1]</a>]
</p>
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="//www.example.com" class="external autonumber"></a>]</p>
!! end

!! test
Plain link to protocol-relative URL with link text
!! wikitext
[[//www.example.com Link text]]
!! html
<p>[<a rel="nofollow" class="external text" href="//www.example.com">Link text</a>]
</p>
!! end

!! test
Plain link to page with question mark in title
!! wikitext
[[A?b]]

[[A?b|Baz]]
!! html
<p><a href="/wiki/A%3Fb" title="A?b">A?b</a>
</p><p><a href="/wiki/A%3Fb" title="A?b">Baz</a>
</p>
!! end

# I'm fairly sure the expected result here is wrong.
# We want these to be URL links, not pseudo-pages with URLs for titles....
# However the current output is also pretty screwy.
#
# ----
# I'm changing it to match the current output--it arguably makes more
# sense in the light of the test above. Old expected result was:
#<p>Piped link to URL: <a href="/index.php?title=Http://www.example.com&amp;action=edit" class="new">an example URL</a>
#</p>
# But I think this test is bordering on "garbage in, garbage out" anyway.
# -- wtm
!! test
Piped link to URL
!! wikitext
Piped link to URL: [[http://www.example.com|an example URL]]
!! html/php
<p>Piped link to URL: [<a rel="nofollow" class="external text" href="http://www.example.com%7Can">example URL</a>]
</p>
!! html/parsoid
<p>Piped link to URL: [<a rel="mw:ExtLink" href="http://www.example.com%7Can" class="external text" data-parsoid='{"a":{"href":"http://www.example.com%7Can"},"sa":{"href":"http://www.example.com|an"}}'>example URL</a>]</p>
!! end

!! test
Plain link in template argument
!! options
parsoid=wt2html
!! wikitext
{{1x|[http://www.example.com |123]}}

{{1x|[[http://www.example.com |123]]}}

{{1x|[[http://www.example.com |123]}}

{{1x|[http://www.example.com |123]]}}
!! html/php
<p>[<a rel="nofollow" class="external free" href="http://www.example.com">http://www.example.com</a> 
</p><p>[<a rel="nofollow" class="external text" href="http://www.example.com">|123</a>]
</p><p>{{1x|[<a rel="nofollow" class="external text" href="http://www.example.com">|123</a>}}
</p><p>[<a rel="nofollow" class="external free" href="http://www.example.com">http://www.example.com</a> 
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[http://www.example.com "},"2":{"wt":"123]"}},"i":0}}]}'>[</span><a about="#mwt1" rel="mw:ExtLink" href="http://www.example.com" class="external free">http://www.example.com</a><span about="#mwt1"> </span></p>

<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[http://www.example.com |123]]"}},"i":0}}]}'>[</span><a about="#mwt2" rel="mw:ExtLink" href="http://www.example.com" class="external text">|123</a><span about="#mwt2">]</span></p>

<p>{{1x|[<a rel="mw:ExtLink" href="http://www.example.com" class="external text" data-parsoid='{"targetOff":114,"contentOffsets":[114,118]}'>|123</a>}}</p>

<p><span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[http://www.example.com "},"2":{"wt":"123]]"}},"i":0}}]}'>[</span><a about="#mwt3" rel="mw:ExtLink" href="http://www.example.com" class="external free">http://www.example.com</a><span about="#mwt3"> </span></p>
!! end

!! test
T2002: [[page|http://url/]] should link to page, not http://url/
!! wikitext
[[Main Page|http://url/]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">http://url/</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">http://url/</a></p>
!! end

# Parsoid does not mark self-links, by design.
!! test
T2337: Escaped self-links should be bold
!! options
title=[[Bug462]]
!! wikitext
[[Bu&#103;462]] [[Bug462]]
!! html/php+tidy
<p><a class="mw-selflink selflink">Bu&#103;462</a> <a class="mw-selflink selflink">Bug462</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Bug462" title="Bug462" class="new">Bug462</a> <a rel="mw:WikiLink" href="./Bug462" title="Bug462" class="new">Bug462</a></p>
!! end

!! test
Self-link to section should not be bold
!! options
title=[[Main Page]]
!! wikitext
[[Main Page#section]]
!! html
<p><a href="/wiki/Main_Page#section" title="Main Page">Main Page#section</a>
</p>
!! end

!! article
00
!! text
This is 00.
!! endarticle

!!test
Self-link to numeric title
!!options
title=[[0]]
!! wikitext
[[0]]
!! html/php
<p><a class="mw-selflink selflink">0</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./0" title="0" class="new">0</a></p>
!!end

!!test
Link to numeric-equivalent title
!!options
title=[[0]]
!! wikitext
[[00]]
!! html
<p><a href="/wiki/00" title="00">00</a>
</p>
!!end

!! test
<nowiki> inside a link
!! wikitext
[[Main<nowiki> Page</nowiki>]] [[Main Page|the main page <nowiki>[it's not very good]</nowiki>]]
!! html/php+tidy
<p>[[Main Page]] <a href="/wiki/Main_Page" title="Main Page">the main page [it's not very good]</a>
</p>
!! html/parsoid
<p>[[Main<span typeof="mw:Nowiki"> Page</span>]] <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">the main page <span typeof="mw:Nowiki">[it's not very good]</span></a></p>
!! end

## Parsoid doesn't get this right and even fails wt2html because, when doing the
## normalization for comparison, the html serialization / re-parse doesn't
## roundtrip.  This is T49963
!! test
<pre> inside a link
!! wikitext
[[Main<pre> Page</pre>]] [[Main Page|the main page <pre>[it's not very good]</pre>]]
!! html/php+tidy
<p>[[Main</p><pre> Page</pre><p>]] <a href="/wiki/Main_Page" title="Main Page">the main page </a></p><a href="/wiki/Main_Page" title="Main Page"><pre>[it's not very good]</pre></a>
!! html/parsoid
<p>[[Main</p><pre typeof="mw:Extension/pre" about="#mwt4" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":" Page"}}'> Page</pre><p>]] <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">the main page <pre typeof="mw:Extension/pre" about="#mwt6" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"[it&apos;s not very good]"}}'>[it's not very good]</pre></a></p>
!! end

!! test
Non-breaking spaces in title
!! wikitext
[[&nbsp; Main &nbsp; Page &nbsp;]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">&#160; Main &#160; Page &#160;</a>
</p>
!!end

# Add new article for the test below so that it doesn't red-link
!! article
Foo bar baz
!! text
boo
!! endarticle

!! test
Multiple spaces in titles should normalize to a single underscore
!! options
parsoid=wt2html,wt2wt
!! wikitext
[[Foo bar baz|x]]
[[Foo  bar baz|x]]
[[Foo  bar   baz|x]]
!! html/php
<p><a href="/wiki/Foo_bar_baz" title="Foo bar baz">x</a>
<a href="/wiki/Foo_bar_baz" title="Foo bar baz">x</a>
<a href="/wiki/Foo_bar_baz" title="Foo bar baz">x</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo_bar_baz" title="Foo bar baz">x</a>
<a rel="mw:WikiLink" href="./Foo_bar_baz" title="Foo bar baz">x</a>
<a rel="mw:WikiLink" href="./Foo_bar_baz" title="Foo bar baz">x</a>
</p>
!! end

!! test
Internal link with ca linktrail, surrounded by bold apostrophes (T29473 primary issue)
!! options
language=ca
!! wikitext
'''[[Main Page]]'''
!! html
<p><b><a href="/wiki/Main_Page" title="Main Page">Main Page</a></b>
</p>
!! end

!! test
Internal link with ca linktrail, surrounded by italic apostrophes (T29473 primary issue)
!! options
language=ca
!! wikitext
''[[Main Page]]''
!! html
<p><i><a href="/wiki/Main_Page" title="Main Page">Main Page</a></i>
</p>
!! end

!! test
Internal link with en linktrail: no apostrophes (T29473)
!! options
language=en
!! wikitext
[[Something]]'nice
!! html
<p><a href="/index.php?title=Something&amp;action=edit&amp;redlink=1" class="new" title="Something (page does not exist)">Something</a>'nice
</p>
!! end

!! test
Internal link with ca linktrail with apostrophes (T29473)
!! options
language=ca
!! wikitext
[[Something]]'nice
!! html
<p><a href="/index.php?title=Something&amp;action=edit&amp;redlink=1" class="new" title="Something (encara no existeix)">Something'nice</a>
</p>
!! end

!! test
Internal link with kaa linktrail with apostrophes (T29473)
!! options
language=kaa
!! wikitext
[[Something]]'nice
!! html
<p><a href="/index.php?title=Something&amp;action=edit&amp;redlink=1" class="new" title="Something (bet ele jaratılmag&#39;an)">Something'nice</a>
</p>
!! end

!! test
Link with multiple ":" in a subpage-supporting namespace (T65636)
!! wikitext
[[User:Foo/Test/63636:Bar|Test]]
!! html/php
<p><a href="/index.php?title=User:Foo/Test/63636:Bar&amp;action=edit&amp;redlink=1" class="new" title="User:Foo/Test/63636:Bar (page does not exist)">Test</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./User:Foo/Test/63636:Bar" title="User:Foo/Test/63636:Bar" class="new">Test</a></p>
!! end

## Mainly a sanity check for Parsoid
!! test
Handle title parsing for subpages
!! options
title=[[/123123]]
subpage
!! wikitext
123
!! html/php
<p>123
</p>
!! html/parsoid
<p>123</p>
!! end

!! article
User:Test/123
!! text
test 123
!! endarticle

!! test
Link to a subpage from a namespace other than main
!! options
title=[[User:Test]]
subpage
!! wikitext
[[/123]]
!! html/php
<p><a href="/wiki/User:Test/123" title="User:Test/123">/123</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./User:Test/123" title="User:Test/123" data-parsoid='{"stx":"simple","a":{"href":"./User:Test/123"},"sa":{"href":"/123"}}'>/123</a></p>
!! end

!! test
Ensure that transclusion titles are not url-decoded
!! options
subpage title=[[Test]]
parsoid=wt2html
!! wikitext
{{Bar%C3%A9}} {{/Bar%C3%A9}}
!! html/php
<p>{{Bar%C3%A9}} {{/Bar%C3%A9}}
</p>
!! html/parsoid
<p>{{Bar%C3%A9}} {{/Bar%C3%A9}}</p>
!! end

!! test
Purely hash wikilink
!! options
title=[[User:Test/123]]
subpage
!! wikitext
[[#a|b]]
!! html/php
<p><a href="#a">b</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./User:Test/123#a" data-parsoid='{"stx":"piped","a":{"href":"./User:Test/123#a"},"sa":{"href":"#a"}}'>b</a></p>
!! end

!! test
Serialization of purely hash wikilink
!! options
title=[[User:Test/123]]
subpage
parsoid=html2wt
!! html/parsoid
<p><a href="#a">[[</a></p>
!! wikitext
[[#a|<nowiki>[[</nowiki>]]
!! html/php
<p><a href="#a">[[</a>
</p>
!! end

!! test
1. Interaction of linktrail and template encapsulation
!! wikitext
{{1x|[[Foo]]}}l

{{1x|[[Foo]]l}}

{{1x|[[Foo]]l}}s

{{1x|[[Foo]]<span>ls</span>}}

[[{{1x|Foo}}]]l
!! html/php+tidy
<p><a href="/wiki/Foo" title="Foo">Fool</a>
</p><p><a href="/wiki/Foo" title="Foo">Fool</a>
</p><p><a href="/wiki/Foo" title="Foo">Fools</a>
</p><p><a href="/wiki/Foo" title="Foo">Foo</a><span>ls</span>
</p><p><a href="/wiki/Foo" title="Foo">Fool</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo" title="Foo" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"Foo"},"pi":[[{"k":"1"}]],"tail":"l"}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Foo]]"}},"i":0}},"l"]}'>Fool</a></p>

<p><a rel="mw:WikiLink" href="./Foo" title="Foo" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"Foo"},"pi":[[{"k":"1"}]],"tail":"l"}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Foo]]l"}},"i":0}}]}'>Fool</a></p>

<p><a rel="mw:WikiLink" href="./Foo" title="Foo" about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"Foo"},"pi":[[{"k":"1"}]],"tail":"ls"}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Foo]]l"}},"i":0}},"s"]}'>Fools</a></p>

<p><a rel="mw:WikiLink" href="./Foo" title="Foo" about="#mwt4" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"Foo"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Foo]]&lt;span>ls&lt;/span>"}},"i":0}}]}'>Foo</a><span about="#mwt4">ls</span></p>

<p><a typeof="mw:ExpandedAttrs" about="#mwt6" rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"{{1x|Foo}}"},"tail":"l"}' data-mw='{"attribs":[[{"txt":"href"},{"html":"&lt;span about=\"#mwt5\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[85,95,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"Foo\"}},\"i\":0}}]}&apos;>Foo&lt;/span>"}]]}'>Fool</a></p>
!! end

!! test
2. Interaction of linktrail and template encapsulation
!! wikitext
{{1x|Some [[Fool]]}}s
!! html/php+tidy
<p>Some <a href="/index.php?title=Fool&amp;action=edit&amp;redlink=1" class="new" title="Fool (page does not exist)">Fools</a>
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Some [[Fool]]"}},"i":0}},"s"]}' data-parsoid='{"pi":[[{"k":"1"}]]}'>Some </span><a rel="mw:WikiLink" href="./Fool" title="Fool" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Fool"},"sa":{"href":"Fool"},"tail":"s"}' class="new">Fools</a></p>
!! end

!! test
3. Interaction of linktrail and template encapsulation
!! wikitext
{{1x|Some [[Fool]]s are '''bold and foolish'''}}
!! html/php+tidy
<p>Some <a href="/index.php?title=Fool&amp;action=edit&amp;redlink=1" class="new" title="Fool (page does not exist)">Fools</a> are <b>bold and foolish</b>
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Some [[Fool]]s are &#39;&#39;&#39;bold and foolish&#39;&#39;&#39;"}},"i":0}}]}' data-parsoid='{"pi":[[{"k":"1"}]]}'>Some </span><a about="#mwt1" rel="mw:WikiLink" href="./Fool" title="Fool" data-parsoid='{"stx":"simple","a":{"href":"./Fool"},"sa":{"href":"Fool"},"tail":"s"}' class="new">Fools</a><span about="#mwt1"> are </span><b about="#mwt1">bold and foolish</b></p>
!! end

!! article
Söfnuður
!! text
Test.
!! endarticle

!! test
Internal link with is link prefix
!! options
language=is
!! wikitext
Aðrir mótmælenda[[söfnuður|söfnuðir]] og
{{1x|mótmælenda[[söfnuður|söfnuðir]]}}
mótmæ{{1x|lenda[[söfnuður|söfnuðir]]}}
!! html/php
<p>Aðrir <a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">mótmælendasöfnuðir</a> og
<a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">mótmælendasöfnuðir</a>
<a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">mótmælendasöfnuðir</a>
</p>
!! html/parsoid
<p>Aðrir <a rel="mw:WikiLink" href="./Söfnuður" title="Söfnuður" data-parsoid='{"stx":"piped","a":{"href":"./Söfnuður"},"sa":{"href":"söfnuður"},"prefix":"mótmælenda"}'>mótmælendasöfnuðir</a> og
<a rel="mw:WikiLink" href="./Söfnuður" title="Söfnuður" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"piped","a":{"href":"./Söfnuður"},"sa":{"href":"söfnuður"},"prefix":"mótmælenda"}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Snið:1x"},"params":{"1":{"wt":"mótmælenda[[söfnuður|söfnuðir]]"}},"i":0}}]}'>mótmælendasöfnuðir</a>
<a rel="mw:WikiLink" href="./Söfnuður" title="Söfnuður" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"piped","a":{"href":"./Söfnuður"},"sa":{"href":"söfnuður"},"prefix":"mótmælenda"}' data-mw='{"parts":["mótmæ",{"template":{"target":{"wt":"1x","href":"./Snið:1x"},"params":{"1":{"wt":"lenda[[söfnuður|söfnuðir]]"}},"i":0}}]}'>mótmælendasöfnuðir</a></p>
!! end

!! article
Mótmælendatrú
!! text
Test.
!! endarticle

!! test
Internal link with is link trail and link prefix
!! options
language=is
!! wikitext
[[mótmælendatrú|xxx]]ar
[[mótmælendatrú]]ar
mótmælenda[[söfnuður]]
mótmælenda[[söfnuður|söfnuðir]]
mótmælenda[[söfnuður|söfnuðir]]xxx
!! html
<p><a href="/wiki/M%C3%B3tm%C3%A6lendatr%C3%BA" title="Mótmælendatrú">xxxar</a>
<a href="/wiki/M%C3%B3tm%C3%A6lendatr%C3%BA" title="Mótmælendatrú">mótmælendatrúar</a>
<a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">mótmælendasöfnuður</a>
<a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">mótmælendasöfnuðir</a>
<a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">mótmælendasöfnuðirxxx</a>
</p>
!! end

!! test
Parsoid link trail escaping
!! options
parsoid=html2wt,html2html
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Apple" title="Apple">apple</a>s</p>
!! wikitext
[[apple]]<nowiki/>s
!! end

!! test
Parsoid link prefix escaping
!! options
language=is
parsoid=html2wt,html2html
!! 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]]
!! end

!! test
Parsoid link bracket escaping
!! options
parsoid=html2wt,html2html
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Test" title="Test">Test</a></p>
<p>[<a rel="mw:WikiLink" href="./Test" title="Test">Test</a>]</p>
<p>[[<a rel="mw:WikiLink" href="./Test" title="Test">Test</a>]]</p>
<p>[[[<a rel="mw:WikiLink" href="./Test" title="Test">Test</a>]]]</p>
<p>[[[[<a rel="mw:WikiLink" href="./Test" title="Test">Test</a>]]]]</p>
<p>[[[[[<a rel="mw:WikiLink" href="./Test" title="Test">Test</a>]]]]]</p>
!! wikitext
[[Test]]

[<nowiki/>[[Test]]]

[[[[Test]]]]

[[[<nowiki/>[[Test]]]]]

[[[[[[Test]]]]]]

[[[[[<nowiki/>[[Test]]]]]]]
!! end

!! test
Parsoid-centric test: Whitespace in ext- and wiki-links should be preserved
!! wikitext
[[Foo|  bar]]

[[Foo|  ''bar'']]

[http://wp.org   foo]

[http://wp.org   ''foo'']
!! html
<p><a href="/wiki/Foo" title="Foo">  bar</a>
</p><p><a href="/wiki/Foo" title="Foo">  <i>bar</i></a>
</p><p><a rel="nofollow" class="external text" href="http://wp.org">foo</a>
</p><p><a rel="nofollow" class="external text" href="http://wp.org"><i>foo</i></a>
</p>
!! end

!! test
Parsoid: Scoped parsing should handle mixed transclusions and plain text
!! wikitext
[[Foo|{{1x|a}} b {{1x|c}}]]
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo" title="Foo"><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span> b <span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"c"}},"i":0}}]}'>c</span></a></p>
!! end

!! test
Link with angle bracket after anchor
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
[[Foo#<bar>]]
!! html/php
<p><a href="/wiki/Foo#&lt;bar&gt;" title="Foo">Foo#&lt;bar&gt;</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo#&lt;bar>" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo#&lt;bar>"},"sa":{"href":"Foo#&lt;bar>"}}'>Foo#&lt;bar></a></p>
!! end

!! test
Link with angle bracket after anchor (legacy)
!! config
wgFragmentMode=[ 'legacy' ]
!! wikitext
[[Foo#<bar>]]
!! html/php
<p><a href="/wiki/Foo#.3Cbar.3E" title="Foo">Foo#&lt;bar&gt;</a>
</p>
!! end

!! test
Wikilink in wikilink
!! wikitext
[[Hi|[[Ho]]]]
!! html/php
<p>[[Hi|<a href="/index.php?title=Ho&amp;action=edit&amp;redlink=1" class="new" title="Ho (page does not exist)">Ho</a>]]
</p>
!! html/parsoid
<p>[[Hi|<a rel="mw:WikiLink" href="./Ho" title="Ho" data-parsoid='{"stx":"simple","a":{"href":"./Ho"},"sa":{"href":"Ho"}}' class="new">Ho</a>]]</p>
!! end

###
### Interwiki links (see maintenance/interwiki.sql)
###

!! test
Inline interwiki link
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[MeatBall:SoftSecurity]]
!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?SoftSecurity" class="extiw" title="meatball:SoftSecurity">MeatBall:SoftSecurity</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?SoftSecurity" title="meatball:SoftSecurity">MeatBall:SoftSecurity</a></p>
!! end

!! test
Inline interwiki link with empty title (T4372)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[MeatBall:]]
!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl" class="extiw" title="meatball:">MeatBall:</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?" title="meatball:">MeatBall:</a></p>
!! end

## html2wt and html2html will fail because we will prefer the :en: interwiki prefix over wikipedia:
!! test
Interwiki link encoding conversion (T3636)
!! options
parsoid=wt2html,wt2wt
!! wikitext
*[[Wikipedia:ro:Olteni&#0355;a]]
*[[Wikipedia:ro:Olteni&#355;a]]
!! html/php+untidy
<ul><li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteni&#355;a</a></li>
<li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteni&#355;a</a></li></ul>
!! html/php+tidy
<ul><li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteni&#355;a</a></li>
<li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteni&#355;a</a></li></ul>
!! html/parsoid
<ul>
<li><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/ro:Olteniţa" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteniţa</a></li>
<li><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/ro:Olteniţa" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteniţa</a></li>
</ul>
!! end

!! test
Interwiki link with fragment (T4130)
!! wikitext
[[MeatBall:SoftSecurity#foo]]
!! html
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?SoftSecurity#foo" class="extiw" title="meatball:SoftSecurity">MeatBall:SoftSecurity#foo</a>
</p>
!! end

## The interwiki case here continued to be legacy escaped because of the
## default setting of $wgExternalInterwikiFragmentMode
!! test
Link scenarios with escaped fragments
!! options
title=[[Main Page]]
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
[[#Is this great?]]
[[Foo#Is this great?]]
[[meatball:Foo#Is this great?]]
!! html/php
<p><a href="#Is_this_great?">#Is this great?</a>
<a href="/wiki/Foo#Is_this_great?" title="Foo">Foo#Is this great?</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F" class="extiw" title="meatball:Foo">meatball:Foo#Is this great?</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page#Is_this_great?" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#Is_this_great?"},"sa":{"href":"#Is this great?"}}'>#Is this great?</a>
<a rel="mw:WikiLink" href="./Foo#Is_this_great?" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo#Is_this_great?"},"sa":{"href":"Foo#Is this great?"}}'>Foo#Is this great?</a>
<a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F" title="meatball:Foo" data-parsoid='{"stx":"simple","a":{"href":"http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F"},"sa":{"href":"meatball:Foo#Is this great?"},"isIW":true}'>meatball:Foo#Is this great?</a></p>
!! end

!! test
Link scenarios with escaped fragments (legacy)
!! config
wgFragmentMode=[ 'legacy' ]
!! wikitext
[[#Is this great?]]
[[Foo#Is this great?]]
[[meatball:Foo#Is this great?]]
!! html/php
<p><a href="#Is_this_great.3F">#Is this great?</a>
<a href="/wiki/Foo#Is_this_great.3F" title="Foo">Foo#Is this great?</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F" class="extiw" title="meatball:Foo">meatball:Foo#Is this great?</a>
</p>
!! end

# Ideally the wikipedia: prefix here should be proto-relative too
# [CSA]: this is kind of a bogus test, as the PHP parser test doesn't
# define the 'en' prefix, and originally the test used 'wikipedia',
# which isn't a localinterwiki prefix hence the links to the 'en:Foo'
# article.
!! test
Different interwiki prefixes mapping to the same URL
!! wikitext
[[:en:Foo]]

[[:en:Foo|Foo]]

[[wikipedia:Foo]]

[[:wikipedia:Foo|Foo]]

[[wikipedia:en:Foo]]

[[:wikipedia:en:Foo]]

[[  wikiPEdia :Foo]]
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="//en.wikipedia.org/wiki/Foo" data-parsoid='{"stx":"simple","a":{"href":"//en.wikipedia.org/wiki/Foo"},"sa":{"href":":en:Foo"},"isIW":true}' title="en:Foo">en:Foo</a></p>

<p><a rel="mw:WikiLink/Interwiki" href="//en.wikipedia.org/wiki/Foo" data-parsoid='{"stx":"piped","a":{"href":"//en.wikipedia.org/wiki/Foo"},"sa":{"href":":en:Foo"},"isIW":true}' title="en:Foo">Foo</a></p>

<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo" data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":"wikipedia:Foo"},"isIW":true}' title="wikipedia:Foo">wikipedia:Foo</a></p>

<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo" data-parsoid='{"stx":"piped","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":":wikipedia:Foo"},"isIW":true}' title="wikipedia:Foo">Foo</a></p>

<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/en:Foo" data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/en:Foo"},"sa":{"href":"wikipedia:en:Foo"},"isIW":true}' title="wikipedia:en:Foo">wikipedia:en:Foo</a></p>

<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/en:Foo" data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/en:Foo"},"sa":{"href":":wikipedia:en:Foo"},"isIW":true}' title="wikipedia:en:Foo">wikipedia:en:Foo</a></p>

<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo" data-parsoid='{"stx":"simple","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":"  wikiPEdia :Foo"},"isIW":true}' title="wikipedia:Foo">  wikiPEdia :Foo</a></p>
!! end

!! test
Interwiki links that cannot be represented in wiki syntax
!! wikitext
[[meatball:ok]]
[[meatball:ok#foo|ok with fragment]]
[[meatball:ok_as_well?|ok ending with ? mark]]
[http://de.wikipedia.org/wiki/Foo?action=history has query]
[http://de.wikipedia.org/wiki/#foo is just fragment]

!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?ok" class="extiw" title="meatball:ok">meatball:ok</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?ok#foo" class="extiw" title="meatball:ok">ok with fragment</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?ok_as_well%3F" class="extiw" title="meatball:ok as well?">ok ending with&#160;? mark</a>
<a rel="nofollow" class="external text" href="http://de.wikipedia.org/wiki/Foo?action=history">has query</a>
<a rel="nofollow" class="external text" href="http://de.wikipedia.org/wiki/#foo">is just fragment</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?ok" title="meatball:ok">meatball:ok</a>
<a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?ok#foo" title="meatball:ok">ok with fragment</a>
<a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?ok_as_well%3F" title="meatball:ok as well?">ok ending with<span typeof="mw:DisplaySpace"> </span>? mark</a>
<a rel="mw:ExtLink" href="http://de.wikipedia.org/wiki/Foo?action=history" class="external text">has query</a>
<a rel="mw:ExtLink" href="http://de.wikipedia.org/wiki/#foo" class="external text">is just fragment</a></p>
!! end

!! test
Interwiki links: trail
!! wikitext
[[wikipedia:Foo|Ba]]r
!! html/php
<p><a href="http://en.wikipedia.org/wiki/Foo" class="extiw" title="wikipedia:Foo">Bar</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://en.wikipedia.org/wiki/Foo" data-parsoid='{"stx":"piped","a":{"href":"http://en.wikipedia.org/wiki/Foo"},"sa":{"href":"wikipedia:Foo"},"isIW":true,"tail":"r"}' title="wikipedia:Foo">Bar</a></p>
!! end

!! test
Local interwiki link
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[local:Template:Foo]]
!! html/php
<p><a href="/wiki/Template:Foo" title="Template:Foo">local:Template:Foo</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Template:Foo" title="Template:Foo">local:Template:Foo</a></p>
!! end

# Parsoid does not mark self-links, by design.
!! test
Local interwiki link: self-link to current page
!! options
title=[[Main Page]]
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[local:Main Page]]
!! html/php
<p><a class="mw-selflink selflink">local:Main Page</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">local:Main Page</a></p>
!! end

!! test
Local interwiki link: prefix only (T66167)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[local:]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">local:</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">local:</a></p>
!! end

!! test
Local interwiki link: with additional interwiki prefix (T63357)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[local:meatball:Hello]]
!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?Hello" class="extiw" title="meatball:Hello">local:meatball:Hello</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?Hello" title="meatball:Hello">local:meatball:Hello</a></p>
!! end

!! test
Multiple local interwiki link prefixes
!! wikitext
[[local:local:local:local:mi:local:Foo]]
!! options
parsoid=wt2html,wt2wt,html2html
!! html/php
<p><a href="/wiki/Foo" title="Foo">local:local:local:local:mi:local:Foo</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo" title="Foo">local:local:local:local:mi:local:Foo</a></p>
!! end

!! test
Interwiki link with percent encoded target
!! wikitext
[[:es:Nueva Guip%C3%BAzcoa|Nueva Guipúzcoa]]
!! html/php
<p><a href="http://es.wikipedia.org/wiki/Nueva_Guip%C3%BAzcoa" class="extiw" title="es:Nueva Guipúzcoa">Nueva Guipúzcoa</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://es.wikipedia.org/wiki/Nueva%20Guipúzcoa" title="es:Nueva Guipúzcoa" data-parsoid='{"stx":"piped","a":{"href":"http://es.wikipedia.org/wiki/Nueva%20Guipúzcoa"},"sa":{"href":":es:Nueva Guip%C3%BAzcoa"},"isIW":true}'>Nueva Guipúzcoa</a></p>
!! end

###
### Interlanguage links
### Language links (so that searching for '### language' matches..)
###

!! test
Interlanguage link
!! wikitext
Blah blah blah
[[zh:Chinese]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" href="http://zh.wikipedia.org/wiki/Chinese"/>
!! end

## parsoid html2wt will lose the space variations
!! test
Interlanguage link with spacing
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
Blah blah blah
[[   zh  :    Chinese     ]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" href="http://zh.wikipedia.org/wiki/Chinese"/>
!! end

!! test
Double interlanguage link
!! wikitext
Blah blah blah
[[es:Spanish]]
[[zh:Chinese]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Spanish"/>
<link rel="mw:PageProp/Language" href="http://zh.wikipedia.org/wiki/Chinese"/>
!! end

## parsoid html2wt will lose the space variations
!! test
Interlanguage link variations
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
Blah blah blah
[[   es :Spanish]]
[[ ZH :Chinese]]
[[es:Foo_bar]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Spanish" />
<link rel="mw:PageProp/Language" href="http://zh.wikipedia.org/wiki/Chinese" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo_bar" />
!! end

!! test
Escaping of interlanguage links (T129218, T156308)
!! wikitext
Blah blah blah
[[:es:Spanish]]
[[ : zh : Chinese ]]
!! html/php
<p>Blah blah blah
<a href="http://es.wikipedia.org/wiki/Spanish" class="extiw" title="es:Spanish">es:Spanish</a>
<a href="http://zh.wikipedia.org/wiki/Chinese" class="extiw" title="zh:Chinese"> zh&#160;: Chinese </a>
</p>
!! html/parsoid
<p>Blah blah blah
<a rel="mw:WikiLink/Interwiki" href="http://es.wikipedia.org/wiki/Spanish" title="es:Spanish">es:Spanish</a>
<a rel="mw:WikiLink/Interwiki" href="http://zh.wikipedia.org/wiki/Chinese" title="zh:Chinese"> zh<span typeof="mw:DisplaySpace"> </span>: Chinese </a></p>
!! end

!! test
Multiple colons escaping interlanguage links
!! options
parsoid=wt2html
!! wikitext
[[:es:Spanish]]
[[::es:Spanish]]
[[:::es:Spanish]]
!! html/php
<p><a href="http://es.wikipedia.org/wiki/Spanish" class="extiw" title="es:Spanish">es:Spanish</a>
[[::es:Spanish]]
[[:::es:Spanish]]
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://es.wikipedia.org/wiki/Spanish" title="es:Spanish">es:Spanish</a>
[[::es:Spanish]]
[[:::es:Spanish]]</p>
!! end

## parsoid html2wt will normalize the space to _
!! test
Space and question mark encoding in interlanguage links (T95473)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
Blah blah blah
[[es:Foo bar?]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo_bar%3F" />
!! end

!! test
Interlanguage link, with prefix links
!! options
language=ln
!! wikitext
Blah blah blah
[[zh:Chinese]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" href="http://zh.wikipedia.org/wiki/Chinese"/>
!! end

!! test
Double interlanguage link, with prefix links (T10897)
!! options
language=ln
!! wikitext
Blah blah blah
[[es:Spanish]]
[[zh:Chinese]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Spanish"/>
<link rel="mw:PageProp/Language" href="http://zh.wikipedia.org/wiki/Chinese"/>
!! end

!! test
"Extra" interlanguage links (T34189 / gerrit 111390)
!! wikitext
Blah blah blah
[[mul:Article]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" title="Multilingual" href="http://wikisource.org/wiki/Article"/>
!! end

## PHP parser tests script needs an update
## Parsoid html2wt will normalize output to [[:zh:Chinese]]
!! test
Language links render as inline links if $wgInterwikiMagic=false
!! options
wgInterwikiMagic=false
parsoid=wt2html,wt2wt,html2html
!! wikitext
Blah blah blah
[[zh:Chinese]]
!! html/parsoid
<p>Blah blah blah <a rel="mw:WikiLink/Interwiki" href="http://zh.wikipedia.org/wiki/Chinese" title="zh:Chinese">zh:Chinese</a></p>
!! end

## PHP parser tests script needs an update
## Parsoid html2wt will normalize output to [[:zh:Chinese]]
!! test
Language links render as inline links in the Talk namespace
!! options
title=Talk:Foo
parsoid=wt2html,wt2wt,html2html
!! wikitext
Blah blah blah
[[zh:Chinese]]
!! html/parsoid
<p>Blah blah blah <a rel="mw:WikiLink/Interwiki" href="http://zh.wikipedia.org/wiki/Chinese" title="zh:Chinese">zh:Chinese</a></p>
!! end

!! test
Parsoid-specific test: Wikilinks with &nbsp; should RT properly
!! options
language=ln
!! wikitext
[[WW&nbsp;II]]
!! html
<p><a href="/index.php?title=WW_II&amp;action=edit&amp;redlink=1" class="new" title="WW II (lonkásá  ezalí tɛ̂)">WW&#160;II</a>
</p>
!! end

!! test
Parsoid T55221: Wikilinks should be properly entity-escaped
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! 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
He&amp;nbsp;llo [[Foo|He&amp;nbsp;llo]]

He&amp;nbsp;llo He&amp;nbsp;llo
!! html/php
<p>He&amp;nbsp;llo <a href="/wiki/Foo" title="Foo">He&amp;nbsp;llo</a>
</p><p>He&amp;nbsp;llo He&amp;nbsp;llo
</p>
!! end

# html2wt will fail because of title normalization without data-parsoid
!! test
Parsoid: handle constructor well
!! options
parsoid=wt2html,wt2wt
!! wikitext
[[constructor]]

[[constructor:foo]]
!! html/php
<p><a href="/index.php?title=Constructor&amp;action=edit&amp;redlink=1" class="new" title="Constructor (page does not exist)">constructor</a>
</p><p><a href="/index.php?title=Constructor:foo&amp;action=edit&amp;redlink=1" class="new" title="Constructor:foo (page does not exist)">constructor:foo</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Constructor" title="Constructor" data-parsoid='{"stx":"simple","a":{"href":"./Constructor"},"sa":{"href":"constructor"}}' class="new">constructor</a></p>

<p><a rel="mw:WikiLink" href="./Constructor:foo" title="Constructor:foo" data-parsoid='{"stx":"simple","a":{"href":"./Constructor:foo"},"sa":{"href":"constructor:foo"}}' class="new">constructor:foo</a></p>
!! end

!! test
Template parameter named "constructor"
!! wikitext
{{1x|  constructor =  |hi}}
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"constructor","named":true,"spc":["  "," ","","  "]},{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"constructor":{"wt":""},"1":{"wt":"hi"}},"i":0}}]}'>hi</span></p>
!! end

!! article
ko:
!! text
Test.
!! endarticle

# Note that `ko` isn't a known interlanguage prefix
!! test
Parsoid: recognize interlanguage links without a target page
!! options
ill
!! wikitext
[[es:]]

[[ko:]]
!! html/php
es:
!! html/parsoid
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/"/>

<p><a rel="mw:WikiLink" href="./Ko:" title="Ko:">ko:</a></p>
!! end

# Note that `ko` isn't a known interwiki prefix
!! test
Parsoid: recognize interwiki links without a target page
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[:es:]]

[[:ko:]]
!! html/php
<p><a href="http://es.wikipedia.org/wiki/" class="extiw" title="es:">es:</a>
</p><p><a href="/wiki/Ko:" title="Ko:">ko:</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://es.wikipedia.org/wiki/" title="es:">es:</a></p>
<p><a rel="mw:WikiLink" href="./Ko:" title="Ko:">ko:</a></p>
!! end

!! test
Handle interwiki links pointing to the current wiki as plain wiki links (T47209)
!! wikitext
[[mi:Foo]]
!! html/php
<p><a href="/wiki/Foo" title="Foo">mi:Foo</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"mi:Foo"}}'>mi:Foo</a></p>
!! end

!! test
Interlanguage link with preceding local interwiki link (T70085)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
Blah blah blah
[[local:es:Spanish]]
!! html/php
<p>Blah blah blah
<a href="http://es.wikipedia.org/wiki/Spanish" class="extiw" title="es:Spanish">local:es:Spanish</a>
</p>
!! html/parsoid
<p>Blah blah blah
<a rel="mw:WikiLink/Interwiki" href="http://es.wikipedia.org/wiki/Spanish" title="es:Spanish">local:es:Spanish</a></p>
!! end

!! test
Looks like an interlanguage link, but is actually a local interwiki
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
Blah blah blah
[[mi:Template:Foo]]
!! html/php
<p>Blah blah blah
<a href="/wiki/Template:Foo" title="Template:Foo">mi:Template:Foo</a>
</p>
!! html/parsoid
<p>Blah blah blah
<a rel="mw:WikiLink" href="./Template:Foo" title="Template:Foo">mi:Template:Foo</a></p>
!! end

###
### Redirects, Parsoid-only
###

!! test
1. Simple redirect to page
!! wikitext
#REDIRECT [[Main Page]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page"/>
!! end

!! test
2. Other redirect variants
!! wikitext
#REDIRECT [[Main_Page]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page" data-parsoid='{"src":"#REDIRECT ","a":{"href":"./Main_Page"},"sa":{"href":"Main_Page"}}'/>
!! end

# Not a valid redirect in PHP (although perhaps it was, once upon a time)
# This tests the Parsoid bail-out code.
!! test
3. Other redirect variants
!! options
parsoid=wt2html
!! wikitext
#REDIRECT [[<nowiki>[[Bar]]</nowiki>]]
!! html/parsoid
<ol><li>REDIRECT [[<span typeof="mw:Nowiki">[[Bar]]</span>]]</li></ol>
!! end

!! test
4. Redirect to a templated destination
!! wikitext
#REDIRECT [[{{1x|Foo}}bar]]
!! html/parsoid
<link about="#mwt2" typeof="mw:ExpandedAttrs" rel="mw:PageProp/redirect" href="./Foobar" data-parsoid='{"a":{"href":"./Foobar"},"sa":{"href":"{{1x|Foo}}bar"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"Foo\"}},\"i\":0}}]}&#39;>Foo&lt;/span>bar"}]]}'/>
!! end

!! test
Empty redirect
!! options
parsoid=wt2html,wt2wt
!! wikitext
#REDIRECT [[]]
!! html/parsoid
<ol>
<li>REDIRECT [[]]</li></ol>
!! end

!! test
Optional colon in #REDIRECT
!! options
# the colon is archaic syntax.  we support it for wt2html, but we
# don't care that it roundtrips back to the modern syntax.
parsoid=wt2html,html2html
!! wikitext
#REDIRECT:[[Main Page]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page"/>
!! end

!! test
Whitespace in #REDIRECT with optional colon
!! options
# the colon and gratuitous whitespace is archaic syntax.  we support
# it for wt2html, but we don't care that it roundtrips back to the
# modern syntax (without extra whitespace)
parsoid=wt2html,html2html
!! wikitext
 
 #REDIRECT 
: 
[[Main Page]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page"/>
!! end

!! test
Piped link in #REDIRECT
!! options
# content after piped link is ignored.  we support this syntax,
# but don't care that the piped link is lost when we roundtrip this.
parsoid=wt2html
!! wikitext
#REDIRECT [[Main Page|bar]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page"/>
!! end

!! test
Redirect to category (T104502)
!! options
parsoid=wt2html,wt2wt
!! wikitext
#REDIRECT [[Category:Foo]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Category:Foo"/>
!! end

!! test
Redirect to category with URL encoding (T104502)
!! options
parsoid=wt2html
!! wikitext
#REDIRECT [[Category%3AFoo]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Category:Foo"/>
!! end

!! test
Redirect to category page
!! wikitext
#REDIRECT [[:Category:Foo]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Category:Foo"/>
!! end

!! test
Redirect to image page (1)
!! wikitext
#REDIRECT [[File:Wiki.png]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./File:Wiki.png"/>
!! end

!! test
Redirect to image page (2)
!! wikitext
#REDIRECT [[Image:Wiki.png]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./File:Wiki.png"  data-parsoid='{"src":"#REDIRECT ","a":{"href":"./File:Wiki.png"},"sa":{"href":"Image:Wiki.png"}}'/>
!! end

# html2wt disabled because wts serializes as "#REDIRECT [[:en:File:Wiki.png]]"
# Next test confirms this.
!! test
Redirect to language (1) (T104918)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
#REDIRECT [[en:File:Wiki.png]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="//en.wikipedia.org/wiki/File:Wiki.png"/>
!! end

!! test
Redirect to language (2) (T104918)
!! wikitext
#REDIRECT [[:en:File:Wiki.png]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="//en.wikipedia.org/wiki/File:Wiki.png"/>
!! end

!! test
Redirect to interwiki (T104918)
!! wikitext
#REDIRECT [[meatball:File:Wiki.png]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="http://www.usemod.com/cgi-bin/mb.pl?File:Wiki.png"/>
!! end

!! test
Non-English #REDIRECT
!! options
language=is
!! wikitext
#TILVÍSUN [[Main Page]]
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page" data-parsoid='{"src":"#TILVÍSUN ","a":{"href":"./Main_Page"},"sa":{"href":"Main Page"}}'/>
!! end

!! test
Redirect syntax under text isn't considered a redirect
!! wikitext
some text

#redirect [[Main Page]]
!! html/parsoid
<p>some text</p>

<ol data-parsoid='{}'><li data-parsoid='{}'>redirect <a rel="mw:WikiLink" href="./Main_Page" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page"},"sa":{"href":"Main Page"}}'>Main Page</a></li></ol>
!! end

!! test
New redirect
!! options
parsoid=html2wt
!! html/parsoid
<p>Foo<link rel="mw:PageProp/redirect" href="./Foo"/></p>
!! wikitext
#REDIRECT [[Foo]]
Foo
!! end

!! test
Redirect followed by block on the same line
!! options
parsoid=wt2html
!! wikitext
#REDIRECT [[Main Page]]<!-- haha -->==hi==
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page"/><!-- haha --><h2 id="hi">hi</h2>
!! end

!! test
Redirect followed by a newline
!! wikitext
#REDIRECT [[Main Page]]
A newline
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page"/>
<p>A newline</p>
!! end

!! test
Redirect followed by multiple newlines
!! wikitext
#REDIRECT [[Main Page]]


A newline
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Main_Page"/>

<p><br/>
A newline</p>
!! end

!! test
Drop duplicate redirects
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Foo"/>
<link rel="mw:PageProp/redirect" href="./Bar"/>
<link rel="mw:PageProp/redirect" href="./Baz"/>
!! wikitext
#REDIRECT [[Foo]]
!! end

##
## XHTML tidiness
###

!! test
<br> to <br />
!! wikitext
1<br>2<br />3
!! html
<p>1<br />2<br />3
</p>
!! end

!! test
Broken br tag sanitization
!! options
parsoid=wt2html,html2html
!! wikitext
</br>
!! html/php+untidy
<p>&lt;/br&gt;
</p>
!! html/php+tidy
<p><br />
</p>
!! html/parsoid
<p><br data-parsoid='{"stx":"html","noClose":true}'/></p>
!! end

# TODO: Fix html2html mode (T53055)!
!! test
Parsoid: Broken br tag recognition
!! options
parsoid=wt2html
!! wikitext
</br>

<br/ >
!! html+tidy
<p><br />
</p><p><br />
</p>
!! end

!! test
Incorrecly removing closing slashes from correctly formed XHTML
!! wikitext
<br style="clear:both;" />
!! html
<p><br style="clear:both;" />
</p>
!! end

!! test
Failing to transform badly formed HTML into correct XHTML
!! wikitext
<br style="clear: left;">
<br style="clear: right;">
<br style="clear: both;">
!! html
<p><br style="clear: left;" />
<br style="clear: right;" />
<br style="clear: both;" />
</p>
!!end

## Parsoid's behavior w/ self-closing HTML tags is now a bug;
## see T134423.  Legacy Parser now implements proper HTML5 semantics.
!! test
Handling html with a div self-closing tag
!! wikitext
<div title />
<div title/>
<div title/ >
<div title=bar />
<div title=bar/>
<div title=bar/ >
!! html+tidy
<div title="">
<div title="">
<div title="">
<div title="bar">
<div title="bar">
<div title="bar/"></div></div></div></div></div></div>
!! end

!! test
Elements with solidus in various attribute positions
!! options
parsoid=wt2html,html2html
!! wikitext
<div cla/ss="123">ha</div>

<div / class="123">ha</div>

<div class= / "123">ha</div>
!! html/php+tidy
<div>ha</div>
<div class="123">ha</div>
<div class="/">ha</div>
!! html/parsoid
<div data-parsoid='{"stx":"html","a":{"cla":null,"ss":null},"sa":{"cla":"","ss":"123"}}'>ha</div>

<div class="123" data-parsoid='{"stx":"html"}'>ha</div>

<div class="/" data-parsoid='{"stx":"html","a":{"\"123\"":null},"sa":{"\"123\"":""}}'>ha</div>
!! end

!! test
Handling html with a br self-closing tag
!! wikitext
<br title />
<br title/>
<br title/ >
<br title=bar />
<br title=bar/>
<br title=bar/ >
!! html/php+tidy
<p><br title="" />
<br title="" />
<br title="" />
<br title="bar" />
<br title="bar" />
<br title="bar/" />
</p>
!! html/parsoid
<p><br title="" />
<br title="" />
<br title="" />
<br title="bar" />
<br title="bar" />
<br title="bar/" />
</p>
!! end

!! test
Quoted attributes without spaces
!! options
parsoid=wt2html
!! wikitext
<div class="foo"style="color:red">red</div>
!! html/php+tidy
<div class="foo" style="color:red">red</div>
!! html/parsoid
<div class="foo" style="color:red">red</div>
!! end

!! test
Horizontal ruler (should it add that extra space?)
!! wikitext
<hr>
<hr >
foo <hr
> bar
!! html+tidy
<hr />
<hr /><p>
foo </p><hr /><p> bar</p>
!! html/parsoid
<hr data-parsoid='{"stx":"html","noClose":true}'/>
<hr data-parsoid='{"stx":"html","noClose":true}'/><p>
foo </p><hr data-parsoid='{"stx":"html","noClose":true}'/><p> bar</p>
!! end

!! test
Horizontal ruler -- 4+ dashes render hr
!! wikitext
----
!! html
<hr />
!! end

!! test
Horizontal ruler -- eats additional dashes on the same line
!! wikitext
---------
!! html
<hr />
!! end

!! test
Horizontal ruler -- does not collapse dashes on consecutive lines
!! wikitext
----
----
!! html
<hr />
<hr />
!! end

!! test
Horizontal ruler -- <4 dashes render as plain text
!! wikitext
---
!! html
<p>---
</p>
!! end

!! test
Horizontal ruler -- Supports content following dashes on same line
!! wikitext
---- Foo
!! html+untidy
<hr /> Foo
!! html+tidy
<hr /><p> Foo</p>
!! html/parsoid
<hr data-parsoid='{"lineContent":true}'/><p> Foo</p>
!! end

###
### Block-level elements
###
!! test
Common list
!! wikitext
*Common list
*item 2
*item 3
!! html
<ul><li>Common list</li>
<li>item 2</li>
<li>item 3</li></ul>
!! end

!! test
Numbered list
!! wikitext
#Numbered list
#item 2
#item 3
!! html
<ol><li>Numbered list</li>
<li>item 2</li>
<li>item 3</li></ol>
!! end

# the switch from level 3 to ordered should not introduce a newline between
!! test
Mixed list
!! wikitext
*Mixed list
*#with numbers
**and bullets
*#and numbers
*bullets again
**bullet level 2
***bullet level 3
***#Number on level 4
**bullet level 2
**#Number on level 3
**#Number on level 3
*#number level 2
*Level 1
***Level 3
#**Level 3, but ordered
!! html
<ul><li>Mixed list
<ol><li>with numbers</li></ol>
<ul><li>and bullets</li></ul>
<ol><li>and numbers</li></ol></li>
<li>bullets again
<ul><li>bullet level 2
<ul><li>bullet level 3
<ol><li>Number on level 4</li></ol></li></ul></li>
<li>bullet level 2
<ol><li>Number on level 3</li>
<li>Number on level 3</li></ol></li></ul>
<ol><li>number level 2</li></ol></li>
<li>Level 1
<ul><li><ul><li>Level 3</li></ul></li></ul></li></ul>
<ol><li><ul><li><ul><li>Level 3, but ordered</li></ul></li></ul></li></ol>
!! end

!! test
1. Nested mixed wikitext and html list
!! wikitext
*hi
*<ul><li>ho</li></ul>
*hi
**ho
!! html/php
<ul><li>hi</li>
<li><ul><li>ho</li></ul></li>
<li>hi
<ul><li>ho</li></ul></li></ul>
!! html/parsoid
<ul><li>hi</li>
<li><ul data-parsoid='{"stx":"html"}'><li data-parsoid='{"stx":"html"}'>ho</li></ul></li>
<li>hi
<ul><li>ho</li></ul></li></ul>
!! end

!! test
2. Nested mixed wikitext and html list (incompatible)
!! wikitext
;hi
:{{1x|<li>ho</li>}}
!! html/php
<dl><dt>hi</dt>
<dd><li>ho</li></dd></dl>
!! html/parsoid
<dl><dt>hi</dt>
<dd><li about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>ho&lt;/li>"}},"i":0}}]}'>ho</li></dd></dl>
!! end

!! test
Nested lists 1
!! wikitext
*foo
**bar
!! html
<ul><li>foo
<ul><li>bar</li></ul></li></ul>
!! end

!! test
Nested lists 2
!! wikitext
**foo
*bar
!! html
<ul><li><ul><li>foo</li></ul></li>
<li>bar</li></ul>
!! end

!! test
Nested lists 3 (first element empty)
!! wikitext
*
**bar
!! html
<ul><li>
<ul><li>bar</li></ul></li></ul>
!! end

!! test
Nested lists 4 (first element empty)
!! wikitext
**
*bar
!! html
<ul><li><ul><li class="mw-empty-elt"></li></ul></li>
<li>bar</li></ul>
!! end

!! test
Nested lists 5 (both elements empty)
!! wikitext
**
*
!! html
<ul><li><ul><li class="mw-empty-elt"></li></ul></li>
<li class="mw-empty-elt"></li></ul>
!! end

!! test
Nested lists 6 (both elements empty)
!! wikitext
*
**
!! html
<ul><li>
<ul><li class="mw-empty-elt"></li></ul></li></ul>
!! end

!! test
Nested lists 7 (skip initial nesting levels)
!! wikitext
***foo
!! html
<ul><li><ul><li><ul><li>foo</li></ul></li></ul></li></ul>
!! end

!! test
Nested lists 8 (multiple nesting transitions)
!! wikitext
*foo
***bar
**baz
*boo
!! html
<ul><li>foo
<ul><li><ul><li>bar</li></ul></li>
<li>baz</li></ul></li>
<li>boo</li></ul>
!! end

# XXX this test should be moved to citeParserTests, since it depends
# on the Cite extension, which is "built in" to Parsoid.
!! test
Nested lists 9 (extension interaction)
!! wikitext
*<references />
!! html/php+tidy-DISABLED
<ul><li class="mw-empty-elt"></li></ul>
!! html/parsoid
<ul><li data-parsoid='{}'><ol class="mw-references references" typeof="mw:Extension/references" about="#mwt2" data-parsoid='{}' data-mw='{"name":"references","attrs":{}}'></ol></li></ul>
!! end

!! test
Nested lists 10 (list and span siblings: wt2wt regression)
!! wikitext
*a <span>x</span>
**b <span>y</span>
!! html/parsoid
<ul><li>a <span>x</span>
<ul><li>b <span>y</span></li></ul></li></ul>
!! end

!! test
Nested lists 11 (T262409: trailing whitespace & selser)
!! options
parsoid={
  "modes": ["wt2html","selser"],
  "changes": [
    [ "ul > li > ul > li > ul > li", "after", "<li>b-new</li>" ]
  ]
}
!! wikitext
**a
***b  
!! html/parsoid
<ul><li><ul><li>a
<ul><li>b</li></ul></li></ul></li></ul>
!! wikitext/edited
**a
***b  
*** b-new
!! end

!! test
1. Lists and block-element interaction
!! options
parsoid=wt2html,selser
!! wikitext
*<div>a
*b
</div>ಕ
!! html/php+tidy
<ul><li><div>a</div></li>
<li>b</li></ul>
<p>ಕ</p>
!! html/parsoid
<ul><li><div data-parsoid='{"stx":"html","autoInsertedEnd":true}'>a</div></li>
<li>b</li></ul>
<p>ಕ</p>
!! end

!! test
2. Lists and block-element interaction
!! options
parsoid=wt2html,selser
!! wikitext
*{{1x|<div>a
*b
}}</div>ಕ
!! html/php+tidy
<ul><li><div>a</div></li>
<li>b</li></ul>
<p>ಕ</p>
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"firstWikitextNode":"UL","pi":[[{"k":"1"}]]}' data-mw='{"parts":["*",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>a\n*b\n"}},"i":0}}]}'><li><div>a</div></li>
<li>b</li></ul><span about="#mwt1">
</span><p>ಕ</p>
!! end

!! test
1. Lists with start-of-line-transparent tokens before bullets: Comments
!! wikitext
*foo
*<!--cmt-->bar
<!--cmt-->*baz
!! html
<ul><li>foo</li>
<li>bar</li>
<li>baz</li></ul>
!! html/parsoid
<ul><li>foo</li>
<li><!--cmt-->bar</li>
<!--cmt--><li>baz</li></ul>
!! end

# Parsoid handles this case differently from the legacy parser, as a side
# effect of handling SOL state in the tokenizer.
!! test
2. Lists with start-of-line-transparent tokens before bullets: Template close
!! wikitext
*foo {{1x|bar
}}*baz
!! html/php+tidy
<ul><li>foo bar</li>
<li>baz</li></ul>
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"firstWikitextNode":"UL","pi":[[{"k":"1"}]]}' data-mw='{"parts":["*foo ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"bar\n"}},"i":0}}]}'><li>foo bar</li><li about="#mwt1">
baz</li></ul>
!! end

!! test
List items are not parsed correctly following a <pre> block (T2785)
!! wikitext
*<pre>foo</pre>
*<pre>bar</pre>
*zar
!! html/php
<ul><li><pre>foo</pre></li>
<li><pre>bar</pre></li>
<li>zar</li></ul>
!! html/parsoid
<ul><li><pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"foo"}}'>foo</pre></li>
<li><pre typeof="mw:Extension/pre" about="#mwt4" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"bar"}}'>bar</pre></li>
<li>zar</li></ul>
!! end

# FIXME: Might benefit from a html/parsoid since this has a template
!! test
List items from template
!! wikitext

{{inner list}}
*item 2

*item 0
{{inner list}}
*item 2

*item 0
*notSOL{{inner list}}
*item 2
!! html
<ul><li>item 1</li>
<li>item 2</li></ul>
<ul><li>item 0</li>
<li>item 1</li>
<li>item 2</li></ul>
<ul><li>item 0</li>
<li>notSOL</li>
<li>item 1</li>
<li>item 2</li></ul>
!! end

!! test
List interrupted by empty line or heading
!! wikitext
*foo

**bar
==A heading==
*Another list item
!! html
<ul><li>foo</li></ul>
<ul><li><ul><li>bar</li></ul></li></ul>
<h2><span class="mw-headline" id="A_heading">A heading</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: A heading">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<ul><li>Another list item</li></ul>
!!end

!! test
Multiple list tags generated by templates
!! wikitext
{{1x|<li>}}a
{{1x|<li>}}b
{{1x|<li>}}c
!! html+untidy
<li>a
<li>b
<li>c</li>
</li>
</li>

!! html+tidy
<li>a
</li><li>b
</li><li>c</li>
!! html/parsoid
<li about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>"}},"i":0}},"a"]}'>a</li>
<li about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>"}},"i":0}},"b"]}'>b</li>
<li about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>"}},"i":0}},"c"]}'>c</li>
!! end

!! test
Multiple newlines in between HTML list items don't induce paragraph wrapping
!! wikitext
<ul>
<li>hi</li>




<li>ho</li>
</ul>

<dl>
<dt>hi</dt>
<dd>ho<div>123</div>
</dd>


</dl>
!! html/php+tidy
<ul>
<li>hi</li>




<li>ho</li>
</ul>
<dl>
<dt>hi</dt>
<dd>ho<div>123</div>
</dd>


</dl>
!! end

!!test
Single-comment whitespace lines dont break lists, and neither do multi-comment whitespace lines
!! wikitext
*a
<!--This line will NOT split the list-->
*b
 <!--This line will NOT split the list either-->
*c
 <!--foo--> <!----> <!--This line NOT split the list either--> 
*d
!! html
<ul><li>a</li>
<li>b</li>
<li>c</li>
<li>d</li></ul>
!!end

!!test
Replacing whitespace with tabs still doesn't break the list (gerrit 78327)
!! wikitext
*a
<!--This line will NOT split the list-->	
*b
	<!--This line will NOT split the list either--> 	
*c
	<!--foo--> <!---->	<!--This line NOT split the list
        either-->	 
*d
!! html
<ul><li>a</li>
<li>b</li>
<li>c</li>
<li>d</li></ul>
!!end

# FIXME: Parsoid has a dedicated DOM pass to mimic this Tidy-specific li-hack
# That pass could possibly be removed.
!!test
Test the li-hack (a hack from Tidy days, but doesn't work as advertised with Remex)
!!options
parsoid=wt2html,wt2wt
!! wikitext
*foo
*<li>li-hack
**bar1
*{{1x|<li>templated li-hack}}
**bar2
*<!--foo--><li> unsupported li-hack with preceding comments

<ul>
<li><li>not a li-hack
</li>
</ul>
!! html+tidy
<ul><li>foo</li>
<li class="mw-empty-elt"></li><li>li-hack
<ul><li>bar1</li></ul></li>
<li class="mw-empty-elt"></li><li>templated li-hack
<ul><li>bar2</li></ul></li>
<li class="mw-empty-elt"></li><li> unsupported li-hack with preceding comments</li></ul>
<ul>
<li class="mw-empty-elt"></li><li>not a li-hack
</li>
</ul>
!! html/parsoid
<ul><li>foo</li>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true,"liHackSrc":"*"}'>li-hack
<ul><li>bar1</li></ul></li>
<li about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":["*",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>templated li-hack"}},"i":0}},"\n**bar2"]}'>templated li-hack
<ul><li>bar2</li></ul></li>
<li><!--foo--></li><li data-parsoid='{"stx":"html","autoInsertedEnd":true}'> unsupported li-hack with preceding comments</li></ul>

<ul data-parsoid='{"stx":"html"}'>
<li class="mw-empty-elt" data-parsoid='{"stx":"html","autoInsertedEnd":true}'></li><li data-parsoid='{"stx":"html"}'>not a li-hack
</li>
</ul>
!! end

!! test
Parsoid: Make sure nested lists are serialized on their own line even if HTML contains no newlines
!! wikitext
#foo
##bar

*foo
**bar

:foo
::bar
!! html/php+tidy
<ol><li>foo
<ol><li>bar</li></ol></li></ol>
<ul><li>foo
<ul><li>bar</li></ul></li></ul>
<dl><dd>foo
<dl><dd>bar</dd></dl></dd></dl>
!! html/parsoid
<ol>
<li>foo<ol>
<li>bar</li>
</ol></li>
</ol><ul>
<li>foo<ul>
<li>bar</li>
</ul></li>
</ul><dl>
<dd>foo<dl>
<dd>bar</dd>
</dl></dd>
</dl>
!! end

!! test
Parsoid: Test of whitespace serialization with Templated bullets
!! options
parsoid=wt2html
!! wikitext
* {{bullet}}
!! html/parsoid
<ul>
<li class="mw-empty-elt"> </li><li about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bullet","href":"./Template:Bullet"},"params":{},"i":0}}]}'> Bar</li>
</ul>
!! end

# ------------------------------------------------------------------------
# The next set of tests are about Parsoid's ability to handle badly nested
# tags (parse, minimize scope of fixup, and roundtrip back)
# ------------------------------------------------------------------------

!! test
Unbalanced closing block tags break a list
!! wikitext
<div>
*a</div><div>
*b</div>
!! html+tidy
<div>
<ul><li>a</li></ul></div><div>
<li>b</li></div>
!! html/parsoid
<div><ul>
<li>a</li>
</ul></div>
<div><ul>
<li>b</li>
</ul></div>
!! end

## We call this "wikitext block" because we're diverging a bit from the HTML5
## parsing spec.  Remex output is because it doesn't need to generate the
## implied end tag for the list item when encountering the closing </p> but
## Parsoid's broader definition opts to.  This can happen for a number of other
## tags but those aren't allowed literal tags in wikitext.  There's also the
## opposite problem, where the wikitext blocks aren't a superset of the tags
## that generate implied ends in HTML5, but the missing ones again aren't
## allowed literal tags in wikitext.
!! test
Unbalanced closing wikitext block tags break a list
!! wikitext
<p>
*a</p><p>
*b</p>
!! html/php+tidy
<p class="mw-empty-elt">
</p><ul><li>a<p class="mw-empty-elt"></p><p class="mw-empty-elt"></p></li>
<li>b<p class="mw-empty-elt"></p></li></ul>
!! html/parsoid
<p class="mw-empty-elt" data-parsoid='{"stx":"html","autoInsertedEnd":true}'></p>
<ul><li>a</li></ul><p class="mw-empty-elt" data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p><p class="mw-empty-elt" data-parsoid='{"stx":"html","autoInsertedEnd":true}'></p>
<ul><li>b</li></ul><p class="mw-empty-elt" data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p>
!! end

!! test
Unbalanced closing non-block tags don't break a list
!! options
parsoid=wt2html,html2html
!! wikitext
<span>
*a</span><span>
*b</span>
!! html/php+tidy
<p><span>
</span></p>
<ul><li>a<span></span></li>
<li>b</li></ul>
!! html/parsoid
<p><span data-parsoid='{"stx":"html","autoInsertedEnd":true}'></span></p>
<ul><li>a<meta typeof="mw:Placeholder/StrippedTag" data-parsoid='{"src":"&lt;/span>","name":"span"}'/><span data-parsoid='{"stx":"html","autoInsertedEnd":true}'></span></li>
<li>b<meta typeof="mw:Placeholder/StrippedTag" data-parsoid='{"src":"&lt;/span>","name":"span"}'/></li></ul>
!! end

# Parsoid does some post-dom-building cleanup
# which is why its output differs from Remex.
!! test
Unclosed formatting tags that straddle lists are closed and reopened
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
#<s> a
#b </s>
!! html/php+tidy
<ol><li><s> a</s></li><s>
</s><li><s>b </s></li></ol>
!! html/parsoid
<ol><li><s> a</s></li>
<li><s>b </s></li></ol>
!! end

# Output is ugly because of all the misnested tag fixups.
!! test
1. List embedded in a formatting tag
!! wikitext
<small>
*foo
</small>
!! html/php+tidy
<p><small>
</small></p><small><ul><li>foo</li></ul></small><small></small><p><small></small>
</p>
!! html/parsoid
<p><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'></small></p><small data-parsoid='{"stx":"html","autoInsertedEnd":true,"autoInsertedStart":true}'>
<ul><li data-parsoid='{}'>foo</li></ul></small>
<p><small data-parsoid='{"stx":"html","autoInsertedStart":true}'></small></p>
!! end

# Output is ugly because of all the misnested tag fixups.
!! test
2. List embedded in a formatting tag in a misnested way
!! wikitext
<small>
*a
*b</small>
!! html/php+tidy
<p><small>
</small></p><small></small><ul><small><li>a</li>
</small><li><small>b</small></li></ul>
!! html/parsoid
<p><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'></small></p>
<ul><small data-parsoid='{"stx":"html","autoInsertedEnd":true,"autoInsertedStart":true}'><li>a</li></small>
<li><small data-parsoid='{"stx":"html","autoInsertedStart":true}'>b</small></li></ul>
!! end

# Output is ugly because of all the misnested tag fixups.
!! test
3. List embedded in a formatting tag in a misnested way
!! wikitext
<small>

** 123</small>
!! html/php+tidy
<p><small>
</small></p><small></small><ul><small></small><li><small></small><ul><small></small><li><small>123</small></li></ul></li></ul>
!! html/parsoid
<p><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'></small></p>

<ul><li><ul><li data-parsoid='{}'><small data-parsoid='{"stx":"html","autoInsertedStart":true}'> 123</small></li></ul></li></ul>
!! end

###
### Magic Words
###

# Note that the current date is hard-coded as
#   1970-01-01T00:02:03Z (a Thursday)
# when running parser tests.  The timezone is also fixed to GMT, so
# local date will be identical to current date.

!! test
Magic Word: {{CURRENTDAY}}
!! wikitext
{{CURRENTDAY}}
!! html
<p>1
</p>
!! end

!! test
Magic Word: {{CURRENTDAY2}}
!! wikitext
{{CURRENTDAY2}}
!! html
<p>01
</p>
!! end

!! test
Magic Word: {{CURRENTDAYNAME}}
!! wikitext
{{CURRENTDAYNAME}}
!! html
<p>Thursday
</p>
!! end

!! test
Magic Word: {{CURRENTDOW}}
!! wikitext
{{CURRENTDOW}}
!! html
<p>4
</p>
!! end

!! test
Magic Word: {{CURRENTMONTH}}
!! wikitext
{{CURRENTMONTH}}
!! html
<p>01
</p>
!! end

!! test
Magic Word: {{CURRENTMONTH1}}
!! wikitext
{{CURRENTMONTH1}}
!! html
<p>1
</p>
!! end

!! test
Magic Word: {{CURRENTMONTHABBREV}}
!! wikitext
{{CURRENTMONTHABBREV}}
!! html
<p>Jan
</p>
!! end

!! test
Magic Word: {{CURRENTMONTHNAME}}
!! wikitext
{{CURRENTMONTHNAME}}
!! html
<p>January
</p>
!! end

!! test
Magic Word: {{CURRENTMONTHNAMEGEN}}
!! wikitext
{{CURRENTMONTHNAMEGEN}}
!! html
<p>January
</p>
!! end

!! test
Magic Word: {{CURRENTTIME}}
!! wikitext
{{CURRENTTIME}}
!! html
<p>00:02
</p>
!! end

!! test
Magic Word: {{CURRENTHOUR}}
!! wikitext
{{CURRENTHOUR}}
!! html
<p>00
</p>
!! end

!! test
Magic Word: {{CURRENTWEEK}} (T6594)
!! wikitext
{{CURRENTWEEK}}
!! html
<p>1
</p>
!! end

!! test
Magic Word: {{CURRENTYEAR}}
!! wikitext
{{CURRENTYEAR}}
!! html
<p>1970
</p>
!! end

!! test
Magic Word: {{CURRENTTIMESTAMP}}
!! wikitext
{{CURRENTTIMESTAMP}}
!! html
<p>19700101000203
</p>
!! end

!! test
Magic Words LOCAL (UTC)
!! wikitext
*{{LOCALMONTH}}
*{{LOCALMONTH1}}
*{{LOCALMONTHNAME}}
*{{LOCALMONTHNAMEGEN}}
*{{LOCALMONTHABBREV}}
*{{LOCALDAY}}
*{{LOCALDAY2}}
*{{LOCALDAYNAME}}
*{{LOCALYEAR}}
*{{LOCALTIME}}
*{{LOCALHOUR}}
*{{LOCALWEEK}}
*{{LOCALDOW}}
*{{LOCALTIMESTAMP}}
!! html
<ul><li>01</li>
<li>1</li>
<li>January</li>
<li>January</li>
<li>Jan</li>
<li>1</li>
<li>01</li>
<li>Thursday</li>
<li>1970</li>
<li>00:02</li>
<li>00</li>
<li>1</li>
<li>4</li>
<li>19700101000203</li></ul>
!! end

!! test
Magic Word: {{FULLPAGENAME}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{FULLPAGENAME}}
!! html/*
<p>User:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{FULLPAGENAMEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{FULLPAGENAMEE}}
!! html/*
<p>User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{TALKSPACE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKSPACE}}
!! html/*
<p>User talk
</p>
!! end

!! test
Magic Word: {{TALKSPACE}}, same namespace
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKSPACE}}
!! html/*
<p>User talk
</p>
!! end

!! test
Magic Word: {{TALKSPACE}}, main namespace
!! options
title=[[Parser Test]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKSPACE}}
!! html/*
<p>Talk
</p>
!! end

!! test
Magic Word: {{TALKSPACEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKSPACEE}}
!! html/*
<p>User_talk
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTSPACE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}, same namespace
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTSPACE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}, main namespace
!! options
title=[[Parser Test]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTSPACE}}
!! html/*
!! end

!! test
Magic Word: {{SUBJECTSPACEE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTSPACEE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{NAMESPACE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{NAMESPACEE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACENUMBER}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{NAMESPACENUMBER}}
!! html/*
<p>2
</p>
!! end

!! test
Magic Word: {{SUBPAGENAME}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub ö]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBPAGENAME}}
!! html/*
<p>sub ö
</p>
!! end

!! test
Magic Word: {{SUBPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub ö]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBPAGENAMEE}}
!! html/*
<p>sub_%C3%B6
</p>
!! end

!! test
Magic Word: {{ROOTPAGENAME}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub/sub2]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{ROOTPAGENAME}}
!! html/*
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{ROOTPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub/sub2]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{ROOTPAGENAMEE}}
!! html/*
<p>%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{BASEPAGENAME}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{BASEPAGENAME}}
!! html/*
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{BASEPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{BASEPAGENAMEE}}
!! html/*
<p>%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{TALKPAGENAME}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKPAGENAME}}
!! html/*
<p>User talk:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{TALKPAGENAMEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKPAGENAMEE}}
!! html/*
<p>User_talk:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{SUBJECTPAGENAME}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTPAGENAME}}
!! html/*
<p>User:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{SUBJECTPAGENAMEE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTPAGENAMEE}}
!! html/*
<p>User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{NUMBEROFFILES}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{NUMBEROFFILES}}
!! html/*
<p>7
</p>
!! end

!! test
Magic Word: {{PAGENAME}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGENAME}}
!! html/*
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{PAGENAME}} with metacharacters
!! options
title=[['foo & bar = baz']]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
''{{PAGENAME}}''
!! html+tidy
<p><i>&#39;foo &#38; bar &#61; baz&#39;</i>
</p>
!! end

!! test
Magic Word: {{PAGENAME}} with metacharacters (T28781)
!! options
title=[[*RFC 1234 http://example.com/]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGENAME}}
!! html+tidy
<p>&#42;RFC&#32;1234 http&#58;//example.com/
</p>
!! end

!! test
Magic Word: {{PAGENAMEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGENAMEE}}
!! html/*
<p>%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{PAGENAMEE}} with metacharacters (T28781)
!! options
title=[[*RFC 1234 http://example.com/]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGENAMEE}}
!! html+tidy
<p>&#42;RFC_1234_http&#58;//example.com/
</p>
!! end

!! test
Magic Word: {{REVISIONID}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONID}}
!! html/*
<p>1337
</p>
flags=vary-revision-id
!! end

!! test
Magic Word: {{REVISIONID}} on non-latest revision
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONID}}
!! html/*
<p>1337
</p>
flags=vary-revision-id
!! end

!! test
Magic Word: {{REVISIONTIMESTAMP}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONTIMESTAMP}}
!! html/*
<p>19700101000203
</p>
flags=
!! end

!! test
Magic Word: {{REVISIONTIMESTAMP}} on non-existing page
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONTIMESTAMP}}
!! html/*
<p>123
</p>
flags=vary-revision-timestamp
!! end

!! test
Magic Word: {{REVISIONUSER}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONUSER}}
!! html/*
<p>127.0.0.1
</p>
flags=vary-user
!! end

!! test
Parser Function: {{REVISIONID:{{PAGENAME}}}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONID:{{PAGENAME}}}}
!! html/*
<p>1337
</p>
flags=vary-revision-id
!! end

!! test
Parser Function: {{REVISIONID:{{PAGENAME}}}} on non-saved revision
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONID:{{PAGENAME}}}}
!! html/*

flags=vary-revision-id
!! end

!! test
Parser Function: {{REVISIONTIMESTAMP:{{PAGENAME}}}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONTIMESTAMP:{{PAGENAME}}}}
!! html/*
<p>19700101000203
</p>
flags=vary-revision-timestamp
!! end

!! test
Parser Function: {{REVISIONDAY:{{PAGENAME}}}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONDAY:{{PAGENAME}}}}
!! html/*
<p>1
</p>
flags=vary-revision-timestamp
!! end

!! test
Parser Function: {{REVISIONMONTH:{{PAGENAME}}}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONMONTH:{{PAGENAME}}}}
!! html/*
<p>01
</p>
flags=vary-revision-timestamp
!! end

!! test
Parser Function: {{REVISIONYEAR:{{PAGENAME}}}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{REVISIONYEAR:{{PAGENAME}}}}
!! html/*
<p>1970
</p>
flags=vary-revision-timestamp
!! end

!! test
Parser Function: {{PAGESIZE:{{PAGENAME}}}} on latest revision
!! options
lastsavedrevision
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
showflags
!! wikitext
{{PAGESIZE:{{PAGENAME}}}}
!! html/*
<p>25
</p>
flags=vary-revision-sha1
!! end

!! test
Magic Word: {{SCRIPTPATH}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SCRIPTPATH}}
!! html/*
!! end

!! test
Magic Word: {{STYLEPATH}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{STYLEPATH}}
!! html/*
<p>/skins
</p>
!! end

!! test
Magic Word: {{SERVER}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SERVER}}
!! html/*
<p><a rel="nofollow" class="external free" href="http://example.org">http://example.org</a>
</p>
!! end

!! test
Magic Word: {{SERVERNAME}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SERVERNAME}}
!! html/*
<p>example.org
</p>
!! end

!! test
Magic Word: {{SITENAME}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SITENAME}}
!! html/*
<p>MediaWiki
</p>
!! end

!! test
Magic Word: {{PAGELANGUAGE}}
!! options
language=fr
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGELANGUAGE}}
!! html/*
<p>fr
</p>
!! end

!! test
Magic Word: {{PAGELANGUAGE}} on a page with no explicitly set language
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGELANGUAGE}}
!! html/*
<p>en
</p>
!! end

!! test
Case-sensitive magic words, when cased differently, should just be template transclusions
!! wikitext
{{CurrentMonth}}
{{currentday}}
{{cURreNTweEK}}
{{currentHour}}
!! html
<p><a href="/index.php?title=Template:CurrentMonth&amp;action=edit&amp;redlink=1" class="new" title="Template:CurrentMonth (page does not exist)">Template:CurrentMonth</a>
<a href="/index.php?title=Template:Currentday&amp;action=edit&amp;redlink=1" class="new" title="Template:Currentday (page does not exist)">Template:Currentday</a>
<a href="/index.php?title=Template:CURreNTweEK&amp;action=edit&amp;redlink=1" class="new" title="Template:CURreNTweEK (page does not exist)">Template:CURreNTweEK</a>
<a href="/index.php?title=Template:CurrentHour&amp;action=edit&amp;redlink=1" class="new" title="Template:CurrentHour (page does not exist)">Template:CurrentHour</a>
</p>
!! end

!! test
Case-insensitive magic words should still work with weird casing.
!! wikitext
{{sErVeRNaMe}}
{{LCFirst:AOEU}}
{{ucFIRST:aoeu}}
{{SERver}}
!! html
<p>example.org
aOEU
Aoeu
<a rel="nofollow" class="external free" href="http://example.org">http://example.org</a>
</p>
!! end

# From plwiki:PLOS_ONE
!! test
Parsoid: Page property magic word with magic word contents
!! options
showtitle
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! wikitext
{{DISPLAYTITLE:''{{PAGENAME}}''}}
!! html/php+tidy
<i>Parser test</i>

!! html/parsoid
<meta property="mw:PageProp/displaytitle" content="Parser test" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"src":"{{DISPLAYTITLE:&#39;&#39;{{PAGENAME}}&#39;&#39;}}"}' data-mw='{"attribs":[[{"txt":"content"},{"html":"DISPLAYTITLE:&lt;i data-parsoid=&#39;{\"dsr\":[15,31,2,2]}&#39;>&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[17,29,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"PAGENAME\",\"function\":\"pagename\"},\"params\":{},\"i\":0}}]}&#39;>Parser test&lt;/span>&lt;/i>"}]]}'/>
!! end

# NOTE: mw:ExpandedAttrs is not the best typeof here. mw:Transclusion is better.
# But, this is a limitation of our representation and is documented in
# TemplateHandler.js in processSpecialMagicWord
!! test
Parsoid: Template-generated DISPLAYTITLE
!! wikitext
{{{{1x|DISPLAYTITLE}}:Foo}}
!! options
showtitle
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! html/php
Foo

!! html/parsoid
<meta property="mw:PageProp/displaytitle" content="Foo" about="#mwt1" typeof="mw:ExpandedAttrs" data-parsoid='{"pi":[[]]}' data-mw='{"attribs":[[{"txt":"content"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[2,23,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"DISPLAYTITLE\"}},\"i\":0}}]}&#39;>DISPLAYTITLE&lt;/span>:Foo"}]]}'/>
!! end

!! test
Namespace 1 {{ns:1}}
!! wikitext
{{ns:1}}
!! html
<p>Talk
</p>
!! end

!! test
Namespace 1 {{ns:01}}
!! wikitext
{{ns:01}}
!! html
<p>Talk
</p>
!! end

!! test
Namespace 0 {{ns:0}} (T6783)
!! wikitext
{{ns:0}}
!! html
!! end

!! test
Namespace 0 {{ns:00}} (T6783)
!! wikitext
{{ns:00}}
!! html
!! end

!! test
Namespace -1 {{ns:-1}}
!! wikitext
{{ns:-1}}
!! html
<p>Special
</p>
!! end

!! test
Namespace User {{ns:User}}
!! wikitext
{{ns:User}}
!! html
<p>User
</p>
!! end

!! test
Namespace User talk {{ns:User_talk}}
!! wikitext
{{ns:User_talk}}
!! html
<p>User talk
</p>
!! end

!! test
Namespace User talk {{ns:uSeR tAlK}}
!! wikitext
{{ns:uSeR tAlK}}
!! html
<p>User talk
</p>
!! end

!! test
Namespace File {{ns:File}}
!! wikitext
{{ns:File}}
!! html
<p>File
</p>
!! end

!! test
Namespace File {{ns:Image}}
!! wikitext
{{ns:Image}}
!! html
<p>File
</p>
!! end

!! test
Namespace (lang=de) Benutzer {{ns:User}}
!! options
language=de
!! wikitext
{{ns:User}}
!! html
<p>Benutzer
</p>
!! end

!! test
Namespace (lang=de) Benutzer Diskussion {{ns:3}}
!! options
language=de
!! wikitext
{{ns:3}}
!! html
<p>Benutzer Diskussion
</p>
!! end

!! test
Urlencode
!! wikitext
{{urlencode:hi world?!}}
{{urlencode:hi world?!|WIKI}}
{{urlencode:hi world?!|PATH}}
{{urlencode:hi world?!|QUERY}}
!! html/php
<p>hi+world%3F%21
hi_world%3F!
hi%20world%3F%21
hi+world%3F%21
</p>
!! end

!! test
Magic Word: prioritize type info over data-parsoid
!! options
parsoid=html2wt
!! html/parsoid
<meta property="mw:PageProp/forcetoc" data-parsoid='{"magicSrc":"__NOTOC__"}'/>
!! wikitext
__FORCETOC__
!! end

!! test
Magic Word: serialize on separate line (parsoid)
!! options
parsoid=wt2wt,html2wt
!! wikitext
foo
__NOTOC__
bar
!! html/parsoid
foo<meta property="mw:PageProp/notoc"/>bar
!! end

!! test
Magic Word: case-insensitive (all-lowercase)
!! wikitext
foo
__notoc__
bar
!! html/php+tidy
<p>foo
</p><p>bar
</p>
!! html/parsoid
<p>foo
<meta property="mw:PageProp/notoc" data-parsoid='{"src":"__notoc__","magicSrc":"__notoc__"}'/>
bar</p>
!! end

# wt2wt,html2wt disabled because we always (unless selser) serialize
# in a uniform case (all upper or all lower)
!! test
Magic Word: case-insensitive (mixed case)
!! options
parsoid=wt2html,html2html
!! wikitext
foo
__NOtOC__
bar
!! html/php+tidy
<p>foo
</p><p>bar
</p>
!! html/parsoid
<p>foo
<meta property="mw:PageProp/notoc" data-parsoid='{"src":"__NOtOC__","magicSrc":"__NOtOC__"}'/>
bar</p>
!! end

!! test
Magic Word: rt non-english wikis
!! options
parsoid=wt2wt
language=de
!! wikitext
__NOEDITSECTION__
!! html/parsoid
<meta property="mw:PageProp/noeditsection" data-parsoid='{"magicSrc":"__NOEDITSECTION__"}'/>
!! end

!!test
__proto__ is treated as normal wikitext (T105997)
!!wikitext
__proto__
!!html
<p>__proto__
</p>
!!end

###
### Magic links
###
!! test
Magic links: internal link to RFC (T2479)
!! wikitext
[[RFC 123]]
!! 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" class="new">RFC 123</a></p>
!! end

!! test
Magic links: RFC (T2479)
!! wikitext
RFC 822
!! html/php
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc822">RFC 822</a>
</p>
!! html/parsoid
<p><a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external mw-magiclink">RFC 822</a></p>
!! end

!! test
Magic links: RFC (T67278)
!! wikitext
This is RFC 822 but thisRFC 822 is not RFC 822linked.
!! html/php
<p>This is <a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc822">RFC 822</a> but thisRFC 822 is not RFC 822linked.
</p>
!! html/parsoid
<p>This is <a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external mw-magiclink">RFC 822</a> but thisRFC 822 is not RFC 822linked.</p>
!! end

!! test
Magic links: RFC (w/ non-newline whitespace, T30950/T31025)
!! wikitext
RFC &nbsp;&#160;&#0160;&#xA0;&#Xa0; 822
RFC
822
!! html/php
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc822">RFC 822</a>
RFC
822
</p>
!! html/parsoid
<p><a href="https://tools.ietf.org/html/rfc822" rel="mw:ExtLink" class="external mw-magiclink">RFC <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 822</a>
RFC
822</p>
!! end

!! test
Magic links: ISBN (T3937)
!! wikitext
ISBN 0-306-40615-2
!! 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
Magic links: ISBN (T67278)
!! wikitext
This is ISBN 978-0-316-09811-3 but thisISBN 978-0-316-09811-3 is not ISBN 978-0-316-09811-3linked.
!! html/php
<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: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
Magic links: ISBN (w/ non-newline whitespace, T30950/T31025)
!! wikitext
ISBN &nbsp;&#160;&#0160;&#xA0;&#Xa0; 978&nbsp;0&#160;316&#0160;09811&#xA0;3
ISBN
9780316098113
ISBN 978
0316098113
!! 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/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" class="external mw-magiclink">PMID 1234</a></p>
!! end

!! test
Magic links: PMID (T67278)
!! wikitext
This is PMID 1234 but thisPMID 1234 is not PMID 1234linked.
!! 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" class="external mw-magiclink">PMID 1234</a> but thisPMID 1234 is not PMID 1234linked.</p>
!! end

!! test
Magic links: PMID (w/ non-newline whitespace, T30950/T31025)
!! wikitext
PMID &nbsp;&#160;&#0160;&#xA0;&#Xa0; 1234
PMID
1234
!! 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" class="external mw-magiclink">PMID <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 1234</a>
PMID
1234</p>
!! end

# <nowiki> nodes shouldn't be inserted during html2wt by Parsoid,
# since these are ExtLinkText, not MagicLinkText
!! test
Magic links: use appropriate serialization for "almost" magic links.
!! wikitext
X[[Special:BookSources/0978739256|foo]]

X[https://tools.ietf.org/html/rfc1234 foo]
!! html/php
<p>X<a href="/wiki/Special:BookSources/0978739256" title="Special:BookSources/0978739256">foo</a>
</p><p>X<a rel="nofollow" class="external text" href="https://tools.ietf.org/html/rfc1234">foo</a>
</p>
!! html/parsoid
<p>X<a rel="mw:WikiLink" href="./Special:BookSources/0978739256" title="Special:BookSources/0978739256">foo</a></p>
<p>X<a rel="mw:ExtLink" href="https://tools.ietf.org/html/rfc1234" class="external text">foo</a></p>
!! end

!! test
Magic links: All disabled (T47942)
!! options
wgEnableMagicLinks={"ISBN":false, "PMID":false, "RFC":false}
!! wikitext
ISBN 0-306-40615-2
PMID 1234
RFC 4321
!! html/php
<p>ISBN 0-306-40615-2
PMID 1234
RFC 4321
</p>
!! end

###
### Templates
####

!! test
Nonexistent template
!! wikitext
{{thistemplatedoesnotexist}}
!! html
<p><a href="/index.php?title=Template:Thistemplatedoesnotexist&amp;action=edit&amp;redlink=1" class="new" title="Template:Thistemplatedoesnotexist (page does not exist)">Template:Thistemplatedoesnotexist</a>
</p>
!! end

!! test
Template with invalid target containing tags
!! wikitext
{{a<b>b</b>|{{1x|foo}}|{{1x|a}}={{1x|b}}|a = b}}
!! html
<p>{{a<b>b</b>|foo|a=b|a = b}}
</p>
!! end

!! test
Template with invalid target containing unclosed tag
!! options
parsoid=wt2html
!! wikitext
{{a<b>|{{1x|foo}}|{{1x|a}}={{1x|b}}|a = b}}
!! html/php
<p>{{a<b>|foo|a=b|a = b}}
</b></p>
!! html/parsoid
<p>{{a<b data-parsoid='{"stx":"html","autoInsertedEnd":true}'>|<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>|<span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span>=<span about="#mwt4" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b"}},"i":0}}]}'>b</span>|a = b}}</b></p>
!! end

!! test
Template with invalid target containing wikilink
!! wikitext
{{[[Main Page]]}}
!! html/php
<p>{{<a href="/wiki/Main_Page" title="Main Page">Main Page</a>}}
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"[[Main Page]]"},"params":{},"i":0}}]}'>{{</span><a rel="mw:WikiLink" href="./Main_Page" about="#mwt1">Main Page</a><span about="#mwt1">}}</span></p>
!! end

# The html2html output of this test is currently failing
# because the html2wt output is broken; see
# https://phabricator.wikimedia.org/T220018#5123777 for a discussion.
# Not (yet) including html2wt as a test mode because there are
# a couple of different correct ways this could be <nowiki>'ed.
!! test
Template with just whitespace in it, T70421
!! wikitext
{{1x|{{ }}}}
!! options
parsoid=wt2html,html2html
!! html/php+tidy
<p>{{ }}
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{ }}"}},"i":0}}]}'>{{ }}</span></p>
!! end

# This is currently the wikitext output of html2wt on the above test
# case; note that it is broken! Adding a <nowiki> around the closing
# brace changes how the open braces associate, breaking the outer
# {{1x}} template invocation.  *However* this "broken" wikitext
# exposed a useful tokenizer bug (T221384) in how the broken_template
# rule was being backtracked into, so it's a useful test case even
# if/when the above test case gets its html2wt output fixed.
!! test
Template with just whitespace (bad template brace matching)
!! options
parsoid=wt2html
!! wikitext
{{1x|{{ }<nowiki>}</nowiki>}}
!! html/php+tidy
<p>{{1x|{{ }}}}
</p>
!! html/parsoid
<p>{{1x|{{ }<span typeof="mw:Nowiki">}</span>}}</p>
!! end

!! article
Template:test
!! text
This is a test template
!! endarticle

!! test
Simple template
!! wikitext
{{test}}
!! html
<p>This is a test template
</p>
!! end

!! test
Template with explicit namespace
!! wikitext
{{Template:test}}
!! html
<p>This is a test template
</p>
!! end


!! article
Template:paramtest
!! text
This is a test template with parameter {{{param}}}
!! endarticle

!! test
Template parameter
!! wikitext
{{paramtest|param=foo}}
!! html
<p>This is a test template with parameter foo
</p>
!! end

!! article
Template:paramtestnum
!! text
[[{{{1}}}|{{{2}}}]]
!! endarticle

!! test
Template unnamed parameter
!! wikitext
{{paramtestnum|Main Page|the main page}}
!! html
<p><a href="/wiki/Main_Page" title="Main Page">the main page</a>
</p>
!! end

!! article
Template:templatesimple
!! text
(test)
!! endarticle

!! article
Template:templateredirect
!! text
#redirect [[Template:templatesimple]]
!! endarticle

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

!! article
Template:templateasargtest
!! text
{{template{{{templ}}}}}
!! endarticle

!! article
Template:templateasargtest2
!! text
{{{{{templ}}}}}
!! endarticle

!! test
Template with template name as unnamed argument
!! wikitext
{{templateasargtestnum|templatesimple}}
!! html
<p>(test)
</p>
!! end

!! test
Template with template name as argument
!! wikitext
{{templateasargtest|templ=simple}}
!! html
<p>(test)
</p>
!! end

!! test
Template with template name as argument (2)
!! wikitext
{{templateasargtest2|templ=templatesimple}}
!! html
<p>(test)
</p>
!! end

!! article
Template:templateasargtestdefault
!! text
{{{{{templ|templatesimple}}}}}
!! endarticle

!! article
Template:templa
!! text
'''templ'''
!! endarticle

!! test
Template with default value
!! wikitext
{{templateasargtestdefault}}
!! html
<p>(test)
</p>
!! end

!! test
Template with default value (value set)
!! wikitext
{{templateasargtestdefault|templ=templa}}
!! html
<p><b>templ</b>
</p>
!! end

!! test
Template redirect
!! wikitext
{{templateredirect}}
!! html/php
<p>(test)
</p>
!! html/parsoid
<link rel="mw:PageProp/redirect" href="./Template:Templatesimple" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"templateredirect","href":"./Template:Templateredirect"},"params":{},"i":0}}]}'/>
!! end

!! test
Template with argument in separate line
!! wikitext
{{ templateasargtest  |
 templ = simple }}
!! html
<p>(test)
</p>
!! end

!! test
Template with complex template as argument
!! wikitext
{{paramtest|
  param ={{ templateasargtest  |
 templ = simple }}}}
!! html
<p>This is a test template with parameter (test)
</p>
!! end

!! test
Templates with templated name
!! wikitext
{{{{1x|1x}}|foo}}
{{{{1x|inner list}} }}
!! html
<p>foo
</p>
<ul><li>item 1</li></ul>
!! html/parsoid
<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|1x}}","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
<ul about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|inner list}} ","href":"./Template:Inner_list"},"params":{},"i":0}}]}'><li>item 1</li></ul>
!! end

## Regression test; the output here isn't really that interesting.
!! test
Templates with templated name and top level template args
!! wikitext
{{1{{2{{{3}}}|4=5}}}}
!! html/parsoid
<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1{{2{{{3}}}|4=5}}"},"params":{},"i":0}}]}'>{{1{{2{{{3}}}|4=5}}}}</span></p>
!! end

# Parsoid markup is deliberate "broken". This is an edge case.
# See long comment in TemplateHandler.js:convertAttribsToString.
!! test
Templates with invalid templated targets
!! wikitext
{{1x
{{1x|foo}}
}}
!! html/php
<p>{{1x
foo
}}
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x\n{{1x|foo}}\n"},"params":{},"i":0}}]}'>{{1x
foo }}</span></p>
!! end

!! article
Template:complextemplate
!! text
{{{1}}} {{paramtest|
  param ={{{param}}}}}
!! endarticle

!! test
Template with complex arguments
!! wikitext
{{complextemplate|
  param ={{ templateasargtest  |
 templ = simple }}|[[Template:complextemplate|link]]}}
!! html
<p><a href="/wiki/Template:Complextemplate" title="Template:Complextemplate">link</a> This is a test template with parameter (test)
</p>
!! end

!! test
T2553: link with two variables in a piped link
!! wikitext
{|
|[[{{{1}}}|{{{2}}}]]
|}
!! html/php
<table>
<tbody><tr>
<td>[[{{{1}}}|{{{2}}}]]
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>[[<span about="#mwt5" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"1"},"params":{},"i":0}}]}'>{{{1}}}</span>|<span about="#mwt2" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"2"},"params":{},"i":0}}]}'>{{{2}}}</span>]]</td></tr>
</tbody></table>
!! end

# See: T2553
!! test
Abort table cell attribute parsing on wikilink
!! wikitext
{|
|testing [[one|two]] |three||four
|testing one two |three||four
|testing="[[one|two]]" |three||four
|}
!! html/php
<table>
<tbody><tr>
<td>testing <a href="/index.php?title=One&amp;action=edit&amp;redlink=1" class="new" title="One (page does not exist)">two</a> |three</td>
<td>four
</td>
<td>three</td>
<td>four
</td>
<td>testing="<a href="/index.php?title=One&amp;action=edit&amp;redlink=1" class="new" title="One (page does not exist)">two</a>" |three</td>
<td>four
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{}'>testing <a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"piped","a":{"href":"./One"},"sa":{"href":"one"}}' class="new">two</a> |three</td><td data-parsoid='{"stx":"row"}'>four</td>
<td data-parsoid='{"a":{"testing":null,"one":null,"two":null},"sa":{"testing":"","one":"","two":""}}'>three</td><td data-parsoid='{"stx":"row"}'>four</td>
<td>testing="<a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"piped","a":{"href":"./One"},"sa":{"href":"one"}}' class="new">two</a>" |three</td><td data-parsoid='{"stx":"row"}'>four</td></tr>
</tbody></table>
!! end

!! test
Don't abort table cell attribute parsing if wikilink is found in template arg
!! wikitext
{|
|Test {{#tag:ref|One two "[[three]]" four}}
|}
!! html/parsoid
<table>
<tbody><tr><td>Test <ref about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#tag:ref","function":"tag"},"params":{"1":{"wt":"One two \"[[three]]\" four"}},"i":0}}]}'>One two "<a rel="mw:WikiLink" href="./Three" title="Three" class="new">three</a>" four</ref></td></tr>
</tbody></table>
!! end

!! test
Magic variable as template parameter
!! wikitext
{{paramtest|param={{SITENAME}}}}
!! html
<p>This is a test template with parameter MediaWiki
</p>
!! end

!! article
Template:linktest
!! text
[[{{{param}}}|link]]
!! endarticle

!! test
Template parameter as link source
!! wikitext
{{linktest|param=Main Page}}
!! html
<p><a href="/wiki/Main_Page" title="Main Page">link</a>
</p>
!! end

!!article
Template:paramtest2
!! text
including another template, {{paramtest|param={{{arg}}}}}
!! endarticle

!! test
Template passing argument to another template
!! wikitext
{{paramtest2|arg='hmm'}}
!! html
<p>including another template, This is a test template with parameter 'hmm'
</p>
!! end

!! article
Template:Linktest2
!! text
Main Page
!! endarticle

!! test
Template as link source
!! wikitext
[[{{linktest2}}]]

[[{{linktest2}}|Main Page]]

[[{{linktest2}}]]Page
!! html
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p><p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p><p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>Page
</p>
!! end


!! article
Template:loop1
!! text
{{loop2}}
!! endarticle

!! article
Template:loop2
!! text
{{loop1}}
!! endarticle

!! test
Template infinite loop
!! wikitext
{{loop1}}
!! html/php
<p><span class="error">Template loop detected: <a href="/wiki/Template:Loop1" title="Template:Loop1">Template:Loop1</a></span>
</p>
!! html/parsoid
<p><span class="error" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"loop1","href":"./Template:Loop1"},"params":{},"i":0}}]}'>Template loop detected: <a rel="mw:WikiLink" href="./Template:Loop1" title="Template:Loop1">Template:Loop1</a></span></p>
!! end

!! test
Template from main namespace
!! wikitext
{{:Main Page}}
!! html
<p>blah blah
</p>
!! end

!! test
Template from non-includable namespace
!! options
wgNonincludableNamespaces=10
!! wikitext
{{1x|uh oh!}}
!! html
<p><a href="/wiki/Template:1x" title="Template:1x">Template:1x</a>
</p>
!! end

!! article
Template:table
!! text
{|
| 1 || 2
|-
| 3 || 4
|}
!! endarticle

!! test
T2529: Template with table, not included at beginning of line
!! wikitext
foo {{table}}
!! html
<p>foo 
</p>
<table>
<tbody><tr>
<td>1</td>
<td>2
</td></tr>
<tr>
<td>3</td>
<td>4
</td></tr></tbody></table>
!! end

!! test
T2523: Template shouldn't eat newline (or add an extra one before table)
!! wikitext
foo
{{table}}
!! html
<p>foo
</p>
<table>
<tbody><tr>
<td>1</td>
<td>2
</td></tr>
<tr>
<td>3</td>
<td>4
</td></tr></tbody></table>
!! end

!! test
T2041: Template parameters shown as broken links
!! wikitext
{{{parameter}}}
!! html
<p>{{{parameter}}}
</p>
!! end

!! test
Template with targets containing wikilinks
!! options
parsoid=wt2html
!! wikitext
{{[[foo]]}}

{{[[{{1x|foo}}]]}}

{{{{1x|[[foo}}]]}}
!! html/php
<p>{{<a href="/wiki/Foo" title="Foo">foo</a>}}
</p><p>{{<a href="/wiki/Foo" title="Foo">foo</a>}}
</p><p>{{[[foo}}]]
</p>
!! html/parsoid
<p>{{<a rel="mw:WikiLink" href="./Foo" title="Foo">foo</a>}}</p>
<p>{{<a typeof="mw:ExpandedAttrs" rel="mw:WikiLink" href="./Foo" title="Foo" data-mw='{"attribs":[[{"txt":"href"},{"html":"&lt;span about=\"#mwt3\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"foo\"}},\"i\":0}}]}&#39;>foo&lt;/span>"}]]}'>foo</a>}}</p>
<p>{{<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[foo}}]]"}},"i":0}}]}'>[[foo}}]]</span></p>
!! end

!! article
Template:''
!! text
bar
!! endarticle

!! test
Templates: Double quotes as template target
!! wikitext
foo {{''}} baz
!! html/php
<p>foo bar baz
</p>
!! html/parsoid
<p>foo <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"&#39;&#39;","href":"./Template:&#39;&#39;"},"params":{},"i":0}}]}'>bar</span> baz
</p>
!! end

## This test is about making sure Parsoid's data-mw is well formed in the
## face of multiple templates with intersecting and overlapping ranges.  The
## wikitext itself is wretched.
!! test
Templates with intersecting and overlapping ranges
!! wikitext
{|{{1x|
<p>ha</p>}}
{|{{1x|
<p>ho</p>}}
{{1x|{{!}}hi}}
|}
!! html/php+tidy
<p>ha</p><table>

</table><p>ho</p><table>

<tbody><tr>
<td>hi
</td></tr></tbody></table>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]],"firstWikitextNode":"TABLE"}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n&lt;p>ha&lt;/p>"}},"i":0}},"\n","{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n&lt;p>ho&lt;/p>"}},"i":1}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}hi"}},"i":2}},"\n|}"]}'>ha</p><table about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"","html":""},{"html":""}]]}'>

</table><p about="#mwt1">ho</p><table about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"","html":""},{"html":""}]]}'>

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

!! article
Template:MSGNW test
!! text
''None'' of '''this''' should be 
* interpreted
 but rather passed unmodified
{{test}}
<gallery>
File:Foobar.jpg
</gallery>
<!-- comment -->
!! endarticle

# hmm, fix this or just deprecate msgnw and document its behavior?
!! test
msgnw keyword
!! wikitext
{{msgnw:MSGNW test}}
!! html/php
<p>&#39;&#39;None&#39;&#39; of &#39;&#39;&#39;this&#39;&#39;&#39; should be 
&#42; interpreted
&#32;but rather passed unmodified
&#123;&#123;test&#125;&#125;
&#60;gallery&#62;
File:Foobar.jpg
&#60;/gallery&#62;
&#60;!-- comment --&#62;
</p>
!! end

!! test
int keyword
!! wikitext
{{int:youhavenewmessages|lots of money|not!}}
!! html
<p>You have lots of money (not!).
</p>
!! end

!! test
int keyword - non-existing message
!! wikitext
{{int:var}}
!! html
<p>⧼var⧽
</p>
!! end

!! article
Template:Includes
!! text
Foo<noinclude>zar</noinclude><includeonly>bar</includeonly>
!! endarticle

!! test
<includeonly> and <noinclude> being included
!! wikitext
{{Includes}}
!! html
<p>Foobar
</p>
!! end

!! article
Template:Includes2
!! text
<onlyinclude>Foo</onlyinclude>bar
!! endarticle

!! test
<onlyinclude> being included
!! wikitext
{{Includes2}}
!! html/php+tidy
<p>Foo
</p>
!! html/parsoid
<p><meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes2","href":"./Template:Includes2"},"params":{},"i":0}}]}'/><span about="#mwt1">Foo</span><meta typeof="mw:Includes/OnlyInclude/End" about="#mwt1"/></p>
!! end


!! article
Template:Includes3
!! text
<onlyinclude>Foo</onlyinclude>bar<includeonly>zar</includeonly>
!! endarticle

!! test
<onlyinclude> and <includeonly> being included
!! wikitext
{{Includes3}}
!! html/php+tidy
<p>Foo
</p>
!! html/parsoid
<p><meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes3","href":"./Template:Includes3"},"params":{},"i":0}}]}'/><span about="#mwt1">Foo</span><meta typeof="mw:Includes/OnlyInclude/End" about="#mwt1"/></p>
!! end

# FIXME: Parsoid's markup for this is quite ugly.
!! test
<includeonly> and <noinclude> on a page
!! wikitext
Foo<noinclude>zar</noinclude><includeonly>bar</includeonly>
!! html/php+tidy
<p>Foozar
</p>
!! html/parsoid
<p>Foo<meta typeof="mw:Includes/NoInclude" data-parsoid="{}"/>zar</p><meta typeof="mw:Includes/NoInclude/End" data-parsoid="{}"/><meta typeof="mw:Includes/IncludeOnly" data-mw='{"src":"&lt;includeonly>bar&lt;/includeonly>"}' data-parsoid="{}"/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid="{}"/>
!! end

!! test
Un-closed <noinclude>
!! wikitext
<noinclude>
!! html/php+tidy
!! html/parsoid
<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
!! end

!! test
Empty <noinclude>
!! wikitext
Hello<noinclude></noinclude>!
!! html/php+tidy
<p>Hello!
</p>
!! html/parsoid
<p>Hello<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>!</p>
!! end

!! test
Nested <noinclude>s
!! wikitext
<noinclude>
x
<noinclude>y</noinclude>
z
</noinclude>
!! html/php
<p>x
y
z
</p>
!! html/parsoid
<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<p>x
<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>y<meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>
z</p>
<meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>
!! end

!! test
<onlyinclude> on a page
!! wikitext
<onlyinclude>Foo</onlyinclude>bar
!! html
<p>Foobar
</p>
!! end

!! test
Un-closed <onlyinclude>
!! wikitext
<onlyinclude>
!! html
!! end

!! test
T236868: Un-closed <noinclude> caused bad SourceRange length
!! wikitext
{| <noinclude>
|- <noinclude>
| A
|-</noinclude>
|}
!! html/parsoid
<table about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"a":{"&lt;noinclude>\n|- &lt;noinclude>\n| A\n|-&lt;/noinclude>":null},"sa":{"&lt;noinclude>\n|- &lt;noinclude>\n| A\n|-&lt;/noinclude>":""}}' data-mw='{"attribs":[[{"txt":" A","html":"&lt;meta typeof=\"mw:Includes/NoInclude\" data-parsoid=&apos;{\"src\":\"&amp;lt;noinclude>\",\"dsr\":[3,14,null,null]}&apos;/>\n|- &amp;lt;noinclude>\n| A\n|-&lt;meta typeof=\"mw:Includes/NoInclude/End\" data-parsoid=&apos;{\"src\":\"&amp;lt;/noinclude>\",\"dsr\":[36,48,null,null]}&apos;/>"},{"html":""}]]}'>
</table>
!! end

!!test
Self-closed noinclude, includeonly, onlyinclude tags
!! wikitext
<noinclude />
<includeonly />
<onlyinclude />
!! html
<p><br />
</p>
!!end

!!test
Unbalanced includeonly and noinclude tags
!! wikitext
{|
|a</noinclude>
|b</noinclude></noinclude>
|c</noinclude></includeonly>
|d</includeonly></includeonly>
|}
!! html
<table>
<tbody><tr>
<td>a
</td>
<td>b
</td>
<td>c&lt;/includeonly&gt;
</td>
<td>d&lt;/includeonly&gt;&lt;/includeonly&gt;
</td></tr></tbody></table>
!!end

!! article
Template:Includeonly section
!! text
<includeonly>
==Includeonly section==
</includeonly>
==Section T-1==
!!endarticle

!! test
T8563: Edit link generation for section shown by <includeonly>
!! wikitext
{{includeonly section}}
!! html+untidy
<h2><span class="mw-headline" id="Includeonly_section">Includeonly section</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Includeonly_section&amp;action=edit&amp;section=T-1" title="Template:Includeonly section">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Section_T-1">Section T-1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Includeonly_section&amp;action=edit&amp;section=T-2" title="Template:Includeonly section">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html+tidy
<h2><span class="mw-headline" id="Includeonly_section">Includeonly section</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Includeonly_section&amp;action=edit&amp;section=T-1" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Section_T-1">Section T-1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Includeonly_section&amp;action=edit&amp;section=T-2" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

# Uses same input as the contents of [[Template:Includeonly section]]
!! test
T8563: Section extraction for section shown by <includeonly>
!! options
section=T-2
!! wikitext
<includeonly>
==Includeonly section==
</includeonly>
==Section T-2==
!! html
==Section T-2==
!! end

!! test
T8563: Edit link generation for section suppressed by <includeonly>
!! wikitext
<includeonly>
==Includeonly section==
</includeonly>
==Section 1==
!! html
<h2><span class="mw-headline" id="Section_1">Section 1</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: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
T8563: Section extraction for section suppressed by <includeonly>
!! options
section=1
!! wikitext
<includeonly>
==Includeonly section==
</includeonly>
==Section 1==
!! html
==Section 1==
!! end

!! test
Un-closed <includeonly>
!! wikitext
<includeonly>
!! html/php
!! html/parsoid
<meta typeof="mw:Includes/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>"}' data-mw='{"src":"&lt;includeonly>"}'/>
!! end

## We used to, but no longer wt2wt this test since the default serializer
## will normalize the include directives to serialize on their own line.
## Selser will take care of preserving formatting in scenarios where they
## intermingled with other wikitext.
## This test also triggered T223411 during Parsoid-PHP porting.
!! test
Includes and comments at SOL
!! options
parsoid=wt2html,html2html
!! wikitext
<!-- comment --><noinclude><!-- comment --></noinclude><!-- comment -->==hu==

<noinclude>
some
</noinclude>*stuff
*here

<noinclude>
some</noinclude>* stuff
* here

<includeonly>can have stuff</includeonly>===here===

!! html/php
<h2><span class="mw-headline" id="hu">hu</span></h2>
<p>some
</p>
<ul><li>stuff</li>
<li>here</li></ul>
<p><br />
some* stuff
</p>
<ul><li>here</li></ul>
<h3><span class="mw-headline" id="here">here</span></h3>
!! html/parsoid
<!-- comment --><meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><!-- comment --><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/><!-- comment --><h2 id="hu">hu</h2>

<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<p>some</p>
<meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/><ul><li>stuff</li>
<li>here</li></ul>

<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<p>some<meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>* stuff</p>
<ul><li>here</li></ul>

<meta typeof="mw:Includes/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>can have stuff&lt;/includeonly>"}' data-mw='{"src":"&lt;includeonly>can have stuff&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><h3 id="here">here</h3>
!! end

# TODO: test with DOM fragment reuse!
!! test
Parsoid: DOM fragment reuse
!! options
parsoid=wt2wt,wt2html
!! wikitext
a{{1x|b<table></table>c}}d

a{{1x|b
<table></table>
c}}d

{{1x|a

<table></table>

b}}
!! html/php+tidy
<p>ab</p><table></table><p>cd
</p><p>ab
</p>
<table></table>
<p>cd
</p><p>a
</p>
<table></table>
<p>b
</p>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["a",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b&lt;table>&lt;/table>c"}},"i":0}},"d"]}' data-parsoid='{"pi":[[{"k":"1"}]]}'>ab</p><table about="#mwt1" data-parsoid='{"stx":"html"}'></table><p about="#mwt1">cd</p>

<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":["a",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b\n&lt;table>&lt;/table>\nc"}},"i":0}},"d"]}' data-parsoid='{"pi":[[{"k":"1"}]]}'>ab</p><span about="#mwt2">
</span><table about="#mwt2" data-parsoid='{"stx":"html"}'></table><span about="#mwt2">
</span><p about="#mwt2">cd</p>

<p about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\n\n&lt;table>&lt;/table>\n\nb"}},"i":0}}]}' data-parsoid='{"pi":[[{"k":"1"}]]}'>a</p><span about="#mwt3">

</span><table about="#mwt3" data-parsoid='{"stx":"html"}'></table><span about="#mwt3">

</span><p about="#mwt3">b</p>
!! end

!! test
Parsoid: Merge double tds (T52603)
!! wikitext
{|
|{{1x|{{!}} foo}}
|}
!! html/php+tidy
<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
Parsoid: Merge double tds in nested transclusion content (T52603)
!! wikitext
{{1x|<div>}}
{|
|{{1x|{{!}} foo}}
|}
{{1x|</div>}}
!! html/php+tidy
<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":"<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":"</div>"}},"i":2}}]}'>
<table><tbody>
<tr><td data-mw='{"parts":["|"]}'> foo</td></tr>
</tbody></table>
</div>
!! end

###
### <includeonly> and <noinclude> in attributes
###
!!test
0. includeonly around the entire attribute
!! wikitext
<span <includeonly>id="v1"</includeonly><noinclude>id="v2"</noinclude>>bar</span>
!! html
<p><span id="v2">bar</span>
</p>
!!end

!!test
1. includeonly in html attr key
!! wikitext
<span <noinclude>id</noinclude><includeonly>about</includeonly>="foo">bar</span>
!! html
<p><span id="foo">bar</span>
</p>
!!end

!!test
2. includeonly in html attr value
!! wikitext
<span id="<noinclude>v1</noinclude><includeonly>v2</includeonly>">bar</span>
<span id=<noinclude>"v1"</noinclude><includeonly>"v2"</includeonly>>bar</span>
!! html
<p><span id="v1">bar</span>
<span id="v1">bar</span>
</p>
!!end

!!test
3. includeonly in part of an attr value
!! wikitext
<span style="color:<noinclude>red</noinclude><includeonly>blue</includeonly>;">bar</span>
!! html
<p><span style="color:red;">bar</span>
</p>
!!end

!!test
4. includeonly in table attributes
!! wikitext
{|
|- <noinclude>
|-
|a
</noinclude>
|- <includeonly>
|-
|b
</includeonly>
|}
!! html
<table>


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

###
### Preprocessor precedence tests
### See: https://www.mediawiki.org/wiki/Preprocessor_ABNF
###
##{{[[-{{{{{{[[Foo|bar}}]]}-}}}}}]]
!! test
Preprocessor precedence 1: link is rightmost opening
!! options
parsoid=wt2html
!! wikitext
{{[[Foo|bar}}]]

But close-brace is not a valid character in a link title:
{{[[Foo}}|bar]]

However, we can still tell this was handled as a link in the preprocessor:
{{1x|[[Foo}}|bar]]|bat}}
!! html/php
<p>{{<a href="/wiki/Foo" title="Foo">bar}}</a>
</p><p>But close-brace is not a valid character in a link title:
{{[[Foo}}|bar]]
</p><p>However, we can still tell this was handled as a link in the preprocessor:
[[Foo}}|bar]]
</p>
!! html/parsoid
<p>{{<a rel="mw:WikiLink" href="./Foo" title="Foo">bar}}</a></p>
<p>But close-brace is not a valid character in a link title: {{[[Foo}}|bar]]</p>
<p>However, we can still tell this was handled as a link in the preprocessor: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Foo}}|bar]]"},"2":{"wt":"bat"}},"i":0}}]}'>[[Foo}}|bar]]</span></p>
!! end

!! test
Preprocessor precedence 2: template is rightmost opening
!! options
language=zh
!! wikitext
-{{1x|foo}-}}-
!! html/php
<p>-foo}--
</p>
!! html/parsoid
<p>-<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo}-"}},"i":0}}]}'>foo}-</span>-</p>
!! end

!! test
Preprocessor precedence 3: language converter is rightmost opening
!! options
language=zh
parsoid=wt2html
!! wikitext
{{1x|hi}}

{{-{R|1x|hi}}}-

[[-{R|raw]]}-
!! html/php
<p>hi
</p><p>{{1x|hi}}
</p><p>[[raw]]
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi"}},"i":0}}]}'>hi</span></p>
<p>{{<span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"1x|hi}}"}}'></span></p>
<p>[[<span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"raw]]"}}'></span></p>
!! end

!! test
Preprocessor precedence 4: left-most angle bracket
!! options
language=zh
!! wikitext
<!--{raw}-->
!! html/php
!! html/parsoid
<!--{raw}-->
!! end

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

!! test
Preprocessor precedence 5: tplarg takes precedence over template
!! wikitext
{{Precedence5|Bullet}}
!! html/php
<ul><li>Bar</li></ul>
!! html/parsoid
<ul typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Precedence5","href":"./Template:Precedence5"},"params":{"1":{"wt":"Bullet"}},"i":0}}]}'><li>Bar</li></ul>
!! end

!! test
Preprocessor precedence 6: broken link is rightmost opening
!! options
parsoid=wt2html
!! wikitext
{{1x|[[Foo}}

{{1x|[[Foo|bar|bat=baz}}
!! html/php
<p>{{1x|[[Foo}}
</p><p>{{1x|[[Foo|bar|bat=baz}}
</p>
!! html/parsoid
<p>{{1x|[[Foo}}</p>
<p>{{1x|[[Foo|bar|bat=baz}}</p>
!! end

# This next test exposes a difference between PHP and Parsoid:
# Given [[Foo|{{1x|Bar]]x}}y]]z:
# 1) Both PHP and Parsoid ignore the `]]` inside the `1x` in the
# "preprocessor" stage.  The `{{1x` extends until the `x}}`, and the
# outer `[[Foo` extends until the `y]]`
# 2a) But then the PHP preprocessor emits `[[Foo|Bar]]xy]]z` as an
# intermediate result (after template expansion), and link processing
# happens on this intermediate result, which moves the wikilink
# boundary leftward to `[[Foo|Bar]]`
# 2b) Parsoid works in a single step, so it's going to keep the
# wikilink as extending to the `y]]`
# 3a) Then PHP does linktrail processing which slurps up the trailing
# `xy` inside the link.
# 3b) Parsoid will do linktrail processing to slurp up the trailing
# `z` inside the link.
# This is "correct" behavior.  Parsoid's basic worldview is that the
# `]]` inside the template shouldn't be allowed to leak out to affect
# the surrounding wikilink.  PHP may match Parsoid (in the future)
# if you use {{#balance}} (T114445).

!! test
Preprocessor precedence 7: broken template is rightmost opening
!! options
parsoid=wt2html
!! wikitext
[[Foo|{{1x|Bar]]

[[Foo|{{1x|Bar]]-x}}-y]]-z

Careful: linktrails can move the end of the wikilink:
[[Foo|{{1x|y']]a}}l]]l
!! html/php
<p><a href="/wiki/Foo" title="Foo">{{1x|Bar</a>
</p><p><a href="/wiki/Foo" title="Foo">Bar</a>-x-y]]-z
</p><p>Careful: linktrails can move the end of the wikilink:
<a href="/wiki/Foo" title="Foo">y'al</a>]]l
</p>
!! html/parsoid
<p>[[Foo|{{1x|Bar]]</p>
<p><a rel="mw:WikiLink" href="./Foo" title="Foo"><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Bar]]-x"}},"i":0}}]}'>Bar]]-x</span>-y</a>-z</p>
<p>Careful: linktrails can move the end of the wikilink:
<a rel="mw:WikiLink" href="./Foo" title="Foo"><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"y&#39;]]a"}},"i":0}}]}'>y']]a</span>ll</a></p>
!! end

!! test
Preprocessor precedence 8: broken language converter is rightmost opening
!! options
language=zh
!! wikitext
[[Foo-{R|raw]]
!! html
<p>[[Foo-{R|raw]]
</p>
!! end

!! article
Template:Preprocessor_precedence_9
!! text
;4: {{{{1}}}}
;5: {{{{{2}}}}}
;6: {{{{{{3}}}}}}
;7: {{{{{{{4}}}}}}}
!! endarticle

!! test
Preprocessor precedence 9: groups of braces
!! wikitext
{{Preprocessor precedence 9|Four|Bullet|1|2}}
!! html/php
<dl><dt>4</dt>
<dd>{Four}</dd>
<dt>5</dt>
<dd></dd></dl>
<ul><li>Bar</li></ul>
<dl><dt>6</dt>
<dd>Four</dd>
<dt>7</dt>
<dd>{Bullet}</dd></dl>
!! html/parsoid
<dl about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Preprocessor precedence 9","href":"./Template:Preprocessor_precedence_9"},"params":{"1":{"wt":"Four"},"2":{"wt":"Bullet"},"3":{"wt":"1"},"4":{"wt":"2"}},"i":0}}]}'>
<dt>4</dt>
<dd>{Four}</dd>
<dt>5</dt>
<dd></dd>
</dl><ul about="#mwt1">
<li>Bar</li>
</ul><span about="#mwt1"> </span><dl about="#mwt1">
<dt>6</dt>
<dd>Four</dd>
<dt>7</dt>
<dd>{Bullet}</dd>
</dl>
!! end

!! article
Template:Preprocessor_precedence_10
!! text
;1: -{R|raw}-
;2: -{{Bullet}}-
;3: -{{{1}}}-
;4: -{{{{2}}}}-
;5: -{{{{{3}}}}}-
;6: -{{{{{{4}}}}}}-
;7: -{{{{{{{5}}}}}}}-
!! endarticle

!! test
Preprocessor precedence 10: groups of braces with leading dash
!! options
language=zh
!! wikitext
{{Preprocessor precedence 10|Three|raw2|Bullet|1|2}}
!! html/php
<dl><dt>1</dt>
<dd>raw</dd>
<dt>2</dt>
<dd>-</dd></dl>
<ul><li>Bar-</li></ul>
<dl><dt>3</dt>
<dd>-Three-</dd>
<dt>4</dt>
<dd>raw2</dd>
<dt>5</dt>
<dd>-</dd></dl>
<ul><li>Bar-</li></ul>
<dl><dt>6</dt>
<dd>-Three-</dd>
<dt>7</dt>
<dd>raw2</dd></dl>
!! html/parsoid
<dl about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Preprocessor precedence 10","href":"./Template:Preprocessor_precedence_10"},"params":{"1":{"wt":"Three"},"2":{"wt":"raw2"},"3":{"wt":"Bullet"},"4":{"wt":"1"},"5":{"wt":"2"}},"i":0}}]}'>
<dt>1</dt>
<dd><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"raw"}}'></span></dd>
<dt>2</dt>
<dd>-</dd>
</dl><ul about="#mwt1">
<li>Bar-</li>
</ul><span about="#mwt1"> </span><dl about="#mwt1">
<dt>3</dt>
<dd>-Three-</dd>
<dt>4</dt>
<dd><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"raw2"}}'></span></dd>
<dt>5</dt>
<dd>-</dd>
</dl><ul about="#mwt1">
<li>Bar-</li>
</ul><span about="#mwt1"> </span><dl about="#mwt1">
<dt>6</dt>
<dd>-Three-</dd>
<dt>7</dt>
<dd><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"raw2"}}'></span></dd>
</dl>
!! end

!! test
Preprocessor precedence 11: found during visual diff testing
!! wikitext
{{#tag:span|-{{#tag:span|-{{1x|x}}}}}}

{{1x|-{{1x|-{{1x|x}}}}}}

{{1x|-{{1x|x}}}}
!! html/php
<p><span>-<span>-x</span></span>
</p><p>--x
</p><p>-x
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#tag:span","function":"tag"},"params":{"1":{"wt":"-{{#tag:span|-{{1x|x}}}}"}},"i":0}}]}'>-<span>-x</span></span></p>

<p><span about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"-{{1x|-{{1x|x}}}}"}},"i":0}}]}'>--x</span></p>

<p><span about="#mwt7" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"-{{1x|x}}"}},"i":0}}]}'>-x</span></p>
!! end

!! test
Preprocessor precedence 12: broken language converter closed by brace.
!! options
parsoid=wt2html
!! wikitext
This form breaks the template, which is unfortunate:
*{{1x|foo-{bar}bat}}

But if the broken language converter markup is inside an extension
tag, nothing bad happens:
*<nowiki>foo-{bar}bat</nowiki>
*{{1x|<nowiki>foo-{bar}bat</nowiki>}}
*<pre>foo-{bar}bat</pre>
*{{1x|<pre>foo-{bar}bat</pre>}}

<tag>foo-{bar}bat</tag>
{{1x|<tag>foo-{bar}bat</tag>}}

!! html/php+tidy
<p>This form breaks the template, which is unfortunate:
</p>
<ul><li>{{1x|foo-{bar}bat}}</li></ul>
<p>But if the broken language converter markup is inside an extension
tag, nothing bad happens:
</p>
<ul><li>foo-&#123;bar}bat</li>
<li>foo-&#123;bar}bat</li>
<li><pre>foo-{bar}bat</pre></li>
<li><pre>foo-{bar}bat</pre></li></ul>
<pre>'foo-{bar}bat'
array (
)
</pre>
<pre>'foo-{bar}bat'
array (
)
</pre>
!! html/parsoid
<p>This form breaks the template, which is unfortunate:</p>
<ul>
<li>{{1x|foo-{bar}bat}}</li>
</ul>
<p>But if the broken language converter markup is inside an extension tag, nothing bad happens:</p>
<ul>
<li><span typeof="mw:Nowiki">foo-{bar}bat</span></li>
<li><span typeof="mw:Nowiki mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;nowiki>foo-{bar}bat&lt;/nowiki>"}},"i":0}}]}'>foo-{bar}bat</span></li>
<li><pre typeof="mw:Extension/pre" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"foo-{bar}bat"}}'>foo-{bar}bat</pre></li>
<li><pre typeof="mw:Extension/pre mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;pre>foo-{bar}bat&lt;/pre>"}},"i":0}}]}'>foo-{bar}bat</pre></li>
</ul>
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"foo-{bar}bat"}}'></pre> <pre typeof="mw:Extension/tag mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tag>foo-{bar}bat&lt;/tag>"}},"i":0}}]}'></pre>
!! end

!! test
Preprocessor precedence 13: broken language converter in external link
!! options
parsoid=wt2html
!! wikitext
*[http://example.com/-{foo Example in URL]
*[http://example.com Example in -{link} description]
*{{1x|[http://example.com/-{foo Breaks template, however]}}
!! html/php+tidy
<ul><li><a rel="nofollow" class="external text" href="http://example.com/-{foo">Example in URL</a></li>
<li><a rel="nofollow" class="external text" href="http://example.com">Example in -{link} description</a></li>
<li>{{1x|<a rel="nofollow" class="external text" href="http://example.com/-{foo">Breaks template, however</a>}}</li></ul>
!! html/parsoid
<ul>
<li><a rel="mw:ExtLink" href="http://example.com/-{foo" class="external text">Example in URL</a></li>
<li><a rel="mw:ExtLink" href="http://example.com" class="external text">Example in -{link} description</a></li>
<li>{{1x|<a rel="mw:ExtLink" href="http://example.com/-{foo" class="external text">Breaks template, however</a>}}</li>
</ul>
!! end

!! test
Preprocessor precedence 14: broken language converter in comment
!! wikitext
*<!--{{foo}}-->...should be ok
*<!---{{foo}}-->...extra dashes
*{{1x|foo<!-- -{bar} -->bat}}...should be ok
!! html/php+tidy
<ul><li>...should be ok</li>
<li>...extra dashes</li>
<li>foobat...should be ok</li></ul>
!! html/parsoid
<ul><li data-parsoid="{}"><!--{{foo}}-->...should be ok</li>
<li data-parsoid="{}"><!--&#x2D;{{foo}}-->...extra dashes</li>
<li data-parsoid="{}"><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;!-- -{bar} -->bat"}},"i":0}}]}'>foo</span><span about="#mwt1"><!-- &#x2D;{bar} --></span><span about="#mwt1">bat</span>...should be ok</li></ul>
!! end

!! test
Preprocessor precedence 15: broken brace markup in headings
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! options
parsoid=wt2html
!! wikitext
__NOTOC__ __NOEDITSECTION__
===1 foo[bar 1===
1
===2 foo[[bar 2===
2
===3 foo{bar 3===
3
===4 foo{{bar 4===
4
===5 foo{{{bar 5===
5
===6 foo-{bar 6===
6
!! html/php+tidy
<h3><span id="1_foo.5Bbar_1"></span><span class="mw-headline" id="1_foo[bar_1">1 foo[bar 1</span></h3>
<p>1
</p>
<h3><span id="2_foo.5B.5Bbar_2"></span><span class="mw-headline" id="2_foo[[bar_2">2 foo[[bar 2</span></h3>
<p>2
</p>
<h3><span id="3_foo.7Bbar_3"></span><span class="mw-headline" id="3_foo{bar_3">3 foo{bar 3</span></h3>
<p>3
</p>
<h3><span id="4_foo.7B.7Bbar_4"></span><span class="mw-headline" id="4_foo{{bar_4">4 foo{{bar 4</span></h3>
<p>4
</p>
<h3><span id="5_foo.7B.7B.7Bbar_5"></span><span class="mw-headline" id="5_foo{{{bar_5">5 foo{{{bar 5</span></h3>
<p>5
</p>
<h3><span id="6_foo-.7Bbar_6"></span><span class="mw-headline" id="6_foo-{bar_6">6 foo-{bar 6</span></h3>
<p>6
</p>
!! html/parsoid
<meta property="mw:PageProp/notoc"/> <meta property="mw:PageProp/noeditsection"/>
<h3 id="1_foo[bar_1"><span id="1_foo.5Bbar_1" typeof="mw:FallbackId"></span>1 foo[bar 1</h3>
<p>1</p>
<h3 id="2_foo[[bar_2"><span id="2_foo.5B.5Bbar_2" typeof="mw:FallbackId"></span>2 foo[[bar 2</h3>
<p>2</p>
<h3 id="3_foo{bar_3"><span id="3_foo.7Bbar_3" typeof="mw:FallbackId"></span>3 foo{bar 3</h3>
<p>3</p>
<h3 id="4_foo{{bar_4"><span id="4_foo.7B.7Bbar_4" typeof="mw:FallbackId"></span>4 foo{{bar 4</h3>
<p>4</p>
<h3 id="5_foo{{{bar_5"><span id="5_foo.7B.7B.7Bbar_5" typeof="mw:FallbackId"></span>5 foo{{{bar 5</h3>
<p>5</p>
<h3 id="6_foo-{bar_6"><span id="6_foo-.7Bbar_6" typeof="mw:FallbackId"></span>6 foo-{bar 6</h3>
<p>6</p>
!! end

!! test
Preprocessor precedence 16: matching closing braces to opening braces
!! options
language=zh
parsoid=wt2html
!! wikitext
-{{{1x|foo}}bar}-
!! html/php
<p>foobar
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"foo\"}},\"i\":0}}]}&#39;>foo&lt;/span>bar"}}'></span></p>
!! end

!! test
Preprocessor precedence 17: template w/o target shouldn't prevent closing
!! options
parsoid=wt2html
!! wikitext
{{1x|hi {{}}}}
!! html/php
<p>hi {{}}
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi {{}}"}},"i":0}}]}'>hi {{}}</span></p>
!! end

# Ensure we're using a language without variants for this test; even
# if $wgUsePigLatinVariant is true.  We've picked `de` arbitrarily.
!! test
Preprocessor precedence 18: another rightmost wins scenario
!! options
parsoid=wt2html
language=de
!! wikitext
{{ -{{{{1|tplarg}}} }} }-
!! html/php
<p>{{ -{tplarg }} }-
</p>
!! html/parsoid
<p>{{ -{<span about="#mwt1" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"1"},"params":{"1":{"wt":"tplarg"}},"i":0}}]}'>tplarg</span> }} }-</p>
!! end

!! test
Preprocessor precedence 19: break syntax
!! options
parsoid=wt2html
!! wikitext
-{{
!! html/php
<p>-{{
</p>
!! html/parsoid
<p>-{{</p>
!! end

## Regression test for Parsoid
!! test
Language converter over extlink
!! wikitext
{{1x
| [-{oh no]}-]
}}
!! html/php
<pre>[-{oh no]}-]
</pre>
!! html/parsoid
<pre about="#mwt1" typeof="mw:Transclusion" data-parsoid='{}' data-mw='{"parts":[{"template":{"target":{"wt":"1x\n","href":"./Template:1x"},"params":{"1":{"wt":" [-{oh no]}-]\n"}},"i":0}}]}'>[-{oh no]}-]</pre><span about="#mwt1">
</span>
!! end

###
### Token Stream Patcher tests
###
### These tests won't always pass wt2wt and other modes because
### on serialization, the table will be output on a new line.
### For now, we are prohibiting them, and using this to test selser.
###

!!test
1. Table tag in SOL posn. should get reparsed correctly with valid TSR
!!options
parsoid=wt2html,wt2wt
!!wikitext
{{1x|}}{| width = '100%'
|foo
|}
!!html/parsoid
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":""}},"i":0}}]}'></span><table width="100%">
<tbody><tr><td>foo</td></tr>
</tbody></table>
!!end

## We used to, but no longer wt2wt this test since the default serializer
## will normalize the include directives to serialize on their own line.
## Selser will take care of preserving formatting in scenarios where they
## intermingled with other wikitext.
!!test
2. Table tag in SOL posn. should get reparsed correctly with valid TSR
!!options
parsoid=wt2html
!!wikitext
<includeonly>a</includeonly>{| {{{b}}}
|c
|}
!!html/parsoid
<meta typeof="mw:Includes/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>a&lt;/includeonly>"}' data-mw='{"src":"&lt;includeonly>a&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><table about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"a":{"{{{b}}}":null},"sa":{"{{{b}}}":""}}' data-mw='{"attribs":[[{"txt":"{{{b}}}","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Param\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[31,38,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"templatearg\":{\"target\":{\"wt\":\"b\"},\"params\":{},\"i\":0}}]}&#39;>{{{b}}}&lt;/span>"},{"html":""}]]}'>
<tbody><tr><td>c</td></tr>
</tbody></table>
!!end

!! test
Table wikitext syntax outside wiki-tables
!! wikitext
a
|+ not a caption
! not a table heading
|- not a table row
| not a table cell
| class="foo bar" | baz
b
|}
|-
c
!! html
<p>a
|+ not a caption
! not a table heading
|- not a table row
| not a table cell
| class="foo bar" | baz
b
|}
|-
c
</p>
!! end

###
### Testing parsing of templates where a template arg
### has the same name as the template itself.
###

!! article
Template:quote
!! text
{{{quote|{{{1}}}}}}
!! endarticle

!!test
Templates: Template Name/Arg clash: 1. Use of positional param
!! wikitext
{{quote|foo}}
!! html/php
<p>foo
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"quote","href":"./Template:Quote"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
!!end

!!test
Templates: Template Name/Arg clash: 2. Use of named param
!! wikitext
{{quote|quote=foo}}
!! html/php
<p>foo
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"quote","href":"./Template:Quote"},"params":{"quote":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
!!end

###
### Parsoid-centric tests to stress Parsoid's ability to RT them unchanged
###

!!test
Templates: 1. Simple use
!! wikitext
{{1x|Foo}}
!! html
<p>Foo
</p>
!!end

!!test
Templates: 2. Inside a block tag
!! wikitext
<div>{{1x|Foo}}</div>
<blockquote>{{1x|Foo}}</blockquote>
!! html+untidy
<div>Foo</div>
<blockquote>Foo</blockquote>
!! html+tidy
<div>Foo</div>
<blockquote><p>Foo</p></blockquote>
!!end

!!test
Templates: P-wrapping: 1a. Templates on consecutive lines
!! wikitext
{{1x|Foo}}
{{1x|bar}}
!! html
<p>Foo
bar
</p>
!!end

!!test
Templates: P-wrapping: 1b. Templates on consecutive lines
!! wikitext
Foo

{{1x|bar}}
{{1x|baz}}
!! html
<p>Foo
</p><p>bar
baz
</p>
!!end

!!test
Templates: P-wrapping: 1c. Templates on consecutive lines
!! wikitext
{{1x|Foo}}
{{1x|bar}} <div>baz</div>
!! html+untidy
<p>Foo
</p>
bar <div>baz</div>
!! html+tidy
<p>Foo
</p><p>
bar </p><div>baz</div>
!! end

!! test
Templates: P-wrapping: 1d. Template preceded by comment-only line
!! wikitext
<!-- foo -->
{{1x|Bar}}
!! html/php+tidy
<p>Bar
</p>
!! html/parsoid
<!-- foo -->

<p><span about="#mwt223" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Bar"}},"i":0}}]}'>Bar</span></p>
!!end

!! test
Templates: Scopes should not be expanded unnecessarily
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{1x|<div>a</div>}}b{{1x|
<div>c</div>}}
!! html/php+tidy
<div>a</div><p>b
</p><div>c</div>
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>a&lt;/div>"}},"i":0}}]}'>a</div><p>b</p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n&lt;div>c&lt;/div>"}},"i":0}}]}'>
</span><div about="#mwt2">c</div>
!! end

!!test
Templates: Inline Text: 1. Multiple template uses
!! wikitext
{{1x|Foo}}bar{{1x|baz}}
!! html
<p>Foobarbaz
</p>
!!end

!!test
Templates: Inline Text: 2. Back-to-back template uses
!! wikitext
{{1x|Foo}}{{1x|bar}}
!! html
<p>Foobar
</p>
!!end

!!test
Templates: Block Tags: 1. Multiple template uses
!! wikitext
{{1x|<div>Foo</div>}}<div>bar</div>{{1x|<div>baz</div>}}
!! html
<div>Foo</div><div>bar</div><div>baz</div>
!!end

!!test
Templates: Block Tags: 2. Back-to-back template uses
!! wikitext
{{1x|<div>Foo</div>}}{{1x|<div>bar</div>}}
!! html
<div>Foo</div><div>bar</div>
!!end

## Parsoid drops empty elements in templates.
!! test
Templates: Correctly encapsulate templates producing </p> tag without a corresponding <p> tag
!! wikitext
{{1x|a
b</p>}}
!! html/php+tidy
<p>a
</p><p>
b</p><p class="mw-empty-elt"></p>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\nb&lt;/p>"}},"i":0}}]}'>a</p><span about="#mwt1">
</span><p about="#mwt1">b</p>
!! end

!! test
Drop stripped tag markers, unless they have encapsulation info
!! wikitext
{{1x|<tr></tr>}}
!! html/php

!! html/parsoid
<meta typeof="mw:Transclusion mw:Placeholder/StrippedTag" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tr>&lt;/tr>"}},"i":0}}]}'/>
!! end

!!test
Templates: Links: 1. Simple example
!! wikitext
{{1x|[[Foo|bar]]}}
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

!!test
Templates: Links: 2. Generation of link href
!! wikitext
[[{{1x|Foo}}|bar]]
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

!!test
Templates: Links: 3. Generation of part of a link href
!! wikitext
[[Fo{{1x|o}}|bar]]

[[Foo{{1x|bar}}]]

[[Foo{{1x|bar}}baz]]

[[Foo{{1x|bar}}|bar]]

[[:Foo{{1x|bar}}]]

[[:Foo{{1x|bar}}|bar]]
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p><p><a href="/index.php?title=Foobar&amp;action=edit&amp;redlink=1" class="new" title="Foobar (page does not exist)">Foobar</a>
</p><p><a href="/index.php?title=Foobarbaz&amp;action=edit&amp;redlink=1" class="new" title="Foobarbaz (page does not exist)">Foobarbaz</a>
</p><p><a href="/index.php?title=Foobar&amp;action=edit&amp;redlink=1" class="new" title="Foobar (page does not exist)">bar</a>
</p><p><a href="/index.php?title=Foobar&amp;action=edit&amp;redlink=1" class="new" title="Foobar (page does not exist)">Foobar</a>
</p><p><a href="/index.php?title=Foobar&amp;action=edit&amp;redlink=1" class="new" title="Foobar (page does not exist)">bar</a>
</p>
!!end

!!test
Templates: Links: 4. Multiple templates generating link href
!! wikitext
[[{{1x|F}}{{1x|o}}ob{{1x|ar}}]]
!! html
<p><a href="/index.php?title=Foobar&amp;action=edit&amp;redlink=1" class="new" title="Foobar (page does not exist)">Foobar</a>
</p>
!!end

!!test
Templates: Links: 5. Generation of link text
!! wikitext
[[Foo|{{1x|bar}}]]
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

!!test
Templates: Links: 5. Nested templates (only outermost template should be marked)
!! wikitext
{{1x|[[{{1x|Foo}}|bar]]}}
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

!! test
File with template filename
!! wikitext
[[File:{{1x|Foobar.jpg}}]]
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"href"},{"html":"File:&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"Foobar.jpg\"}},\"i\":0}}]}&apos;>Foobar.jpg&lt;/span>"}]]}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://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:{{1x|Foobar.jpg}}"}}'/></a></span></p>
!! end

!!test
Templates: HTML Tag: 1. Generation of HTML attr. key
!! wikitext
<div {{1x|style}}="color:red;">foo</div>
!! html
<div style="color:red;">foo</div>
!!end

!!test
Templates: HTML Tag: 2. Generation of HTML attr. value
!! wikitext
<div style={{1x|'color:red;'}}>foo</div>
!! html
<div style="color:red;">foo</div>
!!end

!!test
Templates: HTML Tag: 3. Generation of HTML attr key and value
!! wikitext
<div {{1x|style}}={{1x|'color:red;'}}>foo</div>
!! html
<div style="color:red;">foo</div>
!!end

!!test
Templates: HTML Tag: 4. Generation of starting piece of HTML attr value
!! wikitext
<div title="{{1x|This is a long title}} with just one piece templated">foo</div>
!! html
<div title="This is a long title with just one piece templated">foo</div>
!!end

!!test
Templates: HTML Tag: 5. Generation of middle piece of HTML attr value
!! wikitext
<div title="This is a long title with just {{1x|one piece}} templated">foo</div>
!! html
<div title="This is a long title with just one piece templated">foo</div>
!!end

!!test
Templates: HTML Tag: 6. Generation of end piece of HTML attr value
!! wikitext
<div title="This is a long title with just one piece {{1x|templated}}">foo</div>
!! html
<div title="This is a long title with just one piece templated">foo</div>
!!end

# SSS FIXME: While it is great we added support for all this,
# do we want to make this part of the spec? Maybe we want to
# deprecate this kind of usage in the future?
!!test
Templates: HTML Tag: 7. Generation of partial attribute key string
!! wikitext
<div st{{1x|yle}}="color:red;">foo</div>
!! html
<div style="color:red;">foo</div>
!!end

!! test
Templates: HTML Tag: 8. Template-generated attribute (k=v)
!! wikitext
<div {{1x|1=id="v1"}}>bar</div>
!! html
<div id="v1">bar</div>
!!end

!! test
Templates: HTML Tag: 9. Multiple template-generated attributes
!! wikitext
<div {{1x|1=id="v1" title="foo"}}>bar</div>
!! html
<div id="v1" title="foo">bar</div>
!!end

!! test
Templates: Support for templates generating attributes and content
!! wikitext
{| {{mixed_attr_content_template}}
|-
|bar
|}
!! html/php
<table style="color:red;" title="T48811">

<tbody><tr>
<td>foo
</td></tr>
<tr>
<td>bar
</td></tr></tbody></table>
!! html/parsoid
<table style="color:red;" title="T48811" about="#mwt1" typeof="mw:Transclusion mw:ExpandedAttrs" data-mw='{"parts":["{| ",{"template":{"target":{"wt":"mixed_attr_content_template","href":"./Template:Mixed_attr_content_template"},"params":{},"i":0}},"\n|-\n|bar\n|}"]}'>
<tbody><tr>
<td>foo</td></tr>
<tr>
<td>bar</td></tr>
</tbody></table>
!!end

!! test
Templates: Support for templates generating table attributes and content (with fostered categories)
!! wikitext
{| {{mixed_attr_content_template_2}}
|-
|bar
|}
!! html/php
<table style="color:red;" title="T249740">
<tbody><tr>
<td>foo
</td></tr>
<tr>
<td>bar
</td></tr></tbody></table>
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Fostered_Content" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:Fostered_Content"},"sa":{"href":"Category:Fostered Content"},"pi":[[]],"firstWikitextNode":"TABLE"}' data-mw='{"parts":["{| ",{"template":{"target":{"wt":"mixed_attr_content_template_2","href":"./Template:Mixed_attr_content_template_2"},"params":{},"i":0}},"\n|-\n|bar\n|}"]}'/><table style="color:red;" title="T249740" about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"style","html":"style=\"color:red;\" title=\"T249740\"","uneditable":true},{"html":""}]]}'>
<tbody><tr>

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

!! article
Template:attribute_from_template
!! text
class="123"
!! endarticle

!! test
Table cell with attribute before expanded attribute
!! wikitext
{|
| align="center" {{attribute_from_template}} |456
|}
!! html/parsoid
<table>
<tbody><tr><td align="center" class="123" about="#mwt2" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"class","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[]],\"dsr\":[20,47,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"attribute_from_template\",\"href\":\"./Template:Attribute_from_template\"},\"params\":{},\"i\":0}}]}&apos;>class=\"123\"&lt;/span>"},{"html":""}]]}'>456</td></tr>
</tbody></table>
!! end

!! test
1. Entities and nowikis inside templated attributes should be handled correctly
!! wikitext
<div {{1x|style{{=}}"background:&#35;f9f9f9;"}}>foo</div>
!! html/php
<div style="background:#f9f9f9;">foo</div>
!! html/parsoid
<div style="background:#f9f9f9;" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html"}' data-mw='{"attribs":[[{"txt":"style","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"style{{=}}\\\"background:&amp;amp;#35;f9f9f9;\\\"\"}},\"i\":0}}]}&#39;>style&lt;/span>&lt;span typeof=\"mw:Nowiki\" about=\"#mwt1\" data-parsoid=\"{}\">=&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">\"background:&lt;/span>&lt;span typeof=\"mw:Entity\" about=\"#mwt1\" data-parsoid=&#39;{\"src\":\"&amp;amp;#35;\",\"srcContent\":\"#\"}&#39;>#&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">f9f9f9;\"&lt;/span>"},{"html":""}]]}'>foo</div>
!! end

!! test
2. Entities and nowikis inside templated attributes should be handled correctly
!! wikitext
{|
|{{table_attribs_3}}
|}
!! html/php
<table>
<tbody><tr>
<td style="background:#f9f9f9;">Foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td style="background:#f9f9f9;" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"pi":[[]]}' data-mw='{"parts":["|",{"template":{"target":{"wt":"table_attribs_3","href":"./Template:Table_attribs_3"},"params":{},"i":0}}]}'>Foo</td></tr>
</tbody></table>
!! end

!! test
3. Entities and nowikis inside templated attributes should be handled correctly inside templated tables
!! wikitext
{{tbl-start}}
|{{table_attribs_3}}
{{tbl-end}}
!! html/php
<table>
<tbody><tr>
<td style="background:#f9f9f9;">Foo
</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|",{"template":{"target":{"wt":"table_attribs_3","href":"./Template:Table_attribs_3"},"params":{},"i":1}},"\n",{"template":{"target":{"wt":"tbl-end","href":"./Template:Tbl-end"},"params":{},"i":2}}]}'>
<tbody><tr><td style="background:#f9f9f9;">Foo</td></tr>
</tbody></table>
!! end

# T107622
!! test
4. Entities and nowikis inside templated attributes should be handled correctly inside templated tables
!! wikitext
{|
|{{table_attribs_6}} hi
|}
!! html/php
<table>
<tbody><tr>
<td style="background: red;">hi
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td style="background:  red;" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"pi":[[]]}' data-mw='{"parts":["|",{"template":{"target":{"wt":"table_attribs_6","href":"./Template:Table_attribs_6"},"params":{},"i":0}}," hi"]}'> hi</td></tr>
</tbody></table>
!! end

!! test
Extension tag in templated tag attribute
!! wikitext
{{1x|1=
{{{!}} class="123" <nowiki />
{{!}} hi
{{!}}}
}}
!! html/php
<table class="123">
<tbody><tr>
<td>hi
</td></tr></tbody></table>
!! html/parsoid
<table class="123" about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"startTagSrc":"{{{!}}","a":{"&lt;nowiki />":null},"sa":{"&lt;nowiki />":""},"pi":[[{"k":"1","named":true,"spc":["","","\n","\n"]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{{!}} class=\"123\" &lt;nowiki />\n{{!}} hi\n{{!}}}"}},"i":0}}]}'>
<tbody><tr><td>hi</td></tr>
</tbody></table>
!! end

!!test
Templates: HTML Tables: 1. Generating start of a HTML table
!! wikitext
{{1x|<table><tr><td>foo</td>}}</tr></table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!!end

!!test
Templates: HTML Tables: 2a. Generating middle of a HTML table
!! wikitext
<table><tr>{{1x|<td>foo</td>}}</tr></table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!!end

!!test
Templates: HTML Tables: 2b. Generating middle of a HTML table
!! wikitext
<table>{{1x|<tr><td>foo</td></tr>}}</table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!!end

!!test
Templates: HTML Tables: 3. Generating end of a HTML table
!! wikitext
<table><tr>{{1x|<td>foo</td></tr></table>}}
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! end

!!test
Templates: HTML Tables: 4a. Generating a single tag of a HTML table
!! wikitext
{{1x|<table>}}<tr><td>foo</td></tr></table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! end

!!test
Templates: HTML Tables: 4b. Generating a single tag of a HTML table
!! wikitext
<table>{{1x|<tr>}}<td>foo</td></tr></table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! end

!!test
Templates: HTML Tables: 4c. Generating a single tag of a HTML table
!! wikitext
<table><tr>{{1x|<td>}}foo</td></tr></table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! end

!!test
Templates: HTML Tables: 4d. Generating a single tag of a HTML table
!! wikitext
<table><tr><td>foo{{1x|</td>}}</tr></table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! end

!!test
Templates: HTML Tables: 4e. Generating a single tag of a HTML table
!! wikitext
<table><tr><td>foo</td>{{1x|</tr>}}</table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! end

!!test
Templates: HTML Tables: 4f. Generating a single tag of a HTML table
!! wikitext
<table><tr><td>foo</td></tr>{{1x|</table>}}
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! end

!!test
Templates: HTML Tables: 5. Proper fostering of categories from inside
!!options
parsoid=wt2html,wt2wt
!! wikitext
<table>[[Category:foo1]]<tr><td>foo</td></tr></table>
<!--Two categories (T52330)-->
<table>[[Category:bar1]][[Category:bar2]]<tr><td>foo</td></tr></table>
!! html/php+tidy
<table><tbody><tr><td>foo</td></tr></tbody></table>
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Foo1"><table><tbody><tr><td>foo</td></tr></tbody></table>
<!--Two categories (T52330)-->
<link rel="mw:PageProp/Category" href="./Category:Bar1"><link rel="mw:PageProp/Category" href="./Category:Bar2"><table><tbody><tr><td>foo</td></tr></tbody></table>
!!end

## Remex doesn't account for fostered content.
!! test
Templates: Wiki Tables: 1a. Fostering of entire template content
!! wikitext
{|
{{1x|a}}
|}
!! html/php+untidy
<table>
a
<tr><td></td></tr></table>
!! html/php+tidy

a
<table><tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}},"\n|}"]}'>a</p><table about="#mwt2">

</table>
!! end

!!test
Templates: Wiki Tables: 1b. Fostering of entire template content
!! wikitext
{|
{{1x|<div>}}
foo
{{1x|</div>}}
|}
!! html+untidy
<table>
<div>
<p>foo
</p>
</div>
<tr><td></td></tr></table>
!! html/php+tidy
<div>
<p>foo
</p>
</div><table>

<tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<div about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"stx":"html","fostered":true,"autoInsertedEnd":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}],[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>"}},"i":0}},"\nfoo\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/div>"}},"i":1}},"\n|}"]}'>
<p>foo</p>
</div><table about="#mwt3">

</table>
!! end

## Remex doesn't account for fostered content.
!! test
Templates: Wiki Tables: 2. Fostering of partial template content
!! wikitext
{|
{{1x|a
<div>b</div>}}
|}
!! html/php+untidy
<table>
a
<div>b</div>
<tr><td></td></tr></table>
!! html/php+tidy

a
<div>b</div><table>
<tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\n&lt;div>b&lt;/div>"}},"i":0}},"\n|}"]}'>a</p><div about="#mwt2">b</div><table about="#mwt2">


</table>
!! end

!!test
Templates: Wiki Tables: 3. td-content via multiple templates
!! wikitext
{|
{{1x|{{pipe}}a}}{{1x|b}}
|}
!! html
<table>
<tbody><tr>
<td>ab
</td></tr></tbody></table>
!! end

!!test
Templates: Wiki Tables: 4. Templated tags, no content
!! wikitext
{{tbl-start}}
{{tbl-end}}
!! html/php
<table>
<tbody><tr><td></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",{"template":{"target":{"wt":"tbl-end","href":"./Template:Tbl-end"},"params":{},"i":1}}]}'>
</table>
!! end

!!test
Templates: Wiki Tables: 5. Templated tags, regular td-tags
!! wikitext
{{tbl-start}}
|foo
{{tbl-end}}
!! html
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! end

!!test
Templates: Wiki Tables: 6. Templated tags, templated td-tags
!! wikitext
{{tbl-start}}
{{!}}foo
{{tbl-end}}
!! html
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! end

## This test case is very specific to Parsoid's internals
## and is hence only tested for Parsoid's code. Parsoid uses
## a <meta> marker tag for <ref> tags and they are expanded
## much later. We are verifying that this <meta> tag usage
## doesn't prevent foster parenting.
!! test
Templates: Wiki Tables: 7. Fosterable <ref>s should get fostered
!! wikitext
{{PartialTable}}<ref>foo</ref>
|}

<references />
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"PartialTable","href":"./Template:PartialTable"},"params":{},"i":0}},"&lt;ref>foo&lt;/ref>\n|}"]}'><sup about="#mwt3" class="mw-ref reference" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-1"}}'><a href="./Parser_test#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup></p><table about="#mwt2">
<tbody>
</tbody></table>

<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="./Parser_test#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">foo</span></li></ol>
!! end

!!article
Template:UnclosedTableEndsWithTR
!!text
{|
|-
!!endarticle

!! test
Templates: Wiki Tables: 8. Fosterable meta-tags should get fostered
!! wikitext
{{UnclosedTableEndsWithTR}}
<onlyinclude>
|foo
</onlyinclude>
|}

<noinclude>
{{UnclosedTableEndsWithTR}}
</noinclude>
|foo
|}
!! html/parsoid
<meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"UnclosedTableEndsWithTR","href":"./Template:UnclosedTableEndsWithTR"},"params":{},"i":0}},"\n&lt;onlyinclude>\n|foo\n&lt;/onlyinclude>\n|}"]}'/><table about="#mwt1">

<tbody><tr>

<td>foo
<meta typeof="mw:Includes/OnlyInclude/End"/></td></tr>
</tbody></tbody></table>

<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<meta typeof="mw:Transclusion mw:Includes/NoInclude/End" about="#mwt2" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"UnclosedTableEndsWithTR","href":"./Template:UnclosedTableEndsWithTR"},"params":{},"i":0}},"\n&lt;/noinclude>\n|foo\n|}"]}'/><table about="#mwt2">
<tbody><tr>

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

!!test
Templates: Lists: Multi-line list-items via templates
!! wikitext
*{{1x|a {{nonexistent|
unused}}}}
*{{1x|b {{nonexistent|
unused}}}}
!! html
<ul><li>a <a href="/index.php?title=Template:Nonexistent&amp;action=edit&amp;redlink=1" class="new" title="Template:Nonexistent (page does not exist)">Template:Nonexistent</a></li>
<li>b <a href="/index.php?title=Template:Nonexistent&amp;action=edit&amp;redlink=1" class="new" title="Template:Nonexistent (page does not exist)">Template:Nonexistent</a></li></ul>
!!end

!!test
Templates: Ugly nesting: 1. Quotes opened/closed across templates (1x)
!! wikitext
{{1x|''a}}{{1x|b''c''d}}{{1x|''e}}
!! html
<p><i>ab</i>c<i>d</i>e
</p>
!!end

## Legacy parser generates misnested html
!! test
Templates: Ugly nesting: 2. Quotes opened/closed across templates (1x_with_span)
!! wikitext
{{1x_with_span|''a}}{{1x_with_span|b''c''d}}{{1x_with_span|''e}}
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x_with_span","href":"./Template:1x_with_span"},"params":{"1":{"wt":"&apos;&apos;a"}},"i":0}}]}'><i>a</i></span><i about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"autoInsertedStart":true,"pi":[[{"k":"1"}],[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x_with_span","href":"./Template:1x_with_span"},"params":{"1":{"wt":"b&apos;&apos;c&apos;&apos;d"}},"i":0}},{"template":{"target":{"wt":"1x_with_span","href":"./Template:1x_with_span"},"params":{"1":{"wt":"&apos;&apos;e"}},"i":1}}]}'><span>b</span></i><span about="#mwt2">c</span><i about="#mwt2">d<span></span></i><span about="#mwt2">e</span></p>
!! end

## Legacy parser generates misnested html; Parsoid html2wt mode adds newlines between {{1x}}s
!! test
Templates: Ugly nesting: 3. Quotes opened/closed across templates (1x_with_div)
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{1x_with_div|''a}}{{1x_with_div|b''c''d}}{{1x_with_div|''e}}
!! html/php+tidy
<div><i>a</i></div><div><i>b</i>c<i>d</i></div><div>e</div>
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x_with_div","href":"./Template:1x_with_div"},"params":{"1":{"wt":"&apos;&apos;a"}},"i":0}}]}'><i>a</i></div>
<div about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x_with_div","href":"./Template:1x_with_div"},"params":{"1":{"wt":"b&apos;&apos;c&apos;&apos;d"}},"i":0}}]}'><i>b</i>c<i>d</i></div>
<div about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x_with_div","href":"./Template:1x_with_div"},"params":{"1":{"wt":"&apos;&apos;e"}},"i":0}}]}'>e</div>
!! end

!! test
Templates: Ugly nesting: 4. Divs opened/closed across templates
!! wikitext
a<div>b{{1x|c</div>d}}e
!! html+untidy
a<div>bc</div>de
!! html+tidy
<p>a</p><div>bc</div><p>de</p>
!! end

!! test
Templates: Ugly templates: 3. newline-only template parameter
!! wikitext
foo {{1x|
}}
!! html
<p>foo 
</p>
!! end

# This looks like a bug: a single newline triggers p/br for some reason.
!! test
Templates: Ugly templates: 4. newline-only template parameter inconsistency
!! wikitext
{{1x|
}}
!! html
<p><br />
</p>
!! end

# T66017 -- ugly wikitext with fostered content generates two template ranges that
# have a true overlap (T1-start - T2-start - T1-end - T2-end).
!! test
Templates: Ugly templates: 5. Template encapsulation test: Non-trivial overlap of template ranges is properly handled
!! wikitext
{{1x|<table>}}
{{1x|<div>foo}}
{{1x|</table>}}
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>"}},"i":0}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>foo"}},"i":1}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/table>"}},"i":2}}]}'>foo</div><span about="#mwt1">
</span><table about="#mwt1">
</table>
!! end

# T66017 -- ugly wikitext with fostered content generates two template ranges
# that are "identical" and generate nesting cycles in the algorithm
!! test
Templates: Ugly templates: 6. Template encapsulation test: Cyclical nesting of template ranges is properly handled
!! wikitext
{{1x|<table><tr><td><table>}}
{{1x|<div>}}
{{1x|</div>}}
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>&lt;tr>&lt;td>&lt;table>"}},"i":0}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>"}},"i":1}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/div>"}},"i":2}}]}' data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]]}'><tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'><div data-parsoid='{"stx":"html"}'>
</div><table about="#mwt1" data-parsoid='{"stx":"html"}'>
</table></td></tr></tbody></table>
!! end

!! test
Templates: Parameters substituted at the top-level
!! wikitext
{{{foo|''who'' {{1x|me}}? '''never!'''}}}

{{{foo|bar|baz}}}
!! html/php
<p><i>who</i> me? <b>never!</b>
</p><p>bar
</p>
!! html/parsoid
<p about="#mwt2" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"foo"},"params":{"1":{"wt":"&#39;&#39;who&#39;&#39; {{1x|me}}? &#39;&#39;&#39;never!&#39;&#39;&#39;"}},"i":0}}]}'><i>who</i> me? <b>never!</b></p>

<p about="#mwt3" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"foo"},"params":{"1":{"wt":"bar"},"2":{"wt":"baz"}},"i":0}}]}'>bar</p>
!! end

!! test
Templates: Param with empty arg in the final position
!! wikitext
{{{hi|}}}
!! html/parsoid
<span about="#mwt1" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"hi"},"params":{"1":{"wt":""}},"i":0}}]}'></span>
!! end

!!test
Parser Functions: 1. Simple example
!! wikitext
{{uc:foo}}
!! html
<p>FOO
</p>
!!end

!!test
Parser Functions: 2. Nested use (only outermost should be marked up)
!! wikitext
{{uc:{{lc:FOO}}}}
!! html
<p>FOO
</p>
!!end

## Note that the templates inside the references are not wrapped
!! test
Template nested in extension tag in template
!! options
title=[[Main Page]]
language=zh
!! wikitext
{{1x|hi<ref>[[ho|{{1x|hi}}]]</ref>}}
{{1x|hi<ref>[http://test.com?q={{1x|ho}}]</ref>}}
{{1x|hi<ref>-{ho|{{1x|hi}}}-</ref>}}
<references />
!! html/parsoid
<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;ref>[[ho|{{1x|hi}}]]&lt;/ref>"}},"i":0}}]}'>hi</span><sup about="#mwt2" class="mw-ref reference" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-1"}}'><a href="./Main_Page#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></sup>
<span about="#mwt8" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;ref>[http://test.com?q={{1x|ho}}]&lt;/ref>"}},"i":0}}]}'>hi</span><sup about="#mwt8" class="mw-ref reference" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-2"}}'><a href="./Main_Page#cite_note-2" style="counter-reset: mw-Ref 2;"><span class="mw-reflink-text">[2]</span></a></sup>
<span about="#mwt13" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;ref>-{ho|{{1x|hi}}}-&lt;/ref>"}},"i":0}}]}'>hi</span><sup about="#mwt13" class="mw-ref reference" id="cite_ref-3" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-3"}}'><a href="./Main_Page#cite_note-3" style="counter-reset: mw-Ref 3;"><span class="mw-reflink-text">[3]</span></a></sup></p>
<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt17" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"><a rel="mw:WikiLink" href="./Ho" title="Ho" class="new">hi</a></span></li><li about="#cite_note-2" id="cite_note-2"><a href="./Main_Page#cite_ref-2" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-2" class="mw-reference-text"><a rel="mw:ExtLink" href="http://test.com?q=ho" class="external autonumber"></a></span></li><li about="#cite_note-3" id="cite_note-3"><a href="./Main_Page#cite_ref-3" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-3" class="mw-reference-text"><span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["ho"],"t":"hi"}}'></span></span></li></ol>
!! end

###
### Pre-save transform tests
###

!! test
pre-save transform: subst:
!! options
pst
!! wikitext
{{subst:test}}
!! html/php
This is a test template
!! end

!! test
pre-save transform: normal template
!! options
pst
!! wikitext
{{test}}
!! html/php
{{test}}
!! end

!! test
pre-save transform: nonexistent template
!! options
pst
!! wikitext
{{thistemplatedoesnotexist}}
!! html/php
{{thistemplatedoesnotexist}}
!! end

!! test
pre-save transform: subst magic variables
!! options
pst
!! wikitext
{{subst:SITENAME}}
!! html/php
MediaWiki
!! end

# This is T2089, which I fixed. -- wtm
!! test
pre-save transform: subst: templates with parameters
!! options
pst
!! wikitext
{{subst:paramtest|param="something else"}}
!! html/php
This is a test template with parameter "something else"
!! end

!! article
Template:nowikitest
!! text
<nowiki>'''not wiki'''</nowiki>
!! endarticle

!! test
pre-save transform: nowiki in subst (T3188)
!! options
pst
!! wikitext
{{subst:nowikitest}}
!! html/php
<nowiki>'''not wiki'''</nowiki>
!! end

!! article
Template:commenttest
!! text
This template has <!-- a comment --> in it.
!! endarticle

!! test
pre-save transform: comment in subst (T3936)
!! options
pst
!! wikitext
{{subst:commenttest}}
!! html/php
This template has <!-- a comment --> in it.
!! end

!! test
pre-save transform: unclosed tag
!! options
pst
!! wikitext
<nowiki>'''not wiki'''
!! html/php
<nowiki>'''not wiki'''
!! end

!! test
pre-save transform: mixed tag case
!! options
pst
!! wikitext
<NOwiki>'''not wiki'''</noWIKI>
!! html/php
<NOwiki>'''not wiki'''</noWIKI>
!! end

!! test
pre-save transform: unclosed comment in <nowiki>
!! options
pst
!! wikitext
wiki<nowiki>nowiki<!--nowiki</nowiki>wiki
!! html/php
wiki<nowiki>nowiki<!--nowiki</nowiki>wiki
!!end

# Leading @ in this template definition works around a limitation
# in parsoid's parserTests which otherwise strips the <span> from the
# result (confusing it for a template wrapper)
!! article
Template:dangerous
!!text
@<span onmouseover="alert('crap')">Oh no</span>
!!endarticle

!!test
(confirming safety of fix for subst T3936)
!! wikitext
{{Template:dangerous}}
!! html
<p>@<span>Oh no</span>
</p>
!! end

!! test
pre-save transform: comment containing gallery (T7024)
!! options
pst
!! wikitext
<!-- <gallery>data</gallery> -->
!! html/php
<!-- <gallery>data</gallery> -->
!!end

!! test
pre-save transform: comment containing extension
!! options
pst
!! wikitext
<!-- <tag>data</tag> -->
!! html/php
<!-- <tag>data</tag> -->
!!end

!! test
pre-save transform: comment containing nowiki
!! options
pst
!! wikitext
<!-- <nowiki>data</nowiki> -->
!! html/php
<!-- <nowiki>data</nowiki> -->
!!end

!! test
pre-save transform: <noinclude> in subst (T5298)
!! options
pst
!! wikitext
{{subst:Includes}}
!! html/php
Foobar
!! end

!! test
pre-save transform: <onlyinclude> in subst (T5298)
!! options
pst
!! wikitext
{{subst:Includes2}}
!! html/php
Foo
!! end

!! article
Template:SubstTest
!!text
{{<includeonly>subst:</includeonly>Includes}}
!! endarticle

!! article
Template:SafeSubstTest
!! text
{{<includeonly>safesubst:</includeonly>Includes}}
!! endarticle

!! article
Template:SafeSubstSelfTest
!! text
{{safesubst:SafeSubstSelfTest}}
!! endarticle

!! test
T24297: safesubst: works during PST
!! options
pst
!! wikitext
{{subst:SafeSubstTest}}{{safesubst:SubstTest}}
!! html/php
FoobarFoobar
!! end

!! test
T24297: safesubst: works during normal parse
!! wikitext
{{SafeSubstTest}}
!! html
<p>Foobar
</p>
!! end

!! test
subst: does not work during normal parse
!! wikitext
{{SubstTest}}
!! html
<p>{{subst:Includes}}
</p>
!! end

!! test
safesubst self: does not work during normal parse - T276476
!! options
pst title=[[Template:SafeSubstSelfTest]]
!! wikitext
{{SafeSubstSelfTest}}
!! html/php
{{SafeSubstSelfTest}}
!! end

!! test
pre-save transform: context links ("pipe trick")
!! options
pst
!! wikitext
[[Article (context)|]]
[[Bar:Article|]]
[[:Bar:Article|]]
[[Bar:Article (context)|]]
[[:Bar:Article (context)|]]
[[|Article]]
[[|Article (context)]]
[[Bar:X (Y) Z|]]
[[:Bar:X (Y) Z|]]
!! html/php
[[Article (context)|Article]]
[[Bar:Article|Article]]
[[:Bar:Article|Article]]
[[Bar:Article (context)|Article]]
[[:Bar:Article (context)|Article]]
[[Article]]
[[Article (context)]]
[[Bar:X (Y) Z|X (Y) Z]]
[[:Bar:X (Y) Z|X (Y) Z]]
!! end

!! test
pre-save transform: context links ("pipe trick") with interwiki prefix
!! options
pst
!! wikitext
[[interwiki:Article|]]
[[:interwiki:Article|]]
[[interwiki:Bar:Article|]]
[[:interwiki:Bar:Article|]]
!! html/php
[[interwiki:Article|Article]]
[[:interwiki:Article|Article]]
[[interwiki:Bar:Article|Bar:Article]]
[[:interwiki:Bar:Article|Bar:Article]]
!! end

!! test
pre-save transform: context links ("pipe trick") with parens in title
!! options
pst title=[[Somearticle (context)]]
!! wikitext
[[|Article]]
!! html/php
[[Article (context)|Article]]
!! end

!! test
pre-save transform: context links ("pipe trick") with single, double-width and Arabic comma in title
!! options
pst title=[[Someplace, Somewhere]]
!! wikitext
[[|Otherplace]]
[[Otherplace, Elsewhere|]]
[[Otherplace, Elsewhere, Anywhere|]]
[[Otherplace，Elsewhere|]]
[[Otherplace، Elsewhere|]]
!! html/php
[[Otherplace, Somewhere|Otherplace]]
[[Otherplace, Elsewhere|Otherplace]]
[[Otherplace, Elsewhere, Anywhere|Otherplace]]
[[Otherplace，Elsewhere|Otherplace]]
[[Otherplace، Elsewhere|Otherplace]]
!! end

!! test
pre-save transform: context links ("pipe trick") with parens and comma
!! options
pst title=[[Someplace (IGNORED), Somewhere]]
!! wikitext
[[|Otherplace]]
[[Otherplace (place), Elsewhere|]]
!! html/php
[[Otherplace, Somewhere|Otherplace]]
[[Otherplace (place), Elsewhere|Otherplace]]
!! end

!! test
pre-save transform: context links ("pipe trick") with comma and parens
!! options
pst title=[[Who, me? (context)]]
!! wikitext
[[|Yes, you.]]
[[Me, Myself, and I (1937 song)|]]
!! html/php
[[Yes, you. (context)|Yes, you.]]
[[Me, Myself, and I (1937 song)|Me, Myself, and I]]
!! end

!! test
pre-save transform: context links ("pipe trick") with namespace
!! options
pst title=[[Ns:Somearticle]]
!! wikitext
[[|Article]]
!! html/php
[[Ns:Article|Article]]
!! end

!! test
pre-save transform: context links ("pipe trick") with namespace and parens
!! options
pst title=[[Ns:Somearticle (context)]]
!! wikitext
[[|Article]]
!! html/php
[[Ns:Article (context)|Article]]
!! end

!! test
pre-save transform: context links ("pipe trick") with namespace and comma
!! options
pst title=[[Ns:Somearticle, Context, Whatever]]
!! wikitext
[[|Article]]
!! html/php
[[Ns:Article, Context, Whatever|Article]]
!! end

!! test
pre-save transform: context links ("pipe trick") with namespace, comma and parens
!! options
pst title=[[Ns:Somearticle, Context (context)]]
!! wikitext
[[|Article]]
!! html/php
[[Ns:Article (context)|Article]]
!! end

!! test
pre-save transform: context links ("pipe trick") with namespace, parens and comma
!! options
pst title=[[Ns:Somearticle (IGNORED), Context]]
!! wikitext
[[|Article]]
!! html/php
[[Ns:Article, Context|Article]]
!! end

!! test
pre-save transform: context links ("pipe trick") with full-width parens and no space (Japanese and Chinese style, T32149)
!! options
pst
!! wikitext
[[Article（context）|]]
[[Bar:Article（context）|]]
[[:Bar:Article（context）|]]
[[|Article（context）]]
[[Bar:X（Y）Z|]]
[[:Bar:X（Y）Z|]]
!! html/php
[[Article（context）|Article]]
[[Bar:Article（context）|Article]]
[[:Bar:Article（context）|Article]]
[[Article（context）]]
[[Bar:X（Y）Z|X（Y）Z]]
[[:Bar:X（Y）Z|X（Y）Z]]
!! end

!! test
pre-save transform: context links ("pipe trick") with full-width parens and space (Japanese and Chinese style, T32149)
!! options
pst
!! wikitext
[[Article （context）|]]
[[Bar:Article （context）|]]
[[:Bar:Article （context）|]]
[[|Article （context）]]
[[Bar:X （Y） Z|]]
[[:Bar:X （Y） Z|]]
!! html/php
[[Article （context）|Article]]
[[Bar:Article （context）|Article]]
[[:Bar:Article （context）|Article]]
[[Article （context）]]
[[Bar:X （Y） Z|X （Y） Z]]
[[:Bar:X （Y） Z|X （Y） Z]]
!! end

!! test
pre-save transform: context links ("pipe trick") with parens and no space (Korean style, T32149)
!! options
pst
!! wikitext
[[Article(context)|]]
[[Bar:Article(context)|]]
[[:Bar:Article(context)|]]
[[|Article(context)]]
[[Bar:X(Y)Z|]]
[[:Bar:X(Y)Z|]]
!! html/php
[[Article(context)|Article]]
[[Bar:Article(context)|Article]]
[[:Bar:Article(context)|Article]]
[[Article(context)]]
[[Bar:X(Y)Z|X(Y)Z]]
[[:Bar:X(Y)Z|X(Y)Z]]
!! end

!! test
pre-save transform: context links ("pipe trick") with commas (T23660)
!! options
pst
!! wikitext
[[Article (context), context|]]
[[Article (context)，context|]]
[[Bar:Article (context), context|]]
[[Bar:Article (context)，context|]]
[[:Bar:Article (context), context|]]
[[:Bar:Article (context)，context|]]
!! html/php
[[Article (context), context|Article]]
[[Article (context)，context|Article]]
[[Bar:Article (context), context|Article]]
[[Bar:Article (context)，context|Article]]
[[:Bar:Article (context), context|Article]]
[[:Bar:Article (context)，context|Article]]
!! end

!! test
Parsoid: backwards pipe trick
!! wikitext
[[|'''bar''']]
!! html/php
<p>[[|<b>bar</b>]]
</p>
!! html/parsoid
<p>[[|<b>bar</b>]]</p>
!! end

!! test
pre-save transform: trim trailing empty lines
!! options
pst
!! wikitext
Empty lines are trimmed




!! html/php
Empty lines are trimmed
!! end

!! test
pre-save transform: Signature expansion
!! options
pst
!! wikitext
* ~~~
* ~~~~
* ~~~~~
* <noinclude>~~~</noinclude>
* <includeonly>~~~</includeonly>
* <onlyinclude>~~~</onlyinclude>
!! html/php
* [[Special:Contributions/127.0.0.1|127.0.0.1]]
* [[Special:Contributions/127.0.0.1|127.0.0.1]] 00:02, 1 January 1970 (UTC)
* 00:02, 1 January 1970 (UTC)
* <noinclude>[[Special:Contributions/127.0.0.1|127.0.0.1]]</noinclude>
* <includeonly>[[Special:Contributions/127.0.0.1|127.0.0.1]]</includeonly>
* <onlyinclude>[[Special:Contributions/127.0.0.1|127.0.0.1]]</onlyinclude>
!! end


!! test
ParserOutput flags from signature expansion (T84843)
!! options
pst
showflags
!! wikitext
~~~~
!! html/php
[[Special:Contributions/127.0.0.1|127.0.0.1]] 00:02, 1 January 1970 (UTC)
flags=user-signature
!! end


!! test
pre-save transform: Signature expansion in nowiki tags (T2093)
!! options
pst disabled
!! wikitext
Shall not expand:

<nowiki>~~~~</nowiki>

<includeonly><nowiki>~~~~</nowiki></includeonly>

<noinclude><nowiki>~~~~</nowiki></noinclude>

<onlyinclude><nowiki>~~~~</nowiki></onlyinclude>

{{subst:Foo}} shall be converted to FOO

As well as inside noinclude/onlyinclude
<noinclude>{{subst:Foo}}</noinclude>
<onlyinclude>{{subst:Foo}}</onlyinclude>

But not inside includeonly
<includeonly>{{subst:Foo}}</includeonly>
!! html/php
Shall not expand:

<nowiki>~~~~</nowiki>

<includeonly><nowiki>~~~~</nowiki></includeonly>

<noinclude><nowiki>~~~~</nowiki></noinclude>

<onlyinclude><nowiki>~~~~</nowiki></onlyinclude>

FOO shall be converted to FOO

As well as inside noinclude/onlyinclude
<noinclude>FOO</noinclude>
<onlyinclude>FOO</onlyinclude>

But not inside includeonly
<includeonly>{{subst:Foo}}</includeonly>
!! end

!! test
Parsoid: Recognize nowiki with trailing space in tags
!! options
parsoid=wt2html
!! wikitext
<nowiki ><div>[[foo]]</nowiki >

a<nowiki / >b

c<nowiki />d

e<nowiki/ >f
!! html/php+tidy
<p>&lt;div&gt;[[foo]]
</p><p>a&lt;nowiki / &gt;b
</p><p>cd
</p><p>e&lt;nowiki/ &gt;f
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">&lt;div>[[foo]]</span></p>

<p>a&lt;nowiki / >b</p>

<p>c<span typeof="mw:Nowiki"></span>d</p>

<p>e&lt;nowiki/ >f</p>
!! end

!! test
Parsoid: Recognize nowiki with odd capitalization
!! options
parsoid=wt2html
!! wikitext
<noWikI ><div>[[foo]]</Nowiki >
!! html/php+tidy
<p>&lt;div&gt;[[foo]]
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">&lt;div&gt;[[foo]]</span></p>
!! end


!! test
Parsoid: Escape nowiki with trailing space in tags
!! options
parsoid=html2wt
!! html/parsoid
<p>&lt;nowiki &gt; foo &lt/nowiki ></p>
<p>a&lt;nowiki /&gt;b</p>
<p>c&lt;nowiki/ &gt;d</p>
!! wikitext
&lt;nowiki &gt; foo &lt;/nowiki &gt;

a&lt;nowiki /&gt;b

c&lt;nowiki/ &gt;d
!! end

!! test
Parsoid: Escape weird noWikI capitalizations
!! options
parsoid=html2wt
!! html/parsoid
<p>&lt;noWikI &gt; foo &lt/NoWikI ></p>
!! wikitext
&lt;noWikI &gt; foo &lt;/NoWikI &gt;
!! end

###
### Message transform tests
###
!! test
message transform: magic variables
!! options
msg
!! wikitext
{{SITENAME}}
!! html
MediaWiki
!! end

!! test
message transform: should not transform wiki markup
!! options
msg
!! wikitext
''test''
!! html
''test''
!! end

!! test
message transform: <noinclude> in transcluded template (T6926)
!! options
msg
!! wikitext
{{Includes}}
!! html
Foobar
!! end

!! test
message transform: <onlyinclude> in transcluded template (T6926)
!! options
msg
!! wikitext
{{Includes2}}
!! html
Foo
!! end

!! test
{{#special:}} page name, known
!! options
msg
!! wikitext
{{#special:Recentchanges}}
!! html
Special:RecentChanges
!! end

!! test
{{#special:}} page name with subpage, known
!! options
msg
!! wikitext
{{#special:Recentchanges/param}}
!! html
Special:RecentChanges/param
!! end

!! test
{{#special:}} page name, unknown
!! options
msg
!! wikitext
{{#special:foobar nonexistent}}
!! html
Special:Foobar nonexistent
!! end

!! test
{{#speciale:}} page name, known
!! options
msg
!! wikitext
{{#speciale:Recentchanges}}
!! html
Special:RecentChanges
!! end

!! test
{{#speciale:}} page name with subpage, known
!! options
msg
!! wikitext
{{#speciale:Recentchanges/param}}
!! html
Special:RecentChanges/param
!! end

!! test
{{#speciale:}} page name, unknown
!! options
msg
!! wikitext
{{#speciale:foobar nonexistent}}
!! html
Special:Foobar_nonexistent
!! end

###
### Subpages
###

!! article
Subpage test/subpage
!! text
foo
!! endarticle

!! test
Subpage link
!! options
subpage title=[[Subpage test]]
!! wikitext
[[/subpage]]
!! html
<p><a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">/subpage</a>
</p>
!! end

!! test
Subpage noslash link
!! options
subpage title=[[Subpage test]]
!! wikitext
[[/subpage/]]
!! html
<p><a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">subpage</a>
</p>
!! end

!! article
Subpage test/1/2/subpage
!! text
blah
!! endarticle

!! test
Relative subpage noslash link
!! options
parsoid=wt2wt,wt2html,html2html
subpage title=[[Subpage test/1/2/3/4]]
!! wikitext
[[../../subpage/]]

[[../../subpage]]
!! html/php
<p><a href="/wiki/Subpage_test/1/2/subpage" title="Subpage test/1/2/subpage">subpage</a>
</p><p><a href="/wiki/Subpage_test/1/2/subpage" title="Subpage test/1/2/subpage">Subpage test/1/2/subpage</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/1/2/subpage" title="Subpage test/1/2/subpage">subpage</a></p>
<p><a rel="mw:WikiLink" href="./Subpage_test/1/2/subpage" title="Subpage test/1/2/subpage">Subpage test/1/2/subpage</a></p>
!! end

!! test
Parsoid: dot-slash prefixed wikilinks
!! wikitext
[[./foo]]

[[././bar]]

[[././baz/]]
!! html/php
<p>[[./foo]]
</p><p>[[././bar]]
</p><p>[[././baz/]]
</p>
!! html/parsoid
<p>[[./foo]]
</p><p>[[././bar]]
</p><p>[[././baz/]]
</p>
!! end

!! test
Render invalid page names as plain text (T53090)
!! wikitext
[[./../foo|bar]]
[[foo�|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~bar]]
[[foo>bar]]
[[foo[bar]]
[[.]]
[[..]]
[[foo././bar]]
[[foo[http://example.com]xyz]]

[[{{1x|./../foo}}|bar]]
[[{{1x|foo/.}}|bar]]
[[{{1x|foo/..}}|bar]]
[[{{1x|foo~~~~bar}}]]
[[{{1x|foo>bar}}]]
[[{{1x|foo././bar}}]]
[[{{1x|foo{bar}}]]
[[{{1x|foo}bar}}]]
[[{{1x|foo[bar}}]]
[[{{1x|foo]bar}}]]
[[{{1x|foo<bar}}]]
!!html/php
<p>[[./../foo|bar]]
[[foo�|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~bar]]
[[foo&gt;bar]]
[[foo[bar]]
[[.]]
[[..]]
[[foo././bar]]
[[foo<a rel="nofollow" class="external autonumber" href="http://example.com">[1]</a>xyz]]
</p><p>[[./../foo|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~~bar]]
[[foo&gt;bar]]
[[foo././bar]]
[[foo{bar]]
[[foo}bar]]
[[foo[bar]]
[[foo]bar]]
[[foo&lt;bar]]
</p>
!!html/parsoid
<p>[[./../foo|bar]]
[[foo�|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~bar]]
[[foo>bar]]
[[foo[bar]]
[[.]]
[[..]]
[[foo././bar]]
[[foo<a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a>xyz]]</p>

<p>[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"./../foo"}},"i":0}}]}'>./../foo</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo/."}},"i":0}}]}'>foo/.</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo/.."}},"i":0}}]}'>foo/..</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo~~~~bar"}},"i":0}}]}'>foo~~~~bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo>bar"}},"i":0}}]}'>foo>bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo././bar"}},"i":0}}]}'>foo././bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo{bar"}},"i":0}}]}'>foo{bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo}bar"}},"i":0}}]}'>foo}bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo[bar"}},"i":0}}]}'>foo[bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo]bar"}},"i":0}}]}'>foo]bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;bar"}},"i":0}}]}'>foo&lt;bar</span>]]</p>
!!end

!! test
Disabled subpages
!! wikitext
[[/subpage]]
!! html
<p><a href="/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a>
</p>
!! end

!! test
T2561: {{/Subpage}}
!! options
subpage title=[[Page]]
!! wikitext
{{/Subpage}}
!! html
<p><a href="/index.php?title=Page/Subpage&amp;action=edit&amp;redlink=1" class="new" title="Page/Subpage (page does not exist)">Page/Subpage</a>
</p>
!! end

!! test
Subpage with namespaces
!! options
subpage title=[[Subpage test/1/2/3/4]]
!! wikitext
[[User:../subpage]]
[[meatball:../subpage]]
!! html
<p>[[User:../subpage]]
[[meatball:../subpage]]
</p>
!! end

###
### Categories
###
!! article
Category:MediaWiki User's Guide
!! text
blah
!! endarticle

!! test
Link to category
!! wikitext
[[:Category:MediaWiki User's Guide]]
!! html
<p><a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User&#39;s Guide">Category:MediaWiki User's Guide</a>
</p>
!! end

!! test
Simple category
!! options
cat
!! wikitext
[[Category:MediaWiki User's Guide]]
!! html/php
cat=MediaWiki_User's_Guide sort=
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide" data-parsoid='{"stx":"simple","a":{"href":"./Category:MediaWiki_User&#39;s_Guide"},"sa":{"href":"Category:MediaWiki User&#39;s Guide"}}'/>
!! end

!! test
PAGESINCATEGORY invalid title fatal (r33546 fix)
!! wikitext
{{PAGESINCATEGORY:<bogus>}}
!! html
<p>0
</p>
!! end

!! test
Category with different sort key
!! options
cat
!! wikitext
[[Category:MediaWiki User's Guide|Foo]]
!! html/php
cat=MediaWiki_User's_Guide sort=Foo
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide#Foo" data-parsoid='{"stx":"piped","a":{"href":"./Category:MediaWiki_User&#39;s_Guide"},"sa":{"href":"Category:MediaWiki User&#39;s Guide"}}'/>
!! end

!! test
Category with identical sort key
!! options
cat
!! wikitext
[[Category:MediaWiki User's Guide|MediaWiki User's Guide]]
!! html/php
cat=MediaWiki_User's_Guide sort=MediaWiki User's Guide
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide#MediaWiki%20User's%20Guide" data-parsoid='{"stx":"piped","a":{"href":"./Category:MediaWiki_User&#39;s_Guide"},"sa":{"href":"Category:MediaWiki User&#39;s Guide"}}'/>
!! end

!! test
Category with newline in sort key
!! options
cat
parsoid=wt2html,html2html
!! wikitext
[[Category:Wikidata:Tools|
*]]
!! html/php
cat=Wikidata:Tools sort=*
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Wikidata:Tools#*"/>
!! end

!! test
Category with template-generated sort key
!! options
cat
!! wikitext
[[Category:MediaWiki User's Guide|MediaWiki {{1x|Foo}} Guide]]
!! html/php
cat=MediaWiki_User's_Guide sort=MediaWiki Foo Guide
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide#MediaWiki%20Foo%20Guide" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"mw:sortKey"},{"html":"MediaWiki &lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"Foo\"}},\"i\":0}}]}&apos;>Foo&lt;/span> Guide"}]]}'/>
!! end

!! test
Category with empty sort key
!! options
cat
pst
!! wikitext
[[Category:MediaWiki User's Guide|]]
!! html/php
[[Category:MediaWiki User's Guide|MediaWiki User's Guide]]
!! end

!! test
Category with empty sort key and parentheses
!! options
cat
pst
!! wikitext
[[Category:Foo (bar)|]]
!! html/php
[[Category:Foo (bar)|Foo]]
!! end

!! test
Category with link tail
!! options
cat
pst
!! wikitext
123[[Category:Foo]]456
!! html/php
123[[Category:Foo]]456
!! end

!! test
Category with template
!! options
cat
pst
!! wikitext
[[Category:{{1x|Foo}}]]
!! html/php
[[Category:{{1x|Foo}}]]
!! end

!! test
Category with template in sort key
!! options
cat
pst
!! wikitext
[[Category:Foo|{{1x|Bar}}]]
!! html/php
[[Category:Foo|{{1x|Bar}}]]
!! end

!! test
Category with template in sort key and title
!! options
cat
pst
!! wikitext
[[Category:{{1x|Foo}}|{{1x|Bar}}]]
!! html/php
[[Category:{{1x|Foo}}|{{1x|Bar}}]]
!! end

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
!! test
Category / paragraph interactions
!! options
parsoid=wt2html
!! wikitext
Foo [[Category:Baz]] Bar

Foo [[Category:Baz]]
Bar

Foo
[[Category:Baz]]
Bar

Foo
[[Category:Baz]] Bar

Foo
[[Category:Baz]]
 [[Category:Baz]]
[[Category:Baz]]
Bar

[[Category:Baz]]
 [[Category:Baz]]
[[Category:Baz]]

[[Category:Baz]]
 {{1x|[[Category:Baz]]}}
[[Category:Baz]]
!! html/php
<p>Foo Bar
</p><p>Foo
Bar
</p><p>Foo
Bar
</p><p>Foo Bar
</p><p>Foo
Bar
</p>
!! html/parsoid
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Category:Baz]]"}},"i":0}}]}'/>
<link rel="mw:PageProp/Category" href="./Category:Baz"/>
!! end

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
##
## The whitespace on the empty line is part of the test. Please do not delete
!! test
1. Categories and newlines: All preceding newlines should be suppressed (courtesy T2087)
!! options
parsoid=wt2html
!! wikitext
This
   
[[Category:Foo]] and this should be part of same paragraph (not an indent-pre)
   
{{1x|[[Category:Foo]] and so should this!}}
!! html/php
<p>This and this should be part of same paragraph (not an indent-pre) and so should this!
</p>
!! html/parsoid
<p>This
   
<link rel="mw:PageProp/Category" href="./Category:Foo"/> and this should be part of same paragraph (not an indent-pre)
   
<link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Category:Foo]] and so should this!"}},"i":0}}]}'/><span about="#mwt1"> and so should this!</span></p>
!! end

## Parsoid will not try to wt2wt this while preserving newlines because
## it suppresses excess newlines within list items -- and we don't want to
## introduce a special case just for categories, which is, in reality somewhat
## odd behavior -- categories are unlikely to be used in list items like this
## in top-level pages and are only likely to show up in template-generated
## list items where this RT-ing is a non-issue.
##
## The whitespace on the empty line is part of the test. Please do not delete
!! test
2. Categories and newlines: All preceding newlines should be suppressed (courtesy T2087)
!! options
parsoid=wt2html
!! wikitext
* This
   
[[Category:Foo]] and this should be part of the same list item
* So should this

{{1x|[[Category:Foo]] and this should be part of the same list item}}
!! html/php+tidy
<ul><li>This and this should be part of the same list item</li>
<li>So should this and this should be part of the same list item</li></ul>
!! 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":"1x","href":"./Template:1x"},"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

## Newlines and categories that follow the last item of a list
## are treated differently because this (list followed by categories)
## is an extremely common pattern on wikis.
!! test
3. Categories and newlines: newline suppression for last list item should RT properly
!! wikitext
*a
*b
   
[[Category:Foo]]
   
[[Category:Bar]]
[[Category:Baz]]

:c

[[Category:C]]

;d

[[Category:D]]
!! html/parsoid
<ul><li>a</li>
<li>b</li></ul>
   
<link rel="mw:PageProp/Category" href="./Category:Foo"/>
   
<link rel="mw:PageProp/Category" href="./Category:Bar"/>
<link rel="mw:PageProp/Category" href="./Category:Baz"/>

<dl><dd>c</dd></dl>

<link rel="mw:PageProp/Category" href="./Category:C"/>

<dl><dt>d</dt></dl>

<link rel="mw:PageProp/Category" href="./Category:D"/>
!! end

!! test
4. Categories and newlines: newline suppression for last list item should RT properly
!! wikitext
*a
****b

[[Category:Foo]]
!! html/parsoid
<ul><li>a
<ul><li><ul><li><ul><li>b</li></ul></li></ul></li></ul></li></ul>

<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/>
!! end

## only wt2html for this to make sure the algo only applies to the rightmost path
!! test
5. Categories and newlines: migrateTrailingCategories dom pass should only run on the rightmost path of nested lists
!! options
parsoid=wt2html
!! wikitext
*a
**b
[[Category:Foo]]
*c
**d
[[Category:Foo]]
!! html/parsoid
<ul><li>a
<ul><li>b
<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul></li>
<li>c
<ul><li>d</li></ul></li></ul>
<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/>
!! end

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
!! test
6. Categories and newlines: migrateTrailingCategories dom pass should not migrate categories not preceded by newlines
!! options
parsoid=wt2html
!! wikitext
*a [[Category:Foo]]
!! html/parsoid
<ul><li>a<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul>
!! end

# This test also demonstrates because of newline+category tunneling
# through the list hander, template wrapping doesn't expand to the
# containing list when the list item swallows the category.
!! test
7. Categories and newlines: migrateTrailingCategories dom pass should leave template content alone
!! wikitext
*{{1x|a
[[Category:Foo]]}}
!! html/parsoid
<ul><li><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\n[[Category:Foo]]"}},"i":0}}]}'>a
</span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul>
!! end

!! test
8. Categories and newlines: migrateTrailingCategories dom pass should not get tripped by intervening templates
!! wikitext
*a

{{1x|[[Category:Foo]]
[[Category:Bar]]}}
[[Category:Baz]]
!! html/parsoid
<ul><li>a</li></ul>

<link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Category:Foo]]\n[[Category:Bar]]"}},"i":0}}]}'/><span about="#mwt1">
</span><link rel="mw:PageProp/Category" href="./Category:Bar" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Bar"},"sa":{"href":"Category:Bar"}}'/>
<link rel="mw:PageProp/Category" href="./Category:Baz" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:Baz"}}'/>
!! end

!! test
Categories and newlines: migrateTrailingCategories dom pass should not get tripped by comments and whitespace
!! wikitext
*a

[[Category:Bar]]<!--boo1--> <!--boo2-->
[[Category:Baz]]<!--boo3--> <!--boo4-->
!! html/parsoid
<ul><li>a</li></ul>

<link rel="mw:PageProp/Category" href="./Category:Bar"/><!--boo1--> <!--boo2-->
<link rel="mw:PageProp/Category" href="./Category:Baz"/><!--boo3--> <!--boo4-->
!! end

!! test
Categories and newlines: should behave properly with linkprefix (T87753)
!! options
language=ar
!! wikitext
foo bar
foo bar
[[تصنيف:Foo]]
[[تصنيف:Bar]]
!! html/php
<p>foo bar
foo bar
</p>
!! html/parsoid
<p>foo bar
foo bar</p>
<link rel="mw:PageProp/Category" href="./تصنيف:Foo"/>
<link rel="mw:PageProp/Category" href="./تصنيف:Bar"/>
!! end

!! test
No regressions on internal links following category (T174639)
!! options
parsoid=wt2html,html2html
!! wikitext
[[Category:Foo]]<div>a

[[Foo]]</div>
!! html/php
<div>a
<a href="/wiki/Foo" title="Foo">Foo</a></div>
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Foo"/><div>a

<a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a></div>
!! end

# Note that Parsoid differs slightly from PHP due to T175421
!! test
11. Special case where only newlines separate links (T175416)
!! options
parsoid=wt2html,html2html
!! wikitext
[[Category:Foo]]

[[Foo]][[es:Alimento]]

[[Foo]]
!! html/php
<p><br />
<a href="/wiki/Foo" title="Foo">Foo</a>
</p><p><a href="/wiki/Foo" title="Foo">Foo</a>
</p>
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Foo"/>

<p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a></p><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Alimento"/>

<p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a></p>
!! end

!! test
Category links with multiple namespaces
!! wikitext
[[Category:Project:Foo]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Project:Foo" />
!! end

!! test
Parsoid: Serialize link to category page with colon escape
!! wikitext

[[:Category:Foo]]
[[:Category:Foo|Bar]]
!! html/php+tidy
<p><a href="/index.php?title=Category:Foo&amp;action=edit&amp;redlink=1" class="new" title="Category:Foo (page does not exist)">Category:Foo</a>
<a href="/index.php?title=Category:Foo&amp;action=edit&amp;redlink=1" class="new" title="Category:Foo (page does not exist)">Bar</a>
</p>
!! html/parsoid
<p>
<a rel="mw:WikiLink" href="./Category:Foo" title="Category:Foo" class="new">Category:Foo</a>
<a rel="mw:WikiLink" href="./Category:Foo" title="Category:Foo" class="new">Bar</a>
</p>
!! end

# We used to, but no longer wt2wt this test since the default serializer
# will normalize all categories to serialize on their own line.
# This wikitext usage is going to be fairly uncommon in production and
# selser will take care of preventing whitespace insertion if this
# occurs in an article.
#
# html2html disabled for the same reason (whitespace insertion between
# x and y).
#
# html2wt disabled because it localizes the "Category" namespace.
!! test
Link prefix/suffixes aren't applied to category links
!! options
parsoid=wt2html
language=is
!! wikitext
x[[Category:Foo]]y
!! html/php
<p>xy
</p>
!! html/parsoid
<p>x<link rel="mw:PageProp/Category" href="./Flokkur:Foo" data-parsoid=""/>y</p>
!! end

!! test
Link prefix/suffixes aren't applied to language links
!! options
parsoid=wt2html
language=is
!! wikitext
x[[es:Foo]]y
!! html/php
<p>xy
</p>
!! html/parsoid
<p>x<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" data-parsoid=""/>y</p>
!! end

!! test
Parsoid: Serialize link to file page with colon escape
!! wikitext

[[:File:Foo.png]]
[[:File:Foo.png|Bar]]
!! html/php+tidy
<p><a href="/index.php?title=File:Foo.png&amp;action=edit&amp;redlink=1" class="new" title="File:Foo.png (page does not exist)">File:Foo.png</a>
<a href="/index.php?title=File:Foo.png&amp;action=edit&amp;redlink=1" class="new" title="File:Foo.png (page does not exist)">Bar</a>
</p>
!! html/parsoid
<p>
<a rel="mw:WikiLink" href="./File:Foo.png" title="File:Foo.png" class="new">File:Foo.png</a>
<a rel="mw:WikiLink" href="./File:Foo.png" title="File:Foo.png" class="new">Bar</a>
</p>
!! end

!! test
Parsoid: Serialize a genuine category link without colon escape
!! wikitext
[[Category:Foo]]
[[Category:Foo|Bar]]
!! html/php+tidy
!! html/parsoid
<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 (T72894)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Toxine_bactérienne"/>
!! wikitext
[[Category:Toxine bactérienne]]
!! end

!! test
Parsoid: Defaultsort
!! wikitext
{{DEFAULTSORT:Foo}}
!! html/parsoid
<meta property="mw:PageProp/categorydefaultsort" content="Foo"/>
!! end

!! test
Parsoid: Defaultsort variations (T236846)
!! wikitext
{{DEFAULTSORT}}
{{DEFAULTSORT:}}
{{DEFAULTSORT:DOGGIE}}
!! html/parsoid
<meta property="mw:PageProp/categorydefaultsort" content="" data-parsoid='{"src":"{{DEFAULTSORT}}"}'/>
<meta property="mw:PageProp/categorydefaultsort" content="" data-parsoid='{"src":"{{DEFAULTSORT:}}"}'/>
<meta property="mw:PageProp/categorydefaultsort" content="DOGGIE" data-parsoid='{"src":"{{DEFAULTSORT:DOGGIE}}"}'/>
!! end

!! test
Parsoid: Defaultsort with key content being added (T236846)
!! options
parsoid=html2wt
!! html/parsoid
<meta property="mw:PageProp/categorydefaultsort" content="BIRD" data-parsoid='{"src":"{{DEFAULTSORT}}"}'/>
!! wikitext
{{DEFAULTSORT:BIRD}}
!! end

# NOTE: mw:ExpandedAttrs is not the best typeof here. mw:Transclusion is better.
# But, this is a limitation of our representation and is documented in
# TemplateHandler.js in processSpecialMagicWord
!! test
Parsoid: Defaultsort (template-generated)
!! wikitext
{{{{1x|DEFAULTSORT}}:Foo}}
!! html/parsoid
<meta property="mw:PageProp/categorydefaultsort" content="Foo" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"src":"{{{{1x|DEFAULTSORT}}:Foo}}"}' data-mw='{"attribs":[[{"txt":"content"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[2,22,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"DEFAULTSORT\"}},\"i\":0}}]}&#39;>DEFAULTSORT&lt;/span>:Foo"}]]}'/>
!! end

###
### Inter-language links
###
!! test
Interlanguage links
!! options
ill
!! wikitext
[[es:Alimento]]
[[fr:Nourriture]]
[[zh:食品]]
!! html/php
es:Alimento fr:Nourriture zh:食品
!! html/parsoid
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Alimento"/>
<link rel="mw:PageProp/Language" href="http://fr.wikipedia.org/wiki/Nourriture"/>
<link rel="mw:PageProp/Language" href="http://zh.wikipedia.org/wiki/食品"/>
!! end

!! test
Duplicate interlanguage links (T26502)
!! options
ill
!! wikitext
[[es:1]]
[[es:2]]
[[fr:1]]
[[fr:2]]
!! html/php
es:1 fr:1
!! html/parsoid
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/1"/>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/2"/>
<link rel="mw:PageProp/Language" href="http://fr.wikipedia.org/wiki/1"/>
<link rel="mw:PageProp/Language" href="http://fr.wikipedia.org/wiki/2"/>
!! end

###
### Sections
###
!! test
Basic section headings
!! wikitext
==Headline 1==
Some text

==Headline 2==
More
===Smaller headline===
Blah blah
!! html
<h2><span class="mw-headline" id="Headline_1">Headline 1</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: Headline 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Some text
</p>
<h2><span class="mw-headline" id="Headline_2">Headline 2</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: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>More
</p>
<h3><span class="mw-headline" id="Smaller_headline">Smaller headline</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Smaller headline">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>Blah blah
</p>
!! end

!! test
Section headings with TOC
!! wikitext
==Headline 1==
===Subheadline 1===
=====Skipping a level=====
======Skipping a level======

==Headline 2==
Some text
===Another headline===
!! html
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Headline_1"><span class="tocnumber">1</span> <span class="toctext">Headline 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Subheadline_1"><span class="tocnumber">1.1</span> <span class="toctext">Subheadline 1</span></a>
<ul>
<li class="toclevel-3 tocsection-3"><a href="#Skipping_a_level"><span class="tocnumber">1.1.1</span> <span class="toctext">Skipping a level</span></a>
<ul>
<li class="toclevel-4 tocsection-4"><a href="#Skipping_a_level_2"><span class="tocnumber">1.1.1.1</span> <span class="toctext">Skipping a level</span></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#Headline_2"><span class="tocnumber">2</span> <span class="toctext">Headline 2</span></a>
<ul>
<li class="toclevel-2 tocsection-6"><a href="#Another_headline"><span class="tocnumber">2.1</span> <span class="toctext">Another headline</span></a></li>
</ul>
</li>
</ul>
</div>

<h2><span class="mw-headline" id="Headline_1">Headline 1</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: Headline 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Subheadline_1">Subheadline 1</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: Subheadline 1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h5><span class="mw-headline" id="Skipping_a_level">Skipping a level</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Skipping a level">edit</a><span class="mw-editsection-bracket">]</span></span></h5>
<h6><span class="mw-headline" id="Skipping_a_level_2">Skipping a level</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Skipping a level">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
<h2><span class="mw-headline" id="Headline_2">Headline 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Some text
</p>
<h3><span class="mw-headline" id="Another_headline">Another headline</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Another headline">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
!! end

!! test
TOC anchors don't collide
!! wikitext
__FORCETOC__
==Headline 2==
==Headline==
==Headline 2==
==Headline==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Headline_2"><span class="tocnumber">1</span> <span class="toctext">Headline 2</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Headline"><span class="tocnumber">2</span> <span class="toctext">Headline</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Headline_2_2"><span class="tocnumber">3</span> <span class="toctext">Headline 2</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Headline_3"><span class="tocnumber">4</span> <span class="toctext">Headline</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Headline_2">Headline 2</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: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Headline">Headline</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: Headline">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Headline_2_2">Headline 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Headline_3">Headline</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Headline">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

# perl -e 'print "="x$_," Level $_ heading","="x$_,"\n" for 1..10'
# Parsoid html2wt direction adds <nowiki> for level 7 and up.
!! test
Handling of sections up to level 6 and beyond
!! options
parsoid=wt2html
!! wikitext
=Level 1 Heading=
==Level 2 Heading==
===Level 3 Heading===
====Level 4 Heading====
=====Level 5 Heading=====
======Level 6 Heading======
=======Level 7 Heading=======
========Level 8 Heading========
=========Level 9 Heading=========
==========Level 10 Heading==========
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Level_1_Heading"><span class="tocnumber">1</span> <span class="toctext">Level 1 Heading</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Level_2_Heading"><span class="tocnumber">1.1</span> <span class="toctext">Level 2 Heading</span></a>
<ul>
<li class="toclevel-3 tocsection-3"><a href="#Level_3_Heading"><span class="tocnumber">1.1.1</span> <span class="toctext">Level 3 Heading</span></a>
<ul>
<li class="toclevel-4 tocsection-4"><a href="#Level_4_Heading"><span class="tocnumber">1.1.1.1</span> <span class="toctext">Level 4 Heading</span></a>
<ul>
<li class="toclevel-5 tocsection-5"><a href="#Level_5_Heading"><span class="tocnumber">1.1.1.1.1</span> <span class="toctext">Level 5 Heading</span></a>
<ul>
<li class="toclevel-6 tocsection-6"><a href="#Level_6_Heading"><span class="tocnumber">1.1.1.1.1.1</span> <span class="toctext">Level 6 Heading</span></a></li>
<li class="toclevel-6 tocsection-7"><a href="#.3DLevel_7_Heading.3D"><span class="tocnumber">1.1.1.1.1.2</span> <span class="toctext">=Level 7 Heading=</span></a></li>
<li class="toclevel-6 tocsection-8"><a href="#.3D.3DLevel_8_Heading.3D.3D"><span class="tocnumber">1.1.1.1.1.3</span> <span class="toctext">==Level 8 Heading==</span></a></li>
<li class="toclevel-6 tocsection-9"><a href="#.3D.3D.3DLevel_9_Heading.3D.3D.3D"><span class="tocnumber">1.1.1.1.1.4</span> <span class="toctext">===Level 9 Heading===</span></a></li>
<li class="toclevel-6 tocsection-10"><a href="#.3D.3D.3D.3DLevel_10_Heading.3D.3D.3D.3D"><span class="tocnumber">1.1.1.1.1.5</span> <span class="toctext">====Level 10 Heading====</span></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

<h1><span class="mw-headline" id="Level_1_Heading">Level 1 Heading</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: Level 1 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h2><span class="mw-headline" id="Level_2_Heading">Level 2 Heading</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: Level 2 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Level_3_Heading">Level 3 Heading</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Level 3 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h4><span class="mw-headline" id="Level_4_Heading">Level 4 Heading</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Level 4 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<h5><span class="mw-headline" id="Level_5_Heading">Level 5 Heading</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Level 5 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></h5>
<h6><span class="mw-headline" id="Level_6_Heading">Level 6 Heading</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Level 6 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
<h6><span class="mw-headline" id=".3DLevel_7_Heading.3D">=Level 7 Heading=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=7" title="Edit section: =Level 7 Heading=">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
<h6><span class="mw-headline" id=".3D.3DLevel_8_Heading.3D.3D">==Level 8 Heading==</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=8" title="Edit section: ==Level 8 Heading==">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
<h6><span class="mw-headline" id=".3D.3D.3DLevel_9_Heading.3D.3D.3D">===Level 9 Heading===</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=9" title="Edit section: ===Level 9 Heading===">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
<h6><span class="mw-headline" id=".3D.3D.3D.3DLevel_10_Heading.3D.3D.3D.3D">====Level 10 Heading====</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=10" title="Edit section: ====Level 10 Heading====">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
!! html/parsoid
<h1 id="Level_1_Heading" data-parsoid='{}'>Level 1 Heading</h1>
<h2 id="Level_2_Heading" data-parsoid='{}'>Level 2 Heading</h2>
<h3 id="Level_3_Heading" data-parsoid='{}'>Level 3 Heading</h3>
<h4 id="Level_4_Heading" data-parsoid='{}'>Level 4 Heading</h4>
<h5 id="Level_5_Heading" data-parsoid='{}'>Level 5 Heading</h5>
<h6 id="Level_6_Heading" data-parsoid='{}'>Level 6 Heading</h6>
<h6 id="=Level_7_Heading=" data-parsoid='{}'><span id=".3DLevel_7_Heading.3D" typeof="mw:FallbackId"></span>=Level 7 Heading=</h6>
<h6 id="==Level_8_Heading==" data-parsoid='{}'><span id=".3D.3DLevel_8_Heading.3D.3D" typeof="mw:FallbackId"></span>==Level 8 Heading==</h6>
<h6 id="===Level_9_Heading===" data-parsoid='{}'><span id=".3D.3D.3DLevel_9_Heading.3D.3D.3D" typeof="mw:FallbackId"></span>===Level 9 Heading===</h6>
<h6 id="====Level_10_Heading====" data-parsoid='{}'><span id=".3D.3D.3D.3DLevel_10_Heading.3D.3D.3D.3D" typeof="mw:FallbackId"></span>====Level 10 Heading====</h6>
!! end

!! test
TOC regression (T11764)
!! wikitext
==title 1==
===title 1.1===
====title 1.1.1====
===title 1.2===
==title 2==
===title 2.1===
!! html
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#title_1.1"><span class="tocnumber">1.1</span> <span class="toctext">title 1.1</span></a>
<ul>
<li class="toclevel-3 tocsection-3"><a href="#title_1.1.1"><span class="tocnumber">1.1.1</span> <span class="toctext">title 1.1.1</span></a></li>
</ul>
</li>
<li class="toclevel-2 tocsection-4"><a href="#title_1.2"><span class="tocnumber">1.2</span> <span class="toctext">title 1.2</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#title_2"><span class="tocnumber">2</span> <span class="toctext">title 2</span></a>
<ul>
<li class="toclevel-2 tocsection-6"><a href="#title_2.1"><span class="tocnumber">2.1</span> <span class="toctext">title 2.1</span></a></li>
</ul>
</li>
</ul>
</div>

<h2><span class="mw-headline" id="title_1">title 1</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: title 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="title_1.1">title 1.1</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: title 1.1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h4><span class="mw-headline" id="title_1.1.1">title 1.1.1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: title 1.1.1">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<h3><span class="mw-headline" id="title_1.2">title 1.2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: title 1.2">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="title_2">title 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: title 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="title_2.1">title 2.1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: title 2.1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
!! end

!! test
TOC for heading containing <span id="..."></span> (T96153)
!! wikitext
__FORCETOC__
==<span id="old-anchor"></span>New title==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#New_title"><span class="tocnumber">1</span> <span class="toctext">New title</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="New_title"><span id="old-anchor"></span>New title</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: New title">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
TOC with wgMaxTocLevel=3 (T8204)
!! options
wgMaxTocLevel=3
!! wikitext
==title 1==
===title 1.1===
====title 1.1.1====
===title 1.2===
==title 2==
===title 2.1===
!! html
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#title_1.1"><span class="tocnumber">1.1</span> <span class="toctext">title 1.1</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#title_1.2"><span class="tocnumber">1.2</span> <span class="toctext">title 1.2</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#title_2"><span class="tocnumber">2</span> <span class="toctext">title 2</span></a>
<ul>
<li class="toclevel-2 tocsection-6"><a href="#title_2.1"><span class="tocnumber">2.1</span> <span class="toctext">title 2.1</span></a></li>
</ul>
</li>
</ul>
</div>

<h2><span class="mw-headline" id="title_1">title 1</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: title 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="title_1.1">title 1.1</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: title 1.1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h4><span class="mw-headline" id="title_1.1.1">title 1.1.1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: title 1.1.1">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<h3><span class="mw-headline" id="title_1.2">title 1.2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: title 1.2">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="title_2">title 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: title 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="title_2.1">title 2.1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: title 2.1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
!! end

!! test
TOC with wgMaxTocLevel=3 and two level four headings (T8204)
!! options
wgMaxTocLevel=3
!! wikitext
==Section 1==
===Section 1.1===
====Section 1.1.1====
====Section 1.1.1.1====
==Section 2==
!! html
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Section_1"><span class="tocnumber">1</span> <span class="toctext">Section 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Section_1.1"><span class="tocnumber">1.1</span> <span class="toctext">Section 1.1</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#Section_2"><span class="tocnumber">2</span> <span class="toctext">Section 2</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Section_1">Section 1</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: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Section_1.1">Section 1.1</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: Section 1.1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h4><span class="mw-headline" id="Section_1.1.1">Section 1.1.1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Section 1.1.1">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<h4><span class="mw-headline" id="Section_1.1.1.1">Section 1.1.1.1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Section 1.1.1.1">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
<h2><span class="mw-headline" id="Section_2">Section 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end


!! test
Resolving duplicate section names
!! wikitext
==Foo bar==
==Foo bar==
!! html
<h2><span class="mw-headline" id="Foo_bar">Foo bar</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: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Foo_bar_2">Foo bar</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
Resolving duplicate section names with differing case (T12721)
!! wikitext
==Foo bar==
==Foo Bar==
!! html
<h2><span class="mw-headline" id="Foo_bar">Foo bar</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: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Foo_Bar_2">Foo Bar</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! article
Template:sections
!! text
===Section 1===
==Section 2==
!! endarticle

!! test
Template with sections, __NOTOC__
!! wikitext
__NOTOC__
==Section 0==
{{sections}}
==Section 4==
!! html
<h2><span class="mw-headline" id="Section_0">Section 0</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: Section 0">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Section_1">Section 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Sections&amp;action=edit&amp;section=T-1" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="Section_2">Section 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Sections&amp;action=edit&amp;section=T-2" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Section_4">Section 4</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: Section 4">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
__NOEDITSECTION__ keyword
!! wikitext
__NOEDITSECTION__
==Section 1==
==Section 2==
!! html
<h2><span class="mw-headline" id="Section_1">Section 1</span></h2>
<h2><span class="mw-headline" id="Section_2">Section 2</span></h2>
!! end

!! test
Link inside a section heading
!! wikitext
==Section with a [[Main Page|link]] in it==
!! html
<h2><span class="mw-headline" id="Section_with_a_link_in_it">Section with a <a href="/wiki/Main_Page" title="Main Page">link</a> in it</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: Section with a link in it">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
TOC regression (T14077)
!! wikitext
__TOC__
==title 1==
===title 1.1===
==title 2==
!! html
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#title_1.1"><span class="tocnumber">1.1</span> <span class="toctext">title 1.1</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-3"><a href="#title_2"><span class="tocnumber">2</span> <span class="toctext">title 2</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="title_1">title 1</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: title 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="title_1.1">title 1.1</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: title 1.1">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h2><span class="mw-headline" id="title_2">title 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: title 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

# Parsoid doesn't wt2wt this cleanly because it adds <nowiki>s.
!! test
Short headings with trailing space should match behavior of Parser::doHeadings (T21910)
!! options
parsoid=wt2html,html2html
!! wikitext
=== 
The line above must have a trailing space!
=== <!--
--> <!-- -->
But just in case it doesn't...
!! html/php
<h1><span class="mw-headline" id=".3D">=</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: =">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<p>The line above must have a trailing space!
</p>
<h1><span class="mw-headline" id=".3D_2">=</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: =">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<p>But just in case it doesn't...
</p>
!! html/parsoid
<h1 id="="><span id=".3D" typeof="mw:FallbackId"></span>=</h1> 
<p>The line above must have a trailing space!</p>
<h1 id="=_2"><span id=".3D_2" typeof="mw:FallbackId"></span>=</h1> <!--
--> <!-- -->
<p>But just in case it doesn't...</p>
!! end

!! test
Header with special characters (T27462)
!! wikitext
The tooltips shall not show entities to the user (ie. be double escaped)

==text > text==
section 1

==text < text==
section 2

==text & text==
section 3

==text ' text==
section 4

==text " text==
section 5
!! html/php
<p>The tooltips shall not show entities to the user (ie. be double escaped)
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#text_.3E_text"><span class="tocnumber">1</span> <span class="toctext">text &gt; text</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#text_.3C_text"><span class="tocnumber">2</span> <span class="toctext">text &lt; text</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#text_.26_text"><span class="tocnumber">3</span> <span class="toctext">text &amp; text</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#text_.27_text"><span class="tocnumber">4</span> <span class="toctext">text ' text</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#text_.22_text"><span class="tocnumber">5</span> <span class="toctext">text " text</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="text_.3E_text">text &gt; text</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: text &gt; text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 1
</p>
<h2><span class="mw-headline" id="text_.3C_text">text &lt; text</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: text &lt; text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 2
</p>
<h2><span class="mw-headline" id="text_.26_text">text &amp; text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: text &amp; text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 3
</p>
<h2><span class="mw-headline" id="text_.27_text">text ' text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: text &#039; text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 4
</p>
<h2><span class="mw-headline" id="text_.22_text">text " text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: text &quot; text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 5
</p>
!! html/parsoid
<p>The tooltips shall not show entities to the user (ie. be double escaped)</p>

<h2 id="text_>_text"><span id="text_.3E_text" typeof="mw:FallbackId"></span>text > text</h2>
<p>section 1</p>

<h2 id="text_&lt;_text"><span id="text_.3C_text" typeof="mw:FallbackId"></span>text &lt; text</h2>
<p>section 2</p>

<h2 id="text_&amp;_text"><span id="text_.26_text" typeof="mw:FallbackId"></span>text &amp; text</h2>
<p>section 3</p>

<h2 id="text_'_text"><span id="text_.27_text" typeof="mw:FallbackId"></span>text ' text</h2>
<p>section 4</p>

<h2 id='text_"_text'><span id="text_.22_text" typeof="mw:FallbackId"></span>text " text</h2>
<p>section 5</p>
!! end

!! test
Header with space, plus and underscore as entity
!! wikitext
Id should not contain + for spaces

==Space between Text==
section 1

==Space-Entity&#32;between&#32;Text==
section 2

==Plus+between+Text==
section 3

==Plus-Entity&#43;between&#43;Text==
section 4

==Underscore_between_Text==
section 5

==Underscore-Entity&#95;between&#95;Text==
section 6

[[#Space between Text]]
[[#Space-Entity&#32;between&#32;Text]]
[[#Plus+between+Text]]
[[#Plus-Entity&#43;between&#43;Text]]
[[#Underscore_between_Text]]
[[#Underscore-Entity&#95;between&#95;Text]]
!! html/php
<p>Id should not contain + for spaces
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Space_between_Text"><span class="tocnumber">1</span> <span class="toctext">Space between Text</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Space-Entity_between_Text"><span class="tocnumber">2</span> <span class="toctext">Space-Entity&#32;between&#32;Text</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Plus.2Bbetween.2BText"><span class="tocnumber">3</span> <span class="toctext">Plus+between+Text</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Plus-Entity.2Bbetween.2BText"><span class="tocnumber">4</span> <span class="toctext">Plus-Entity&#43;between&#43;Text</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#Underscore_between_Text"><span class="tocnumber">5</span> <span class="toctext">Underscore_between_Text</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="#Underscore-Entity_between_Text"><span class="tocnumber">6</span> <span class="toctext">Underscore-Entity&#95;between&#95;Text</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Space_between_Text">Space between Text</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: Space between Text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 1
</p>
<h2><span class="mw-headline" id="Space-Entity_between_Text">Space-Entity&#32;between&#32;Text</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: Space-Entity between Text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 2
</p>
<h2><span class="mw-headline" id="Plus.2Bbetween.2BText">Plus+between+Text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Plus+between+Text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 3
</p>
<h2><span class="mw-headline" id="Plus-Entity.2Bbetween.2BText">Plus-Entity&#43;between&#43;Text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Plus-Entity+between+Text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 4
</p>
<h2><span class="mw-headline" id="Underscore_between_Text">Underscore_between_Text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Underscore between Text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 5
</p>
<h2><span class="mw-headline" id="Underscore-Entity_between_Text">Underscore-Entity&#95;between&#95;Text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Underscore-Entity_between_Text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>section 6
</p><p><a href="#Space_between_Text">#Space between Text</a>
<a href="#Space-Entity_between_Text">#Space-Entity&#32;between&#32;Text</a>
<a href="#Plus.2Bbetween.2BText">#Plus+between+Text</a>
<a href="#Plus-Entity.2Bbetween.2BText">#Plus-Entity&#43;between&#43;Text</a>
<a href="#Underscore_between_Text">#Underscore_between_Text</a>
<a href="#Underscore-Entity_between_Text">#Underscore-Entity&#95;between&#95;Text</a>
</p>
!! html/parsoid
<p>Id should not contain + for spaces</p>

<h2 id="Space_between_Text">Space between Text</h2>
<p>section 1</p>

<h2 id="Space-Entity_between_Text">Space-Entity<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#32;","srcContent":" "}'> </span>between<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#32;","srcContent":" "}'> </span>Text</h2>
<p>section 2</p>

<h2 id="Plus+between+Text"><span id="Plus.2Bbetween.2BText" typeof="mw:FallbackId"></span>Plus+between+Text</h2>
<p>section 3</p>

<h2 id="Plus-Entity+between+Text"><span id="Plus-Entity.2Bbetween.2BText" typeof="mw:FallbackId"></span>Plus-Entity<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#43;","srcContent":"+"}'>+</span>between<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#43;","srcContent":"+"}'>+</span>Text</h2>
<p>section 4</p>

<h2 id="Underscore_between_Text">Underscore_between_Text</h2>
<p>section 5</p>

<h2 id="Underscore-Entity_between_Text">Underscore-Entity<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#95;","srcContent":"_"}'>_</span>between<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#95;","srcContent":"_"}'>_</span>Text</h2>
<p>section 6</p>

<p><a rel="mw:WikiLink" href="./Parser_test#Space_between_Text" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Space_between_Text"},"sa":{"href":"#Space between Text"}}'>#Space between Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Space-Entity_between_Text" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Space-Entity_between_Text"},"sa":{"href":"#Space-Entity&amp;#32;between&amp;#32;Text"}}'>#Space-Entity between Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Plus+between+Text" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Plus+between+Text"},"sa":{"href":"#Plus+between+Text"}}'>#Plus+between+Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Plus-Entity+between+Text" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Plus-Entity+between+Text"},"sa":{"href":"#Plus-Entity&amp;#43;between&amp;#43;Text"}}'>#Plus-Entity+between+Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Underscore_between_Text" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Underscore_between_Text"},"sa":{"href":"#Underscore_between_Text"}}'>#Underscore_between_Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Underscore-Entity_between_Text" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Underscore-Entity_between_Text"},"sa":{"href":"#Underscore-Entity&amp;#95;between&amp;#95;Text"}}'>#Underscore-Entity_between_Text</a></p>
!! end

# Parsoid html2wt disabled because it adds padding spaces around =
!! test
Headers with excess '=' characters
(Are similar tests necessary beyond the 1st level?)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
=foo==
==foo=
=''italic'' heading==
==''italic'' heading=
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#foo.3D"><span class="tocnumber">1</span> <span class="toctext">foo=</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#.3Dfoo"><span class="tocnumber">2</span> <span class="toctext">=foo</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#italic_heading.3D"><span class="tocnumber">3</span> <span class="toctext"><i>italic</i> heading=</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#.3Ditalic_heading"><span class="tocnumber">4</span> <span class="toctext">=<i>italic</i> heading</span></a></li>
</ul>
</div>

<h1><span class="mw-headline" id="foo.3D">foo=</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: foo=">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h1><span class="mw-headline" id=".3Dfoo">=foo</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: =foo">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h1><span class="mw-headline" id="italic_heading.3D"><i>italic</i> heading=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: italic heading=">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h1><span class="mw-headline" id=".3Ditalic_heading">=<i>italic</i> heading</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: =italic heading">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
!! html/parsoid
<h1 id="foo="><span id="foo.3D" typeof="mw:FallbackId"></span>foo=</h1>
<h1 id="=foo"><span id=".3Dfoo" typeof="mw:FallbackId"></span>=foo</h1>
<h1 id="italic_heading="><span id="italic_heading.3D" typeof="mw:FallbackId"></span><i>italic</i> heading=</h1>
<h1 id="=italic_heading"><span id=".3Ditalic_heading" typeof="mw:FallbackId"></span>=<i>italic</i> heading</h1>
!! end

!! test
HTML headers vs TOC (T25393)
(__NOEDITSECTION__ for clearer output, doesn't matter here)
!! wikitext
<h1>Header 1</h1>
==Header 1.1==
==Header 1.2==

<h1>Header 2
</h1>
==Header 2.1==
==Header 2.2==
__NOEDITSECTION__
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1"><a href="#Header_1"><span class="tocnumber">1</span> <span class="toctext">Header 1</span></a>
<ul>
<li class="toclevel-2 tocsection-1"><a href="#Header_1.1"><span class="tocnumber">1.1</span> <span class="toctext">Header 1.1</span></a></li>
<li class="toclevel-2 tocsection-2"><a href="#Header_1.2"><span class="tocnumber">1.2</span> <span class="toctext">Header 1.2</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="#Header_2"><span class="tocnumber">2</span> <span class="toctext">Header 2</span></a>
<ul>
<li class="toclevel-2 tocsection-3"><a href="#Header_2.1"><span class="tocnumber">2.1</span> <span class="toctext">Header 2.1</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#Header_2.2"><span class="tocnumber">2.2</span> <span class="toctext">Header 2.2</span></a></li>
</ul>
</li>
</ul>
</div>

<h1><span class="mw-headline" id="Header_1">Header 1</span></h1>
<h2><span class="mw-headline" id="Header_1.1">Header 1.1</span></h2>
<h2><span class="mw-headline" id="Header_1.2">Header 1.2</span></h2>
<h1><span class="mw-headline" id="Header_2">Header 2
</span></h1>
<h2><span class="mw-headline" id="Header_2.1">Header 2.1</span></h2>
<h2><span class="mw-headline" id="Header_2.2">Header 2.2</span></h2>
!! html/parsoid
<h1 id="Header_1" data-parsoid='{"stx":"html"}'>Header 1</h1>
<h2 id="Header_1.1" data-parsoid='{}'>Header 1.1</h2>
<h2 id="Header_1.2" data-parsoid='{}'>Header 1.2</h2>

<h1 id="Header_2" data-parsoid='{"stx":"html"}'>Header 2
</h1>
<h2 id="Header_2.1" data-parsoid='{}'>Header 2.1</h2>
<h2 id="Header_2.2" data-parsoid='{}'>Header 2.2</h2>
<meta property="mw:PageProp/noeditsection"/>
!! end

!! test
Single-line or multiline-comments can follow headings
!! options
parsoid=wt2html,wt2wt
!! wikitext
==foo==<!---->
==bar==<!--c1-->
==baz==<!--
c2
c3-->
!! html/php
<h2><span class="mw-headline" id="foo">foo</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: foo">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="bar">bar</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: bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="baz">baz</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: baz">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<h2 id="foo">foo</h2><!---->
<h2 id="bar">bar</h2><!--c1-->
<h2 id="baz">baz</h2><!--
c2
c3-->
!! end

!! test
T3186 news: in the middle of text
!! wikitext
http://en.wikinews.org/wiki/Wikinews:Workplace
!! html
<p><a rel="nofollow" class="external free" href="http://en.wikinews.org/wiki/Wikinews:Workplace">http://en.wikinews.org/wiki/Wikinews:Workplace</a>
</p>
!!end


!! test
Namespaced link must have a title
!! wikitext
[[Project:]]
!! html
<p>[[Project:]]
</p>
!!end

!! test
Namespaced link must have a title (bad fragment version)
!! wikitext
[[Project:#fragment]]
!! html
<p>[[Project:#fragment]]
</p>
!!end


###
### HTML tags and HTML attributes
###

!! test
div with no attributes
!! wikitext
<div>HTML rocks</div>
!! html
<div>HTML rocks</div>
!! end

!! test
div with double-quoted attribute
!! wikitext
<div id="rock">HTML rocks</div>
!! html
<div id="rock">HTML rocks</div>
!! end

!! test
div with single-quoted attribute
!! wikitext
<div id='rock'>HTML rocks</div>
!! html
<div id="rock">HTML rocks</div>
!! end

!! test
div with unquoted attribute
!! wikitext
<div id=rock>HTML rocks</div>
!! html
<div id="rock">HTML rocks</div>
!! end

!! test
div with illegal double attributes
!! wikitext
<div id="a" id="b">HTML rocks</div>
!! html
<div id="b">HTML rocks</div>
!! end

!! test
div with empty attribute value, space before equals
!! options
parsoid=wt2html,html2html
!! wikitext
<div class =>HTML rocks</div>
!! html/php
<div class="">HTML rocks</div>
!! html/parsoid
<div class="" data-parsoid='{"stx":"html"}'>HTML rocks</div>
!! end

!! test
div with multiple empty attribute values
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! options
parsoid=wt2html,html2html
!! wikitext
<div id= title=>HTML rocks</div>
!! html/php
<div id="title=">HTML rocks</div>
!! html/parsoid
<div id="title=" data-parsoid='{"stx":"html"}'>HTML rocks</div>
!! end

# FIXME Parsoid doesn't actually match PHP here.
!! test
Extension tag in attribute value
!! options
wgRawHtml=1
!! wikitext
<span title="<html><div>123</div></html>">ok</span>
!! html/php+tidy
<p><span title="&lt;div&gt;123&lt;/div&gt;">ok</span>
</p>
!! html/parsoid
<p><span title="123" about="#mwt4" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"title":"123"},"sa":{"title":"&lt;html>&lt;div>123&lt;/div>&lt;/html>"}}' data-mw='{"attribs":[[{"txt":"title"},{"html":"&lt;div typeof=\"mw:Extension/html\" about=\"#mwt3\" data-parsoid=&apos;{\"dsr\":[13,40,2,2]}&apos; data-mw=&apos;{\"name\":\"html\",\"attrs\":{},\"body\":{\"extsrc\":\"&amp;lt;div>123&amp;lt;/div>\"}}&apos;>123&lt;/div>"}]]}'>ok</span></p>
!! end

!! test
table with multiple empty attribute values
!! options
parsoid=wt2html,html2html
!! wikitext
{| title= id=
|hi
|}
!! html/php
<table title="id=">
<tbody><tr>
<td>hi
</td></tr></tbody></table>
!! html/parsoid
<table title="id=">
<tbody><tr><td>hi</td></tr>
</tbody></table>
!! end

!! test
div with braces in attribute value
!! wikitext
<div title="{}">Foo</div>
!! html/php
<div title="&#123;&#125;">Foo</div>
!! html/parsoid
<div title="{}">Foo</div>
!! end

!! test
div with empty attribute value, no space before equals
!! options
parsoid=wt2html,html2html
!! wikitext
<div class=>HTML rocks</div>
!! html/php
<div class="">HTML rocks</div>
!! html/parsoid
<div class="">HTML rocks</div>
!! end

!! test
HTML multiple attributes correction
!! wikitext
<p class="error" class="awesome">Awesome!</p>
!! html
<p class="awesome">Awesome!</p>
!! end

!! test
Table multiple attributes correction
!! wikitext
{|
!+ class="error" class="awesome"|status
|}
!! html
<table>
<tbody><tr>
<th class="awesome">status
</th></tr></tbody></table>
!! end

!! test
DIV IN UPPERCASE
!! wikitext
<DIV ID="x">HTML ROCKS</DIV>
!! html
<div id="x">HTML ROCKS</div>
!! end

!! test
Non-ASCII pseudo-tags are rendered as text
!! wikitext
<khyô>
!! html
<p>&lt;khyô&gt;
</p>
!! end

!! test
Pseudo-tag with URL 'name' renders as url link
!! wikitext
<http://example.com/>
!! html
<p>&lt;<a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a>&gt;
</p>
!! end

!! test
text with amp in the middle of nowhere
!! wikitext
Remember AT&T?
!! html
<p>Remember AT&amp;T?
</p>
!! end

!! test
text with character entity: eacute
!! wikitext
I always thought &eacute; was a cute letter.
!! html+tidy
<p>I always thought &#233; was a cute letter.
</p>
!! end

!! test
text with entity-escaped character entity-like string: eacute
!! wikitext
I always thought &amp;eacute; was a cute letter.
!! html
<p>I always thought &amp;eacute; was a cute letter.
</p>
!! end

!! test
text with undefined character entity: xacute
!! wikitext
I always thought &xacute; was a cute letter.
!! html
<p>I always thought &amp;xacute; was a cute letter.
</p>
!! end

!! test
Text with HTML5 semicolon-less entity (should not decode)
!! wikitext
&ampamp;
!! html/php+tidy
<p>&amp;ampamp;
</p>
!! html/parsoid
<p>&amp;ampamp;</p>
!! end

!! test
HTML5 tags
!! wikitext
<data value="5">five</data>
<time datetime="2000-01-01T00:00Z">The new millenium started</time>
<mark>This highlighted text</mark>
!! html
<p><data value="5">five</data>
<time datetime="2000-01-01T00:00Z">The new millenium started</time>
<mark>This highlighted text</mark>
</p>
!! end

!! test
HTML tag with leading space is parsed as text
!! wikitext
< div>foo< /div>
!! html
<p>&lt; div&gt;foo&lt; /div&gt;
</p>
!! end

## FIXME: The untrimmed attribute in Parsoid is T205737
!! test
Element with broken attribute syntax
!! options
parsoid=wt2html
!! wikitext
<div style=" style="123">hi</div>
<div =>ho</div>
!! html/php
<div style="style=">hi</div>
<div>ho</div>
!! html/parsoid
<div style=" style=" data-parsoid='{"stx":"html","a":{"123\"":null},"sa":{"123\"":""}}'>hi</div>
<div data-parsoid='{"stx":"html","a":{"=":null},"sa":{"=":""}}'>ho</div>
!! end

###
### Nesting tests (see T43545, T52604, T53081)
###

# This test case is fixed in Parsoid by domino 1.0.12. (T52604)
# Note that html2wt is considerably more difficult if we use <b> in
# the test case, instead of <small>
!! test
Ensure that HTML adoption agency algorithm is properly implemented.
!! wikitext
<small>X<small>Y</small>Z</small>
!! html
<p><small>X<small>Y</small>Z</small>
</p>
!! end

# This was T43545 in the PHP parser.
!! test
Nesting of <kbd>
!! wikitext
<kbd>X<kbd>Y</kbd>Z</kbd>
!! html+tidy
<p><kbd>X<kbd>Y</kbd>Z</kbd>
</p>
!! end

# The following cases were T53081 in the PHP parser.
# Note that there are some other nestable tags (b, i, etc) which are
# not covered; see T53081 for discussion.

!! test
Nesting of <em>
!! wikitext
<em>X<em>Y</em>Z</em>
!! html+tidy
<p><em>X<em>Y</em>Z</em>
</p>
!! end

!! test
Nesting of <strong>
!! wikitext
<strong>X<strong>Y</strong>Z</strong>
!! html+tidy
<p><strong>X<strong>Y</strong>Z</strong>
</p>
!! end

!! test
Nesting of <q>
!! wikitext
<q>X<q>Y</q>Z</q>
!! html+tidy
<p><q>X<q>Y</q>Z</q>
</p>
!! end

!! test
Nesting of <ruby>
!! wikitext
<ruby>X<ruby>Y</ruby>Z</ruby>
!! html
<p><ruby>X<ruby>Y</ruby>Z</ruby>
</p>
!! end

!! test
Nesting of <bdo>
!! wikitext
<bdo>X<bdo>Y</bdo>Z</bdo>
!! html
<p><bdo>X<bdo>Y</bdo>Z</bdo>
</p>
!! end


###
### Media links
###

!! test
Media link
!! wikitext
[[Media:Foobar.jpg]]
[[Media:Video.ogv]]
[[:Media:Video.ogv]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Media:Foobar.jpg</a>
<a href="http://example.com/images/0/00/Video.ogv" class="internal" title="Video.ogv">Media:Video.ogv</a>
<a href="http://example.com/images/0/00/Video.ogv" class="internal" title="Video.ogv">Media:Video.ogv</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">Media:Foobar.jpg</a>
<a rel="mw:MediaLink" href="http://example.com/images/0/00/Video.ogv" resource="./Media:Video.ogv" title="Video.ogv">Media:Video.ogv</a>
<a rel="mw:MediaLink" href="http://example.com/images/0/00/Video.ogv" resource="./Media:Video.ogv" title="Video.ogv" data-parsoid='{"a":{"resource":"./Media:Video.ogv"},"sa":{"resource":":Media:Video.ogv"}}'>Media:Video.ogv</a></p>
!! end

!! test
Media link with text
!! wikitext
[[Media:Foobar.jpg|A neat file to look at]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">A neat file to look at</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">A neat file to look at</a></p>
!! end

!! test
Localized media link
!! options
language=is
!! wikitext
[[Miðill:Foobar.jpg]]

[[Miðill:Foobar.jpg|Icelandic]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Miðill:Foobar.jpg</a>
</p><p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Icelandic</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Miðill:Foobar.jpg" title="Foobar.jpg">Miðill:Foobar.jpg</a></p>
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Miðill:Foobar.jpg" title="Foobar.jpg">Icelandic</a></p>
!! end

# FIXME: this is still bad HTML tag nesting
# FIXME: doBlockLevels won't wrap this in a paragraph because it contains a div
# Parsoid & Remex fix the p-wrapping since they operate on the DOM.
!! test
Media link with nasty text
!! options
parsoid=wt2html,html2html
!! wikitext
[[Media:Foobar.jpg|Safe Link<div style=display:none>" onmouseover="alert(document.cookie)" onfoo="</div>]]
!! html/php+untidy
<a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Safe Link&lt;div style="display:none"&gt;" onmouseover="alert(document.cookie)" onfoo="&lt;/div&gt;</a>
!! html/php+tidy
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Safe Link</a></p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg"><div style="display:none">" onmouseover="alert(document.cookie)" onfoo="</div></a>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">Safe Link</a></p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg"><div style="display:none" data-parsoid='{"stx":"html"}'>" onmouseover="alert(document.cookie)" onfoo="</div></a>
!! end

!! test
Media link from missing resource (parsoid-only)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg">Bat!</a>
!! wikitext
[[Media:Foobar.jpg|Bat!]]
!! end

!! test
Media link from missing resource, localized (parsoid-only)
!! options
parsoid=html2wt
language=is
!! html/parsoid
<a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg">Bat!</a>
!! wikitext
[[Miðill:Foobar.jpg|Bat!]]
!! end

# This is a sanity test to ensure we don't crash or choke when given
# old cached 1.7.0 HTML for media links; we don't require that the
# result be "valid" because wt2wt was completely broken in 1.7.0
!! test
Media link from old 1.7.0 DOM spec (crash test, parsoid-only) T198511
!! options
parsoid=html2wt
!! html/parsoid
<p>This is what Parsoid would emit (and we still handle this HTML fine):</p>
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" title="Foobar.jpg">A neat file to look at</a></p>
<p>But VisualEditor would mangle the rel attribute, and give us back this:</p>
<p><a rel="mw:ExtLink" href="http://example.com/images/3/3a/Foobar.jpg" title="Foobar.jpg">A neat file to look at</a></p>
<p>But at least we don't crash when trying to handle the mangled HTML!</p>
!! wikitext
This is what Parsoid would emit (and we still handle this HTML fine):

[[Media:Foobar.jpg|A neat file to look at]]

But VisualEditor would mangle the rel attribute, and give us back this:

[http://example.com/images/3/3a/Foobar.jpg A neat file to look at]

But at least we don't crash when trying to handle the mangled HTML!
!! end

!! test
Media link to nonexistent file (T3702)
!! wikitext
[[Media:No such.jpg]]
[[Media:No_such file.jpg]]
!! html/php
<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=No_such.jpg" class="new" title="No such.jpg">Media:No such.jpg</a>
<a href="/index.php?title=Special:Upload&amp;wpDestFile=No_such_file.jpg" class="new" title="No such file.jpg">Media:No_such file.jpg</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="./Special:FilePath/No_such.jpg" resource="./Media:No_such.jpg" title="No such.jpg" typeof="mw:Error" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}' data-parsoid='{"a":{"resource":"./Media:No_such.jpg"},"sa":{"resource":"Media:No such.jpg"}}'>Media:No such.jpg</a>
<a rel="mw:MediaLink" href="./Special:FilePath/No_such_file.jpg" resource="./Media:No_such_file.jpg" title="No such file.jpg" typeof="mw:Error" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}' data-parsoid='{"a":{"resource":"./Media:No_such_file.jpg"},"sa":{"resource":"Media:No_such file.jpg"}}'>Media:No_such file.jpg</a></p>
!! end

!! test
Media link with nested wikilinks
!! wikitext
[[Media:Foobar.jpg|[[Test]]]]
[[Media:Foobar.jpg|[[File:Foobar.jpg]]]]
!! html/php
<p>[[Media:Foobar.jpg|<a href="/index.php?title=Test&amp;action=edit&amp;redlink=1" class="new" title="Test (page does not exist)">Test</a>]]
[[Media:Foobar.jpg|<a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a>]]
</p>
!! html/parsoid
<p>[[Media:Foobar.jpg|<a rel="mw:WikiLink" href="./Test" title="Test" class="new">Test</a>]]
[[Media:Foobar.jpg|<span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://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
Media link with multiple options
!! wikitext
[[Media:Foobar.jpg|123|345]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">123|345</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">123|345</a></p>
!! end

!! test
Character reference normalization in link text (T3938)
!! wikitext
[[Main Page|this&that]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">this&amp;that</a>
</p>
!! end

!! article
אַ
!! text
Test for unicode normalization

The page's name is U+05d0 U+05b7, with non-canonical form U+FB2E
!! endarticle

# Parsoid has a regression here (T258858) note the incorrect redlink as well
!! test
(T21451) Links should refer to the normalized form.
!! wikitext
[[&#xFB2E;]]
[[&#x5d0;&#x5b7;]]
[[&#x5d0;ַ]]
[[א&#x5b7;]]
[[אַ]]
!! html/php
<p><a href="/wiki/%D7%90%D6%B7" title="אַ">&#xfb2e;</a>
<a href="/wiki/%D7%90%D6%B7" title="אַ">&#x5d0;&#x5b7;</a>
<a href="/wiki/%D7%90%D6%B7" title="אַ">&#x5d0;ַ</a>
<a href="/wiki/%D7%90%D6%B7" title="אַ">א&#x5b7;</a>
<a href="/wiki/%D7%90%D6%B7" title="אַ">אַ</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"&amp;#xFB2E;"}}' class="new">אַ</a>
<a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"&amp;#x5d0;&amp;#x5b7;"}}'>אַ</a>
<a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"&amp;#x5d0;ַ"}}'>אַ</a>
<a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"א&amp;#x5b7;"}}'>אַ</a>
<a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"אַ"}}'>אַ</a></p>
!! end

!! test
Empty attribute crash test (T4067)
!! wikitext
<font color="">foo</font>
!! html
<p><font color="">foo</font>
</p>
!! end

!! test
Empty attribute crash test single-quotes (T4067)
!! wikitext
<font color=''>foo</font>
!! html
<p><font color="">foo</font>
</p>
!! end

!! test
Attribute test: equals, then nothing
!! options
parsoid=wt2html,html2html
!! wikitext
<font color=>foo</font>
!! html/php
<p><font color="">foo</font>
</p>
!! html/parsoid
<p><font color="" data-parsoid='{"stx":"html"}'>foo</font></p>
!! end

!! test
Attribute test: unquoted value
!! options
parsoid=wt2html,html2html
!! wikitext
<font color=x>foo</font>
!! html/php
<p><font color="x">foo</font>
</p>
!! html/parsoid
<p><font color="x" data-parsoid='{"stx":"html"}'>foo</font></p>
!! end

!! test
Attribute test: unquoted but illegal value (hash)
!! wikitext
<font color=#x>foo</font>
!! html
<p><font color="#x">foo</font>
</p>
!! end

# Parsoid does not serialize to empty attribute syntax,
# so wt2wt and html2wt cases are skipped
!! test
Attribute test: no value (T54330)
!! options
parsoid=wt2html,html2html
!! wikitext
<font color>foo</font>
!! html/php
<p><font color="">foo</font>
</p>
!! html/parsoid
<p><font color="">foo</font></p>
!! end

!! test
T4095: link with three closing brackets
!! wikitext
[[Main Page]]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>]
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a>]</p>
!! end

!! test
T4095: link with pipe and three closing brackets
!! wikitext
[[Main Page|link]]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">link</a>]
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">link</a>]</p>
!! end

!! test
T4095: link with pipe and three closing brackets, version 2
!! wikitext
[[Main Page|[http://example.com/]]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">[http://example.com/]</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">[http://example.com/]</a></p>
!! end


###
### Safety
###

!! article
Template:Dangerous attribute
!! text
" onmouseover="alert(document.cookie)
!! endarticle

!! article
Template:Dangerous style attribute
!! text
border-size: expression(alert(document.cookie))
!! endarticle

!! article
Template:Div style
!! text
<div style="float: right; {{{1}}}">Magic div</div>
!! endarticle

!! test
T4304: HTML attribute safety (safe template; regression T4309)
!! wikitext
<div title="{{test}}"></div>
!! html/php
<div title="This is a test template"></div>
!! html/parsoid
<div title="This is a test template" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"title":"This is a test template"},"sa":{"title":"{{test}}"}}' data-mw='{"attribs":[[{"txt":"title"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[12,20,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"test\",\"href\":\"./Template:Test\"},\"params\":{},\"i\":0}}]}&#39;>This is a test template&lt;/span>"}]]}'></div>
!! end

# Parsoid has enough context to handle this case
!! test
T4304: HTML attribute safety (dangerous template; 2309)
!! wikitext
<div title="{{dangerous attribute}}"></div>
!! html/php
<div title=""></div>
!! html/parsoid
<div title='" onmouseover="alert(document.cookie)' about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"title":"\" onmouseover=\"alert(document.cookie)"},"sa":{"title":"{{dangerous attribute}}"}}' data-mw='{"attribs":[[{"txt":"title"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[12,35,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"dangerous attribute\",\"href\":\"./Template:Dangerous_attribute\"},\"params\":{},\"i\":0}}]}&#39;>\" onmouseover=\"alert(document.cookie)&lt;/span>"}]]}'></div>
!! end

!! test
T4304: HTML attribute safety (dangerous style template; 2309)
!! wikitext
<div style="{{dangerous style attribute}}"></div>
!! html/php
<div style="/* insecure input */"></div>
!! html/parsoid
<div style="/* insecure input */" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"{{dangerous style attribute}}"}}' data-mw='{"attribs":[[{"txt":"style"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[12,41,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"dangerous style attribute\",\"href\":\"./Template:Dangerous_style_attribute\"},\"params\":{},\"i\":0}}]}&#39;>border-size: expression(alert(document.cookie))&lt;/span>"}]]}'></div>
!! end

!! test
T4304: HTML attribute safety (safe parameter; 2309)
!! wikitext
{{div style|width: 200px}}
!! html/php
<div style="float: right; width: 200px">Magic div</div>
!! html/parsoid
<div style="float: right; width: 200px" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","a":{"style":"float: right; width: 200px"},"sa":{"style":"float: right; {{{1}}}"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"div style","href":"./Template:Div_style"},"params":{"1":{"wt":"width: 200px"}},"i":0}}]}'>Magic div</div>
!! end

!! test
T4304: HTML attribute safety (unsafe parameter; 2309)
!! wikitext
{{div style|width: expression(alert(document.cookie))}}
!! html/php
<div style="/* insecure input */">Magic div</div>
!! html/parsoid
<div style="/* insecure input */" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"float: right; {{{1}}}"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"div style","href":"./Template:Div_style"},"params":{"1":{"wt":"width: expression(alert(document.cookie))"}},"i":0}}]}'>Magic div</div>
!! end

## Parsoid output here differs; needs investigation.
!! test
T4304: HTML attribute safety (unsafe breakout parameter; 2309)
!! wikitext
{{div style|"><script>alert(document.cookie)</script>}}
!! html
<div style="float: right;">&lt;script&gt;alert(document.cookie)&lt;/script&gt;"&gt;Magic div</div>
!! end

## Parsoid output here differs; needs investigation.
!! test
T4304: HTML attribute safety (unsafe breakout parameter 2; 2309)
!! wikitext
{{div style|" ><script>alert(document.cookie)</script>}}
!! html
<div style="float: right;">&lt;script&gt;alert(document.cookie)&lt;/script&gt;"&gt;Magic div</div>
!! end

!! test
T4304: HTML attribute safety (link)
!! wikitext
<div title="[[Main Page]]"></div>
!! html/php
<div title="&#91;&#91;Main Page&#93;&#93;"></div>
!! html/parsoid
<div title="[[Main Page]]"></div>
!! end

!! test
T4304: HTML attribute safety (italics)
!! wikitext
<div title="''foobar''"></div>
!! html
<div title="&#39;&#39;foobar&#39;&#39;"></div>
!! end

!! test
T4304: HTML attribute safety (bold)
!! wikitext
<div title="'''foobar'''"></div>
!! html
<div title="&#39;&#39;&#39;foobar&#39;&#39;&#39;"></div>
!! end

!! test
T4304: HTML attribute safety (ISBN)
!! wikitext
<div title="ISBN 1234567890"></div>
!! html
<div title="&#73;SBN 1234567890"></div>
!! end

!! test
T4304: HTML attribute safety (RFC)
!! wikitext
<div title="RFC 1234"></div>
!! html
<div title="&#82;FC 1234"></div>
!! end

!! test
T4304: HTML attribute safety (PMID)
!! wikitext
<div title="PMID 1234567890"></div>
!! html
<div title="&#80;MID 1234567890"></div>
!! end

!! test
T4304: HTML attribute safety (web link)
!! wikitext
<div title="http://example.com/"></div>
!! html
<div title="http&#58;//example.com/"></div>
!! end

!! test
T4304: HTML attribute safety (named web link)
!! wikitext
<div title="[http://example.com/ link]"></div>
!! html/php
<div title="&#91;http&#58;//example.com/ link&#93;"></div>
!! html/parsoid
<div title="[http://example.com/ link]"></div>
!! end

!! test
T5244: HTML attribute safety (extension; safe)
!! wikitext
<div style="<nowiki>background:blue</nowiki>"></div>
!! html/php
<div style="background:blue"></div>
!! html/parsoid
<div style="background:blue" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"style":"background:blue"},"sa":{"style":"&lt;nowiki>background:blue&lt;/nowiki>"}}' data-mw='{"attribs":[[{"txt":"style"},{"html":"&lt;span typeof=\"mw:Nowiki\" data-parsoid=&apos;{\"dsr\":[12,44,8,9]}&apos;>background:blue&lt;/span>"}]]}'></div>
!! end

!! test
T5244: HTML attribute safety (extension; unsafe)
!! wikitext
<div style="<nowiki>border-left:expression(alert(document.cookie))</nowiki>"></div>
!! html/php
<div style="/* insecure input */"></div>
!! html/parsoid
<div style="/* insecure input */" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"&lt;nowiki>border-left:expression(alert(document.cookie))&lt;/nowiki>"}}' data-mw='{"attribs":[[{"txt":"style"},{"html":"&lt;span typeof=\"mw:Nowiki\" data-parsoid=&apos;{\"dsr\":[12,75,8,9]}&apos;>border-left:expression(alert(document.cookie))&lt;/span>"}]]}'></div>
!! end

# More MSIE fun discovered by Tom Gilder

!! test
MSIE CSS safety test: spurious slash
!! wikitext
<div style="background-image:u\rl(javascript:alert('boo'))">evil</div>
!! html/php
<div style="/* insecure input */">evil</div>
!! html/parsoid
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"background-image:u\\rl(javascript:alert(&#39;boo&#39;))"}}'>evil</div>
!! end

!! test
MSIE CSS safety test: hex code
!! wikitext
<div style="background-image:u\72l(javascript:alert('boo'))">evil</div>
!! html/php
<div style="/* insecure input */">evil</div>
!! html/parsoid
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"background-image:u\\72l(javascript:alert(&#39;boo&#39;))"}}'>evil</div>
!! end

!! test
MSIE CSS safety test: comment in url
!! wikitext
<div style="background-image:u/**/rl(javascript:alert('boo'))">evil</div>
!! html/php
<div style="background-image:u rl(javascript:alert(&#39;boo&#39;))">evil</div>
!! html/parsoid
<div style="background-image:u rl(javascript:alert('boo'))" data-parsoid='{"stx":"html","a":{"style":"background-image:u rl(javascript:alert(&#39;boo&#39;))"},"sa":{"style":"background-image:u/**/rl(javascript:alert(&#39;boo&#39;))"}}'>evil</div>
!! end

!! test
MSIE CSS safety test: comment in expression
!! wikitext
<div style="background-image:expres/**/sion(alert('boo4'))">evil4</div>
!! html/php
<div style="background-image:expres sion(alert(&#39;boo4&#39;))">evil4</div>
!! html/parsoid
<div style="background-image:expres sion(alert('boo4'))" data-parsoid='{"stx":"html","a":{"style":"background-image:expres sion(alert(&#39;boo4&#39;))"},"sa":{"style":"background-image:expres/**/sion(alert(&#39;boo4&#39;))"}}'>evil4</div>
!! end

!! test
CSS safety test (all browsers): vertical tab (T57332 / CVE-2013-4567)
!! wikitext
<p style="font-size: 100px; background-image:url\b(https://www.google.com/images/srpr/logo6w.png)">A</p>
!! html/php
<p style="/* invalid control char */">A</p>
!! html/parsoid
<p style="/* invalid control char */" data-parsoid='{"stx":"html","a":{"style":"/* invalid control char */"},"sa":{"style":"font-size: 100px; background-image:url\\b(https://www.google.com/images/srpr/logo6w.png)"}}'>A</p>
!! end

!! test
Opera -o-link CSS
!! options
parsoid=wt2html,html2html
!! wikitext
<div
title="&#100;&#97;&#116;&#97;&#58;&#116;&#101;&#120;&#116;&#47;&#104;&#116;&#109;&#108;&#44;&#60;&#105;&#109;&#103;&#32;&#115;&#114;&#99;&#61;&#49;&#32;&#111;&#110;&#101;&#114;&#114;&#111;&#114;&#61;&#97;&#108;&#101;&#114;&#116;&#40;&#49;&#41;&#62;"
style="-o-link:attr(title);-o-link-source:current">X</div>
!! html/php
<div title="data:text/html,&lt;img src=1 onerror=alert(1)&gt;" style="/* insecure input */">X</div>
!! html/parsoid
<div title="data:text/html,&lt;img src=1 onerror=alert(1)>" style="/* insecure input */" data-parsoid='{"stx":"html","a":{"title":"data:text/html,&lt;img src=1 onerror=alert(1)>","style":"/* insecure input */"},"sa":{"title":"&amp;#100;&amp;#97;&amp;#116;&amp;#97;&amp;#58;&amp;#116;&amp;#101;&amp;#120;&amp;#116;&amp;#47;&amp;#104;&amp;#116;&amp;#109;&amp;#108;&amp;#44;&amp;#60;&amp;#105;&amp;#109;&amp;#103;&amp;#32;&amp;#115;&amp;#114;&amp;#99;&amp;#61;&amp;#49;&amp;#32;&amp;#111;&amp;#110;&amp;#101;&amp;#114;&amp;#114;&amp;#111;&amp;#114;&amp;#61;&amp;#97;&amp;#108;&amp;#101;&amp;#114;&amp;#116;&amp;#40;&amp;#49;&amp;#41;&amp;#62;","style":"-o-link:attr(title);-o-link-source:current"}}'>X</div>
!! end

!! test
Table attribute legitimate extension
!! wikitext
{|
!+ style="<nowiki>color:blue</nowiki>"|status
|}
!! html
<table>
<tbody><tr>
<th style="color:blue">status
</th></tr></tbody></table>
!! end

!! test
Table attribute safety
!! wikitext
{|
!+ style="<nowiki>border-width:expression(0+alert(document.cookie))</nowiki>"|status
|}
!! html
<table>
<tbody><tr>
<th style="/* insecure input */">status
</th></tr></tbody></table>
!! end

!! test
CSS line continuation 1
!! wikitext
<div style="background-image: u\&#10;rl(test.jpg);"></div>
!! html
<div style="/* insecure input */"></div>
!! end

!! test
CSS line continuation 2
!! wikitext
<div style="background-image: u\&#13;rl(test.jpg); "></div>
!! html
<div style="/* invalid control char */"></div>
!! end

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

!! test
Expansion of multi-line templates in attribute values (T8255)
!! wikitext
<div style="background: {{identity|#00FF00}}">-</div>
!! html
<div style="background: #00FF00">-</div>
!! end

!! test
Expansion of multi-line templates in attribute values (T8255 sanity check)
!! wikitext
<div style="background:
#00FF00">-</div>
!! html/php
<div style="background: #00FF00">-</div>
!! html/parsoid
<div style="background:
#00FF00">-</div>
!! end

!! test
Expansion of multi-line templates in attribute values (T8255 sanity check 2)
!! wikitext
<div style="background: &#10;#00FF00">-</div>
!! html
<div style="background: &#10;#00FF00">-</div>
!! end

!! test
Tags which are hidden from tidiers cannot pass through the Sanitizer
!! wikitext
<mw:toc><script>alert();</script></mw:toc>
!! html+tidy
<p>&lt;mw:toc&gt;&lt;script&gt;alert();&lt;/script&gt;&lt;/mw:toc&gt;
</p>
!! end

###
### Parser hooks (see tests/parser/ParserTestParserHook.php for the <tag> extension)
###

!! test
Parser hook: empty input
!! wikitext
<tag></tag>
!! html/php
<pre>''
array (
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: empty input using terminated empty elements
!! options
parsoid=wt2html,html2html
!! wikitext
<tag/>
!! html/php
<pre>NULL
array (
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

!! test
Parser hook: empty input using terminated empty elements (space before)
!! wikitext
<tag />
!! html/php
<pre>NULL
array (
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

!! test
Parser hook: basic input
!! wikitext
<tag>input</tag>
!! html/php
<pre>'input'
array (
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"input"}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: case insensitive
!! options
parsoid=wt2html,html2html
!! wikitext
<TAG>input</TAG>
!! html/php
<pre>'input'
array (
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"input"}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: case insensitive, redux
!! options
parsoid=wt2html,html2html
!! wikitext
<TaG>input</TAg>
!! html/php
<pre>'input'
array (
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"input"}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

!! test
Parser hook: nested tags
!! options
parsoid=wt2html
!! wikitext
<tag><tag></tag></tag>
!! html/php+untidy
<pre>
'<tag>'
array (
)
</pre>&lt;/tag&gt;
!! html/php+tidy
<pre>'<tag>'
array (
)
</tag></pre><p>&lt;/tag&gt;</p>
!! html/parsoid
<pre typeof="mw:Extension/tag" about="#mwt2" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"&lt;tag>"}}'></pre><p>&lt;/tag></p>
!! end

!! test
Parser hook: basic arguments
!! wikitext
<tag width="200" height="100" depth="50" square=""></tag>
!! html/php
<pre>''
array (
  'width' =&gt; '200',
  'height' =&gt; '100',
  'depth' =&gt; '50',
  'square' =&gt; '',
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: basic arguments, variations
!! options
parsoid=wt2html,html2html
!! wikitext
<tag width=200 height = "100" depth = '50' square></tag>
!! html/php
<pre>''
array (
  'width' =&gt; '200',
  'height' =&gt; '100',
  'depth' =&gt; '50',
  'square' =&gt; '',
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

!! test
Parser hook: argument containing a forward slash (T7344)
!! wikitext
<tag filename="/tmp/bla"></tag>
!! html/php
<pre>''
array (
  'filename' =&gt; '/tmp/bla',
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"filename":"/tmp/bla"},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: empty input using terminated empty elements (T4374)
!! options
parsoid=wt2html,html2html
!! wikitext
<tag foo=bar/>text
!! html/php
<pre>NULL
array (
  'foo' =&gt; 'bar',
)
</pre><p>text</p>
!! html/parsoid
<pre typeof="mw:Extension/tag" about="#mwt2" data-mw='{"name":"tag","attrs":{"foo":"bar"}}'></pre><p>text</p>
!! end

## </tag> should be output literally since there is no matching tag that begins it
## Don't expect parsoid to rt this form.
!! test
Parser hook: basic arguments using terminated empty elements (T4374)
!! options
parsoid=wt2html
!! wikitext
<tag width=200 height = "100" depth = '50' square/>
other stuff
</tag>
!! html/php
<pre>NULL
array (
  'width' =&gt; '200',
  'height' =&gt; '100',
  'depth' =&gt; '50',
  'square' =&gt; '',
)
</pre>
<p>other stuff
&lt;/tag&gt;
</p>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""}}' about="#mwt2"></pre><p>other stuff
&lt;/tag></p>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: Don't allow unclosed extension tags
!! options
parsoid=wt2html
!! wikitext
test <tag>123

this is a '''test'''
!! html/php
<p>test &lt;tag&gt;123
</p><p>this is a <b>test</b>
</p>
!! html/parsoid
<p>test &lt;tag>123</p>

<p>this is a <b>test</b></p>
!! end

!! test
Parser hook: horizontal rule inside extension tag that outputs <pre>
!! wikitext
<tag>
Hello
<hr/>
Goodbye
</tag>
!! html/php
<pre>'
Hello
<hr />
Goodbye
'
array (
)
</pre>
!! end

###
### (see tests/parser/ParserTestParserHook.php for the <statictag> extension)
###

!! test
Parser hook: static parser hook not inside a comment
!! wikitext
<statictag>hello, world</statictag>

<statictag action="flush" />
!! html/php
<p><br />
hello, world
</p>
!! html/parsoid
<p><span typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{},"body":{"extsrc":"hello, world"}}' about="#mwt2"></span></p>
<p><span typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{"action":"flush"}}' about="#mwt4">hello, world</span></p>
!! end

!! test
Parser hook: static parser hook inside a comment
!! wikitext
<!-- <statictag>hello, world</statictag> -->
<statictag action="flush" />
!! html/php
<p><br />
</p>
!! html/parsoid
<!-- <statictag&#x3E;hello, world</statictag&#x3E; -->
<p><span typeof='mw:Extension/statictag' data-mw='{"name":"statictag","attrs":{"action":"flush"}}' data-parsoid='{}' about='#mwt2'></span></p>
!! end

# Nested template calls; this case was broken by Parser.php rev 1.506,
# since reverted.

!! article
Template:One-parameter
!! text
(My parameter is: {{{1}}})
!! endarticle

!! article
Template:Map-one-parameter
!! text
{{{{{1}}}|{{{2}}}}}
!! endarticle

!! test
Nested template calls
!! wikitext
{{Map-one-parameter|One-parameter|param}}
!! html
<p>(My parameter is: param)
</p>
!! end


###
### Sanitizer
###

!! test
Sanitizer: Closing of open tags
!! wikitext
<s></s><table></table>
!! html/php+tidy
<p><s></s></p><table></table>
!! html/parsoid
<p><s data-parsoid='{"stx":"html"}'></s></p><table data-parsoid='{"stx":"html"}'></table>
!! end

# Legacy parser adds an extra newline (seen as a space) which Parsoid does not
!! test
Sanitizer: Closing of open but not closed tags
!! wikitext
<s>foo
!! html/php
<p><s>foo
</s></p>
!! html/parsoid
<p><s data-parsoid='{"stx":"html","autoInsertedEnd":true}'>foo</s></p>
!! end

!! test
Sanitizer: Closing of closed but not open tags
!! options
parsoid=wt2html
!! wikitext
</s>
!! html+tidy
<p class="mw-empty-elt">
</p>
!! end

!! test
Sanitizer: Closing of closed but not open table tags
!! options
parsoid=wt2html
!! wikitext
Table not started</td></tr></table>
!! html+tidy
<p>Table not started</p>
!! end

!! test
Sanitizer: Escaping of spaces, multibyte characters, colons & other stuff in id=""
!! options
title=[[Main Page]]
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
<span id="æ: v">byte</span>[[#æ: v|backlink]]
!! html/php
<p><span id="æ:_v">byte</span><a href="#æ:_v">backlink</a>
</p>
!! html/parsoid
<p><span id="æ:_v" data-parsoid='{"stx":"html","a":{"id":"æ:_v"},"sa":{"id":"æ: v"}}'>byte</span><a rel="mw:WikiLink" href="./Main_Page#æ:_v" data-parsoid='{"stx":"piped","a":{"href":"./Main_Page#æ:_v"},"sa":{"href":"#æ: v"}}'>backlink</a></p>
!! end

!! test
Sanitizer: Escaping of spaces, multibyte characters, colons & other stuff in id="" (legacy)
!! config
wgFragmentMode=[ 'legacy' ]
!! wikitext
<span id="æ: v">byte</span>[[#æ: v|backlink]]
!! html/php
<p><span id=".C3.A6:_v">byte</span><a href="#.C3.A6:_v">backlink</a>
</p>
!! end

# In HTML5, the restrictions are that id must contain at least one character,
# and must not contain any space characters.
!! test
Sanitizer: Validating the contents of the id attribute (T6515)
!! options
disabled
!! wikitext
<br id="" /><br id="a space" />
!! html
Something ...
!! end

# In HTML5, id must be unique amongst all the ids in the element's home subtree.
!! test
Sanitizer: Validating id attribute uniqueness (T6515, T8301)
!! options
disabled
!! wikitext
<br id="foo" /><br id="foo" />
!! html
Something need to be done. foo-2 ? 
!! end

!! test
Sanitizer: Validating that <meta> and <link> work, but only for Microdata
!! wikitext
<div itemscope>
	<meta itemprop="hello" content="world">
	<meta http-equiv="refresh" content="5">
	<meta itemprop="hello" http-equiv="refresh" content="5">
	<link itemprop="hello" href="{{SERVER}}">
	<link rel="stylesheet" href="{{SERVER}}">
	<link rel="stylesheet" itemprop="hello" href="{{SERVER}}">
</div>
!! html
<div itemscope="">
<p>	<meta itemprop="hello" content="world" />
	&lt;meta http-equiv="refresh" content="5"&gt;
	<meta itemprop="hello" content="5" />
	<link itemprop="hello" href="http&#58;//example.org" />
	&lt;link rel="stylesheet" href="<a rel="nofollow" class="external free" href="http://example.org">http://example.org</a>"&gt;
	<link itemprop="hello" href="http&#58;//example.org" />
</p>
</div>
!! end

!! test
Sanitizer: Strip comments from CSS attributes
!! options
parsoid=wt2html,wt2wt
!! wikitext
<span style="margin:/*negate mbox-text padding */-0.125em -0.45em; /*rainbow*/rgba(255, 0, 0, 0.3)">2013</span>
!! html/php
<p><span style="margin: -0.125em -0.45em;  rgba(255, 0, 0, 0.3)">2013</span>
</p>
!! html/parsoid
<p><span style="margin: -0.125em -0.45em;  rgba(255, 0, 0, 0.3)">2013</span></p>
!! end

!! test
Sanitizer: Avoid unnecessary percent encoded characters in interwiki links
!! wikitext
[[meatball:Soft"Security]]
!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?Soft%22Security" class="extiw" title="meatball:Soft&quot;Security">meatball:Soft"Security</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href='http://www.usemod.com/cgi-bin/mb.pl?Soft"Security' title='meatball:Soft"Security'>meatball:Soft"Security</a></p>
!! end

!! test
Sanitizer: angle brackets are invalid, even in interwiki links (T182338)
!! wikitext
[[meatball:Foo<Bar]]
[[meatball:Foo>Bar]]
[[meatball:Foo&lt;bar]]
[[meatball:Foo&gt;bar]]
!! html/php
<p>[[meatball:Foo&lt;Bar]]
[[meatball:Foo&gt;Bar]]
[[meatball:Foo&lt;bar]]
[[meatball:Foo&gt;bar]]
</p>
!! html/parsoid
<p>[[meatball:Foo&lt;Bar]]
[[meatball:Foo>Bar]]
[[meatball:Foo<span typeof="mw:Entity" data-parsoid='{"src":"&amp;lt;","srcContent":"&lt;"}'>&lt;</span>bar]]
[[meatball:Foo<span typeof="mw:Entity" data-parsoid='{"src":"&amp;gt;","srcContent":">"}'>></span>bar]]</p>
!! end

!! test
Language converter: output gets cut off unexpectedly (T7757)
!! options
language=zh
!! wikitext
this bit is safe: }-

but if we add a conversion instance: -{zh-cn:xxx;zh-tw:yyy}-

then we get cut off here: }-

all additional text is vanished
!! html/php
<p>this bit is safe: }-
</p><p>but if we add a conversion instance: xxx
</p><p>then we get cut off here: }-
</p><p>all additional text is vanished
</p>
!! html/parsoid
<p>this bit is safe: }-</p>
<p>but if we add a conversion instance: <span typeof="mw:LanguageVariant" data-parsoid='{"tSp":[6]}' data-mw-variant='{"twoway":[{"l":"zh-cn","t":"xxx"},{"l":"zh-tw","t":"yyy"}]}'></span></p>
<p>then we get cut off here: }-</p>
<p>all additional text is vanished</p>
!! end

!! test
Language converter glossary rules inside attributes (T119158)
!! options
language=sr variant=sr-el
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
-{H|foAjrjvi=>sr-el:" onload="alert(1)" data-foo="}-

[[File:Foobar.jpg|alt=-{}-foAjrjvi-{}-]]
!! html/php
<p class="mw-empty-elt">
</p><p><span class="mw-default-size" typeof="mw:Image"><a href="/wiki/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:Foobar.jpg"><img alt="&quot; onload=&quot;alert(1)&quot; data-foo=&quot;" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a></span>
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"foAjrjvi","l":"sr-el","t":"\" onload=\"alert(1)\" data-foo=\""}]}'/></p>

<p><span class="mw-default-size" typeof="mw:Image mw:ExpandedAttrs" about="#mwt1" data-mw='{"attribs":[["alt",{"html":"alt=&lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&apos;{\"disabled\":{\"t\":\"\"}}&apos; data-parsoid=&apos;{\"fl\":[],\"dsr\":[76,80,null,2]}&apos;>&lt;/span>foAjrjvi&lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&apos;{\"disabled\":{\"t\":\"\"}}&apos; data-parsoid=&apos;{\"fl\":[],\"dsr\":[88,92,null,2]}&apos;>&lt;/span>","txt":"foAjrjvi"}]]}'><a href="./Датотека:Foobar.jpg"><img alt="foAjrjvi" resource="./Датотека:Foobar.jpg" src="http://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":"./Датотека:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
!! end

!! test
Self closed html pairs (T7487)
!! wikitext
<center><font id="bug" />Centered text</center>
<div><font id="bug2" />In div text</div>
!! html+tidy
<center><font id="bug">Centered text</font></center><font id="bug"><div><font id="bug2">In div text</font></div></font>
!! end

!! test
Punctuation: nbsp before exclamation
!! wikitext
C'est grave !
!! html/php
<p>C'est grave&#160;!
</p>
!! html/parsoid
<p>C'est grave<span typeof="mw:DisplaySpace"> </span>!</p>
!! end

!! test
Punctuation: CSS !important (T13874)
!! wikitext
<div style="width:50% !important">important</div>
!! html
<div style="width:50% !important">important</div>
!! end

!! test
Punctuation: CSS ! important (T13874; with space after)
!! wikitext
<div style="width:50% ! important">important</div>
!! html
<div style="width:50% ! important">important</div>
!! end

!! test
HTML bullet list, closed tags (T7497)
!! wikitext
<ul>
<li>One</li>
<li>Two</li>
</ul>
!! html/php
<ul>
<li>One</li>
<li>Two</li>
</ul>
!! html/parsoid
<ul data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html"}'>One</li>
<li data-parsoid='{"stx":"html"}'>Two</li>
</ul>
!! end

!! test
HTML bullet list, unclosed tags (T7497)
!! wikitext
<ul>
<li>One
<li>Two
</ul>
!! html/php+tidy
<ul>
<li>One
</li><li>Two
</li></ul>
!! html/parsoid
<ul data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>One</li>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>Two</li>
</ul>
!! end

!! test
HTML ordered list, closed tags (T7497)
!! wikitext
<ol>
<li>One</li>
<li>Two</li>
</ol>
!! html/php
<ol>
<li>One</li>
<li>Two</li>
</ol>
!! html/parsoid
<ol data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html"}'>One</li>
<li data-parsoid='{"stx":"html"}'>Two</li>
</ol>
!! end

!! test
HTML ordered list, unclosed tags (T7497)
!! options
!! wikitext
<ol>
<li>One
<li>Two
</ol>
!! html/php+tidy
<ol>
<li>One
</li><li>Two
</li></ol>
!! html/parsoid
<ol data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>One</li>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>Two</li>
</ol>
!! end

!! test
HTML nested bullet list, closed tags (T7497)
!! wikitext
<ul>
<li>One</li>
<li>Two:
<ul>
<li>Sub-one</li>
<li>Sub-two</li>
</ul>
</li>
</ul>
!! html/php
<ul>
<li>One</li>
<li>Two:
<ul>
<li>Sub-one</li>
<li>Sub-two</li>
</ul>
</li>
</ul>
!! html/parsoid
<ul data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html"}'>One</li>
<li data-parsoid='{"stx":"html"}'>Two:
<ul data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html"}'>Sub-one</li>
<li data-parsoid='{"stx":"html"}'>Sub-two</li>
</ul>
</li>
</ul>
!! end

!! test
HTML nested bullet list, open tags (T7497)
!! wikitext
<ul>
<li>One
<li>Two:
<ul>
<li>Sub-one
<li>Sub-two
</ul>
</ul>
!! html+tidy
<ul>
<li>One
</li><li>Two:
<ul>
<li>Sub-one
</li><li>Sub-two
</li></ul>
</li></ul>
!! end

!! test
HTML nested ordered list, closed tags (T7497)
!! wikitext
<ol>
<li>One</li>
<li>Two:
<ol>
<li>Sub-one</li>
<li>Sub-two</li>
</ol>
</li>
</ol>
!! html
<ol>
<li>One</li>
<li>Two:
<ol>
<li>Sub-one</li>
<li>Sub-two</li>
</ol>
</li>
</ol>
!! end

!! test
HTML nested ordered list, open tags (T7497)
!! wikitext
<ol>
<li>One
<li>Two:
<ol>
<li>Sub-one
<li>Sub-two
</ol>
</ol>
!! html/php
<ol>
<li>One
</li><li>Two:
<ol>
<li>Sub-one
</li><li>Sub-two
</li></ol>
</li></ol>
!! html/parsoid
<ol>
<li>One
</li>
<li>Two:
<ol>
<li>Sub-one
</li>
<li>Sub-two
</li>
</ol>
</li>
</ol>
!! end

!! test
HTML ordered list item with parameters oddity
!! wikitext
<ol><li id="fragment">One</li>
</ol>
!! html
<ol><li id="fragment">One</li>
</ol>
!! end

# parsoid doesn't explicitly mark autonumbered links, see T55505
!!test
T7918: autonumbering
!! wikitext
[http://first/] [http://second] [ftp://ftp]

ftp://inlineftp

[mailto:enclosed@mail.tld With target]

[mailto:enclosed@mail.tld]

mailto:inline@mail.tld
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://first/">[1]</a> <a rel="nofollow" class="external autonumber" href="http://second">[2]</a> <a rel="nofollow" class="external autonumber" href="ftp://ftp">[3]</a>
</p><p><a rel="nofollow" class="external free" href="ftp://inlineftp">ftp://inlineftp</a>
</p><p><a rel="nofollow" class="external text" href="mailto:enclosed@mail.tld">With target</a>
</p><p><a rel="nofollow" class="external autonumber" href="mailto:enclosed@mail.tld">[4]</a>
</p><p><a rel="nofollow" class="external free" href="mailto:inline@mail.tld">mailto:inline@mail.tld</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://first/" class="external autonumber"></a> <a rel="mw:ExtLink" href="http://second" class="external autonumber"></a> <a rel="mw:ExtLink" href="ftp://ftp" class="external autonumber"></a></p>
<p><a rel="mw:ExtLink" href="ftp://inlineftp" class="external free">ftp://inlineftp</a></p>
<p><a rel="mw:ExtLink" href="mailto:enclosed@mail.tld" class="external text">With target</a></p>
<p><a rel="mw:ExtLink" href="mailto:enclosed@mail.tld" class="external autonumber"></a></p>
<p><a rel="mw:ExtLink" href="mailto:inline@mail.tld" class="external free">mailto:inline@mail.tld</a></p>
!! end


#
# Security and HTML correctness
# From Nick Jenkins' fuzz testing
#

!! test
Fuzz testing: Parser13
!! wikitext
{| 
| http://a|
!! html
<table>
<tbody><tr>
<td>
</td>
</tr>
</tbody></table>
!! end

# Note that Parsoid output differs from the PHP parser here: the PHP
# parser breaks the URL for the magic word, while in Parsoid the URL
# production takes precedence.
!! test
Fuzz testing: Parser14
!! wikitext
==onmouseover===
http://__TOC__
!! html/php+untidy
<h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
http://<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#onmouseover.3D"><span class="tocnumber">1</span> <span class="toctext">onmouseover=</span></a></li>
</ul>
</div>

!! html/php+tidy
<h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2><p>
http://</p><div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#onmouseover.3D"><span class="tocnumber">1</span> <span class="toctext">onmouseover=</span></a></li>
</ul>
</div>
!! html/parsoid
<h2 id="onmouseover="><span id="onmouseover.3D" typeof="mw:FallbackId"></span>onmouseover=</h2>
<p><a rel="mw:ExtLink" href="http://__TOC__" class="external free" data-parsoid='{"stx":"url"}'>http://__TOC__</a></p>
!! end

!! test
Fuzz testing: Parser14-table
!! options
parsoid=wt2html,html2html
!! wikitext
==a==
{| STYLE=__TOC__
!! html/php+untidy
<h2><span class="mw-headline" id="a">a</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: a">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<table style="&#95;_TOC&#95;_">
<tr><td></td></tr>
</table>
!! html/php+tidy
<h2><span class="mw-headline" id="a">a</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: a">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<table style="&#95;_TOC&#95;_">
<tbody><tr><td></td></tr>
</tbody></table>
!! html/parsoid
<h2 id="a">a</h2>
<table style="__TOC__"></table>
!! end

# Known to produce bogus xml (extra </td>)
# Don't add the html/php section since it generates broken HTML
!! test
Fuzz testing: Parser16
!! wikitext
{|
!https://||||||
!! html+tidy
<table>
<tbody><tr>
<th>https://</th>
<th></th>
<th></th>
<th>

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

!! test
Fuzz testing: Parser21
!! wikitext
{|
!irc://{{ftp://a" onmouseover="alert('hello world');"
|
!! html
<table>
<tbody><tr>
<th><a rel="nofollow" class="external free" href="irc://{{ftp://a">irc://{{ftp://a</a>" onmouseover="alert('hello world');"
</th>
<td>
</td>
</tr>
</tbody></table>
!! end

!! test
Fuzz testing: Parser22
!! wikitext
http://===r:::https://b

{|
!! html/php
<p><a rel="nofollow" class="external free" href="http://===r:::https://b">http://===r:::https://b</a>
</p>
<table>
<tbody><tr><td></td></tr>
</tbody></table>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://===r:::https://b" class="external free" data-parsoid='{"stx":"url"}'>http://===r:::https://b</a></p>

<table data-parsoid='{"autoInsertedEnd":true}'></table>
!! end

# The above 'Parser24' fuzz test exposed a tokenizer bug (T221384);
# this is a minimized version of the above test to catch regressions.
!! test
Fuzz testing: Parser24 (minimized)
!! options
parsoid=wt2html
!! wikitext
{{<u {{{{[[Sx-->}}
!! html/php+tidy
<p>{{<u>}}
</u></p>
!! html/parsoid
<p>{{<u data-parsoid='{"stx":"html","a":{"{{{{[[Sx--":null},"sa":{"{{{{[[Sx--":""},"autoInsertedEnd":true}'>}}</u></p>
!! end

## Remex doesn't account for fostered content.
## Known to produce bad XML for now
!! test
Fuzz testing: Parser24
!! options
parsoid=wt2html
!! wikitext
{|
{{{|
<u CLASS=
| {{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}} >
<br style="onmouseover='alert(document.cookie);' " />

MOVE YOUR MOUSE CURSOR OVER THIS TEXT
|
!! html/php+untidy
<table>
{{{|
<u class="&#124;">}}}} &gt;
<br style="onmouseover=&#39;alert(document.cookie);&#39;" />

MOVE YOUR MOUSE CURSOR OVER THIS TEXT
<tr>
<td></u>
</td>
</tr>
</table>
!! html/php+tidy

{{{|
<u class="&#124;">}}}} &gt;
<br style="onmouseover=&#39;alert(document.cookie);&#39;" />

MOVE YOUR MOUSE CURSOR OVER THIS TEXT
</u><table><tbody><tr>
<td>
</td>
</tr>
</tbody></table>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>
{{{|
<u class="|" data-parsoid='{"stx":"html","a":{"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--":null},"sa":{"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--":""},"autoInsertedEnd":true}'><meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>}}}} >
<br style="onmouseover='alert(document.cookie);' " data-parsoid='{"stx":"html","selfClose":true}'/>

MOVE YOUR MOUSE CURSOR OVER THIS TEXT</u></p>
<table data-parsoid='{"autoInsertedEnd":true}'><tbody><tr data-parsoid='{"autoInsertedStart":true}'><td></td></tr></tbody></table>
!! end

# Note: the current result listed for this is not what the original one was,
# but the original bug was JavaScript injection, which is fixed in any case.
# It's not clear that the original result listed was any more correct than the
# current one.  Original result:
# <p>{{{| 
# </p>
# <li class="&#124;&#124;">
# }}}blah" onmouseover="alert('hello world');" align="left"<b>MOVE MOUSE CURSOR OVER HERE</b>
!!test
Fuzz testing: Parser25 (T8055)
!! wikitext
{{{
| 
<LI CLASS=||
 >
}}}blah" onmouseover="alert('hello world');" align="left"'''MOVE MOUSE CURSOR OVER HERE
!! html/php
<p>&lt;LI CLASS=blah" onmouseover="alert('hello world');" align="left"<b>MOVE MOUSE CURSOR OVER HERE</b>
</p>
!! html/parsoid
<span about="#mwt1" typeof="mw:Param" data-parsoid='{"pi":[[{"k":"1"},{"k":"2"},{"k":"3"}]]}' data-mw='{"parts":[{"templatearg":{"target":{"wt":"\n"},"params":{"1":{"wt":" \n&lt;LI CLASS="},"2":{"wt":""},"3":{"wt":"\n >\n"}},"i":0}},"blah\" onmouseover=\"alert(&#39;hello world&#39;);\" align=\"left\"&#39;&#39;&#39;MOVE MOUSE CURSOR OVER HERE"]}'> 
</span><p about="#mwt1">&lt;LI CLASS=blah" onmouseover="alert('hello world');" align="left"<b>MOVE MOUSE CURSOR OVER HERE</b></p>
!! end

!!test
Fuzz testing: URL adjacent extension (with space, clean)
!! wikitext
http://example.com <nowiki>junk</nowiki>
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a> junk
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a> <span typeof="mw:Nowiki">junk</span></p>
!! end

!!test
Fuzz testing: URL adjacent extension (no space, dirty; nowiki)
!! wikitext
http://example.com<nowiki>junk</nowiki>
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>junk
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a><span typeof="mw:Nowiki">junk</span></p>
!! end

!! test
Fuzz testing: URL adjacent extension (no space, dirty; pre)
!! wikitext
http://example.com<pre>junk</pre>
!! html/php+untidy
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a><pre>junk</pre>
!! html/php+tidy
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></p><pre>junk</pre>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a></p><pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"junk"}}'>junk</pre>
!! end

# Parsoid will emit the newline literally in wt2wt; see next test case.
!! test
Fuzz testing: encoded newline in generated HTML replacements (T8577)
!! options
parsoid=wt2html
!! wikitext
<pre dir="&#10;"></pre>
!! html/php
<pre dir="&#10;"></pre>
!! html/parsoid
<pre dir="
" typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{"dir":""},"body":{"extsrc":""}}'></pre>
!! end

!! test
Fuzz testing: encoded newline in generated HTML replacements, html2wt (T8577)
!! options
parsoid=html2wt
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" dir="
" data-mw='{"name":"pre","attrs":{"dir":"\n"},"body":{"extsrc":""}}'></pre>
!! wikitext
<pre dir="
"></pre>
!! html/php
<pre dir=""></pre>
!! end

!! test
Templates in extension attributes are not expanded
!! wikitext
<pre dir="{{1x|ltr}}"></pre>
!! html/php
<pre dir="{{1x|ltr}}"></pre>
!! html/parsoid
<pre dir="{{1x|ltr}}" typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{"dir":"{{1x|ltr}}"},"body":{"extsrc":""}}'></pre>
!! end

!! test
Parsing optional HTML elements (T8171)
!! options
!! wikitext
<table>
  <tr>
    <td> Some tabular data</td>
    <td> More tabular data ...
    <td> And yet som tabular data</td>
  </tr>
</table>
!! html
<table>
  <tbody><tr>
    <td> Some tabular data</td>
    <td> More tabular data ...
    </td><td> And yet som tabular data</td>
  </tr>
</tbody></table>
!! end

!! test
Correct handling of <td>, <tr> (T8171)
!! options
!! wikitext
<table>
  <tr>
    <td> Some tabular data</td>
    <td> More tabular data ...</td>
    <td> And yet som tabular data</td>
  </tr>
</table>
!! html
<table>
  <tbody><tr>
    <td> Some tabular data</td>
    <td> More tabular data ...</td>
    <td> And yet som tabular data</td>
  </tr>
</tbody></table>
!! end


!! test
Parsing crashing regression (fr:JavaScript)
!! wikitext
</body></x>
!! html
<p>&lt;/body&gt;&lt;/x&gt;
</p>
!! end

!! test
Inline wiki vs wiki block nesting
!! wikitext
'''Bold paragraph

New wiki paragraph
!! html
<p><b>Bold paragraph</b>
</p><p>New wiki paragraph
</p>
!! end

# FIXME: The current php output is documented
# and desired output is the parsoid target.
!! test
Inline HTML vs wiki block nesting
!! wikitext
<b>Bold paragraph

New wiki paragraph
!! html/php+untidy
<p><b>Bold paragraph
</p><p>New wiki paragraph</b>
</p>
!! html/php+tidy
<p><b>Bold paragraph
</b></p><p><b>New wiki paragraph
</b></p>
!! html/parsoid
<p><b>Bold paragraph</b>
</p><p>New wiki paragraph
</p>
!! end

# Original result was this:
# <p><b>bold</b><b>bold<i>bolditalics</i></b>
# </p>
# While that might be marginally more intuitive, maybe, the six-apostrophe
# construct is clearly pathological and the result stated here (which is what
# the parser actually does) is about as reasonable as anything.
!!test
Mixing markup for italics and bold
!! options
!! wikitext
'''bold''''''bold''bolditalics'''''
!! html
<p>'<i>bold'</i><b>bold<i>bolditalics</i></b>
</p>
!! end


!! article
Xyzzyx
!! text
Article for special page transclusion test
!! endarticle

!! test
Special page transclusion
!! options
!! wikitext
{{Special:Prefixindex/Xyzzyx}}
!! html
<ul class="mw-prefixindex-list"><li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>
!! end

!! test
Special page transclusion twice (T7021)
!! options
!! wikitext
{{Special:Prefixindex/Xyzzyx}}
{{Special:Prefixindex/Xyzzyx}}
!! html
<ul class="mw-prefixindex-list"><li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>
<ul class="mw-prefixindex-list"><li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>
!! end

!! test
Transclusion of default MediaWiki message
!! wikitext
{{MediaWiki:Mainpage}}
!! html
<p>Main Page
</p>
!! end

!! test
Transclusion of nonexistent MediaWiki message
!! wikitext
{{MediaWiki:Mainpagexxx}}
!! html
<p><a href="/index.php?title=MediaWiki:Mainpagexxx&amp;action=edit&amp;redlink=1" class="new" title="MediaWiki:Mainpagexxx (page does not exist)">MediaWiki:Mainpagexxx</a>
</p>
!! end

!! test
Transclusion of MediaWiki message with underscore
!! wikitext
{{MediaWiki:history_short}}
!! html
<p>History
</p>
!! end

!! test
Transclusion of MediaWiki message with space
!! wikitext
{{MediaWiki:history short}}
!! html
<p>History
</p>
!! end

!! test
Invalid header with following text
!! wikitext
= x = y
!! html
<p>= x = y
</p>
!! end


!! test
Section extraction test (section 0)
!! options
section=0
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
!! end

!! test
Section extraction test (section 1)
!! options
section=1
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
==a==
===aa===
====aaa====
!! end

!! test
Section extraction test (section 2)
!! options
section=2
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===aa===
====aaa====
!! end

!! test
Section extraction test (section 3)
!! options
section=3
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
====aaa====
!! end

!! test
Section extraction test (section 4)
!! options
section=4
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
==b==
===ba===
===bb===
====bba====
===bc===
!! end

!! test
Section extraction test (section 5)
!! options
section=5
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===ba===
!! end

!! test
Section extraction test (section 6)
!! options
section=6
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===bb===
====bba====
!! end

!! test
Section extraction test (section 7)
!! options
section=7
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
====bba====
!! end

!! test
Section extraction test (section 8)
!! options
section=8
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===bc===
!! end

!! test
Section extraction test (section 9)
!! options
section=9
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
==c==
===ca===
!! end

!! test
Section extraction test (section 10)
!! options
section=10
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===ca===
!! end

!! test
Section extraction test (nonexistent section 11)
!! options
section=11
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
!! end

!! test
Section extraction test with bogus heading (section 1)
!! options
section=1
!! wikitext
==a==
==bogus== not a legal section
==b==
!! html/php
==a==
==bogus== not a legal section
!! end

!! test
Section extraction test with bogus heading (section 2)
!! options
section=2
!! wikitext
==a==
==bogus== not a legal section
==b==
!! html/php
==b==
!! end

!! test
Section extraction test with comment after heading (section 1)
!! options
section=1
!! wikitext
==a==
==b== <!-- -->
==c==
!! html/php
==a==
!! end

!! test
Section extraction test with comment after heading (section 2)
!! options
section=2
!! wikitext
==a==
==b== <!-- -->
==c==
!! html/php
==b== <!-- -->
!! end

!! test
Section extraction test with bogus <nowiki> heading (section 1)
!! options
section=1
!! wikitext
==a==
==bogus== <nowiki>not a legal section</nowiki>
==b==
!! html/php
==a==
==bogus== <nowiki>not a legal section</nowiki>
!! end

!! test
Section extraction test with bogus <nowiki> heading (section 2)
!! options
section=2
!! wikitext
==a==
==bogus== <nowiki>not a legal section</nowiki>
==b==
!! html/php
==b==
!! end

# Formerly testing for T4587, now resolved by the use of unmarked sections
# instead of respecting commented sections
!! test
Section extraction prefixed by comment (section 1)
!! options
section=1
!! wikitext
<!-- -->==sec1==
==sec2==
!! html/php
==sec2==
!!end

!! test
Section extraction prefixed by comment (section 2)
!! options
section=2
!! wikitext
<!-- -->==sec1==
==sec2==
!! html/php
!! end

# Formerly testing for T4607, now resolved by the use of unmarked sections
# instead of respecting HTML-style headings
!! test
Section extraction, mixed wiki and html (section 1)
!! options
section=1
!! wikitext
<h2>unmarked</h2>
unmarked
==1==
one
==2==
two
!! html/php
==1==
one
!! end

!! test
Section extraction, mixed wiki and html (section 2)
!! options
section=2
!! wikitext
<h2>unmarked</h2>
unmarked
==1==
one
==2==
two
!! html/php
==2==
two
!! end


# Formerly testing for T5342
!! test
Section extraction, heading surrounded by <noinclude>
!! options
section=1
!! wikitext
<noinclude>==unmarked==</noinclude>
==marked==
!! html/php
==marked==
!!end

# Test behavior of T21910
!! test
Sectiion with all-equals
!! options
section=2
!! wikitext
=== 
The line above must have a trailing space
=== <!--
--> <!-- -->
But just in case it doesn't...
!! html/php
=== <!--
--> <!-- -->
But just in case it doesn't...
!! end

!! test
Section replacement test (section 0)
!! options
replace=0,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
xxx

==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 1)
!! options
replace=1,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
xxx

==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 2)
!! options
replace=2,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
xxx

==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 3)
!! options
replace=3,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
xxx

==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 4)
!! options
replace=4,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
xxx

==c==
===ca===
!! end

!! test
Section replacement test (section 5)
!! options
replace=5,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
xxx

===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 6)
!! options
replace=6,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
xxx

===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 7)
!! options
replace=7,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
xxx

===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 8)
!! options
replace=8,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
xxx

==c==
===ca===
!!end

!! test
Section replacement test (section 9)
!! options
replace=9,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
xxx
!! end

!! test
Section replacement test (section 10)
!! options
replace=10,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
xxx
!! end

!! test
Section replacement test with initial whitespace (T15728)
!! options
replace=2,"xxx"
!! wikitext
 Preformatted initial line
==a==
===a===
!! html/php
 Preformatted initial line
==a==
xxx
!! end


!! test
Section extraction, heading followed by pre with 20 spaces (T8398)
!! options
section=1
!! wikitext
==a==
                    a
!! html/php
==a==
                    a
!! end

!! test
Section extraction, heading followed by pre with 19 spaces (T8398 sanity check)
!! options
section=1
!! wikitext
==a==
                   a
!! html/php
==a==
                   a
!! end


!! test
Section extraction, <pre> around bogus header (T12309)
!! options
section=2
!! wikitext
== Section One ==
<pre>
=======
</pre>

== Section Two ==
stuff
!! html/php
== Section Two ==
stuff
!! end

!! test
Section replacement, <pre> around bogus header (T12309)
!! options
replace=2,"xxx"
!! wikitext
== Section One ==
<pre>
=======
</pre>

== Section Two ==
stuff
!! html/php
== Section One ==
<pre>
=======
</pre>

xxx
!! end

!! test
Handling of &#x0A; in URLs
!! wikitext
*irc://&#x0A;a
!! html/php
<ul><li><a rel="nofollow" class="external free" href="irc://%0Aa">irc://%0Aa</a></li></ul>
!! html/parsoid
<ul><li><a rel="mw:ExtLink" href="irc://%0Aa" class="external free" data-parsoid='{"stx":"url","a":{"href":"irc://%0Aa"},"sa":{"href":"irc://&amp;#x0A;a"}}'>irc://%0Aa</a></li></ul>
!! end

!! test
Handling of %0A in URLs
!! wikitext
*irc://%0Aa
!! html/php
<ul><li><a rel="nofollow" class="external free" href="irc://%0Aa">irc://%0Aa</a></li></ul>
!! html/parsoid
<ul><li><a rel="mw:ExtLink" href="irc://%0Aa" class="external free">irc://%0Aa</a></li></ul>
!! end

# The PHP parser strips the empty tags out for giggles; parsoid doesn't.
!! test
5 quotes, code coverage +1 line
!! options
parsoid=wt2html
!! wikitext
'''''
!! html/php
!! html/parsoid
<p><b><i></i></b></p>
!! end

# same html as previous, but wikitext adjusted to match parsoid html2wt
# note that wt2html and html2html will put the <i> before the <b>
!! test
5 quotes, code coverage +1 line w/ nowiki (1)
!! options
parsoid=wt2wt,html2wt
!! wikitext
'''''<nowiki/>'''''
!! html/php
<p><i><b></b></i>
</p>
!! html/parsoid
<p><b><i></i></b></p>
!! end

# same as previous, just swapping the <i> and <b> in Parsoid output
!! test
5 quotes, code coverage +1 line w/ nowiki (2)
!! wikitext
'''''<nowiki/>'''''
!! html/php
<p><i><b></b></i>
</p>
!! html/parsoid
<p><i><b></b></i></p>
!! end

!! test
Special:Search page linking.
!! wikitext
{{Special:search}}
!! html
<p><a href="/wiki/Special:Search" title="Special:Search">Special:Search</a>
</p>
!! end

!! test
{{!}} is a magic word
!! wikitext
{{!}} is a magic word there and {{!}} is still a magic word here
| is not a magic word here but {{!}} is still a magic word here
!! html/php
<p>| is a magic word there and | is still a magic word here
| is not a magic word here but | is still a magic word here
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"!","function":"!"},"params":{},"i":0}}]}'>|</span> is a magic word there and <span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"!","function":"!"},"params":{},"i":0}}]}'>|</span> is still a magic word here
| is not a magic word here but <span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"!","function":"!"},"params":{},"i":0}}]}'>|</span> is still a magic word here</p>
!! end

!! test
Say the magic word
!! options
title=[[Parser test]]
!! wikitext
*{{PAGENAME}}
*{{PAGENAMEE}}
*{{FULLPAGENAME}}
*{{FULLPAGENAMEE}}
*{{BASEPAGENAME}}
*{{BASEPAGENAMEE}}
*{{SUBPAGENAME}}
*{{SUBPAGENAMEE}}
*{{ROOTPAGENAME}}
*{{ROOTPAGENAMEE}}
*{{TALKPAGENAME}}
*{{TALKPAGENAMEE}}
*{{SUBJECTPAGENAME}}
*{{SUBJECTPAGENAMEE}}
*{{NAMESPACEE}}
*{{NAMESPACE}}
*{{NAMESPACENUMBER}}
*{{TALKSPACE}}
*{{TALKSPACEE}}
*{{SUBJECTSPACE}}
*{{SUBJECTSPACEE}}
*{{Dynamic|{{NUMBEROFUSERS}}|{{NUMBEROFPAGES}}|{{CURRENTVERSION}}|{{CONTENTLANGUAGE}}|{{DIRECTIONMARK}}|{{CURRENTTIMESTAMP}}|{{NUMBEROFARTICLES}}}}
!! html
<ul><li>Parser test</li>
<li>Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li>Talk:Parser test</li>
<li>Talk:Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li class="mw-empty-elt"></li>
<li class="mw-empty-elt"></li>
<li>0</li>
<li>Talk</li>
<li>Talk</li>
<li class="mw-empty-elt"></li>
<li class="mw-empty-elt"></li>
<li><a href="/index.php?title=Template:Dynamic&amp;action=edit&amp;redlink=1" class="new" title="Template:Dynamic (page does not exist)">Template:Dynamic</a></li></ul>
!! end
### Note: Above tests excludes the "{{NUMBEROFADMINS}}" magic word because it generates a MySQL error when included.

!! test
HTML Hex character encoding (spells the word "JavaScript")
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
&#x4A;&#x061;&#x0076;&#x00061;&#x000053;&#x0000063;&#114;&#x0000069;&#00000112;&#x0000000074;
!! html/php
<p>&#x4a;&#x61;&#x76;&#x61;&#x53;&#x63;&#114;&#x69;&#112;&#x74;
</p>
!! html/parsoid
<p><span typeof="mw:Entity">J</span><span typeof="mw:Entity">a</span><span typeof="mw:Entity">v</span><span typeof="mw:Entity">a</span><span typeof="mw:Entity">S</span><span typeof="mw:Entity">c</span><span typeof="mw:Entity">r</span><span typeof="mw:Entity">i</span><span typeof="mw:Entity">p</span><span typeof="mw:Entity">t</span></p>
!! end

!! test
HTML Hex character encoding bogus encoding (T28437 regression check)
!! wikitext
&#xsee;&#XSEE;
!! html
<p>&amp;#xsee;&amp;#XSEE;
</p>
!! end

!! test
HTML Hex character encoding mixed case
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
&#xEE;&#Xee;
!! html/php
<p>&#xee;&#xee;
</p>
!! html/parsoid
<p><span typeof="mw:Entity">î</span><span typeof="mw:Entity">î</span></p>
!! end

# See: https://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.
# Note there are also weird legacy numeric entities which are mapped
# elsewhere; see T113194
!! test
Illegal character references (T106578, T113194)
!! options
parsoid={ "modes": ["wt2html","html2html"], "normalizePhp": true }
!! wikitext
; Null: &#00;
; FF: &#xC;
; CR: &#xD;
; Control (low): &#8;
; Control (high): &#x7F; &#x9F;
; Unsupported legacy: &#128; &#130; &#131; &#150; &#159;
; Surrogate: &#xD83D;&#xDCA9;
; Invalid characters: &#xfffe; &#xffff;
; This is an okay astral character: &#x1F4A9;
; This is an okay multi-codepoint HTML5 entity: &acE;
; This are valid wikitext-specific entities: &רלמ; &رلم;
; Highest valid characters: &#x10fffd; &#x10fffe; &#x10ffff;
!! html
<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>Unsupported legacy</dt>
<dd>&amp;#128; &amp;#130; &amp;#131; &amp;#150; &amp;#159;</dd>
<dt>Surrogate</dt>
<dd>&amp;#xD83D;&amp;#xDCA9;</dd>
<dt>Invalid characters</dt>
<dd>&amp;#xfffe; &amp;#xffff;</dd>
<dt>This is an okay astral character</dt>
<dd>&#x1f4a9;</dd>
<dt>This is an okay multi-codepoint HTML5 entity</dt>
<dd>&#8766;&#819;</dd>
<dt>This are valid wikitext-specific entities</dt>
<dd>&rlm; &rlm;</dd>
<dt>Highest valid characters</dt>
<dd>&#x10fffd; &#x10fffe; &#x10ffff;</dd></dl>
!! end

!! test
__FORCETOC__ override
!! wikitext
__NEWSECTIONLINK__
__FORCETOC__
!! html/php
<p><br />
</p>
!! end

!! test
ISBN code coverage
!! wikitext
ISBN  978-0-1234-56&#x20;789
!! html/php
<p><a href="/wiki/Special:BookSources/9780123456" class="internal mw-magiclink-isbn">ISBN 978-0-1234-56</a>&#x20;789
</p>
!! html/parsoid
<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
ISBN followed by 5 spaces
!! wikitext
ISBN    
!! html
<p>ISBN    
</p>
!! end

!! test
Double ISBN
!! wikitext
ISBN ISBN 1234567890
!! html/php
<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: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: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
ISBN with empty prefix (parsoid test)
!! wikitext
ISBN 1234567890
!! html/php
<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:WikiLink">ISBN 1234567890</a></p>
!! end

!! test
T24905: <abbr> followed by ISBN followed by </a>
!! wikitext
<abbr>(fr)</abbr> ISBN 2753300917 [http://www.example.com example.com]
!! html/php
<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:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 2753300917</a> <a rel="mw:ExtLink" href="http://www.example.com" class="external text">example.com</a></p>
!! end

!! test
Double RFC
!! wikitext
RFC RFC 1234
!! html/php
<p>RFC <a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc1234">RFC 1234</a>
</p>
!! html/parsoid
<p>RFC <a href="https://tools.ietf.org/html/rfc1234" rel="mw:ExtLink" class="external mw-magiclink">RFC 1234</a></p>
!! end

!! test
Double RFC with a wiki link
!! wikitext
RFC [[RFC 1234]]
!! html/php
<p>RFC <a href="/index.php?title=RFC_1234&amp;action=edit&amp;redlink=1" class="new" title="RFC 1234 (page does not exist)">RFC 1234</a>
</p>
!! html/parsoid
<p>RFC <a rel="mw:WikiLink" href="./RFC_1234" title="RFC 1234" class="new">RFC 1234</a></p>
!! end

!! test
RFC code coverage
!! wikitext
RFC   983&#x20;987
!! html/php
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc983">RFC 983</a>&#x20;987
</p>
!! html/parsoid
<p><a href="https://tools.ietf.org/html/rfc983" rel="mw:ExtLink" class="external mw-magiclink" data-parsoid='{"stx":"magiclink"}'>RFC   983</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#x20;","srcContent":" "}'> </span>987</p>
!! end

!! test
Another italics / bold test
!! wikitext
 ''' ''x'
!! html
<pre>'<i> </i>x'
</pre>
!!end

!! test
dt/dd/dl test
!! wikitext
:;;;::
!! html
<dl><dd><dl><dt><dl><dt><dl><dt><dl><dd><dl><dd></dd></dl></dd></dl></dt></dl></dt></dl></dt></dl></dd></dl>
!! end

!! test
[Before] HTML without raw HTML enabled ($wgRawHtml==false)
!! wikitext
<html><script>alert(1);</script></html>
!! html
<p>&lt;html&gt;&lt;script&gt;alert(1);&lt;/script&gt;&lt;/html&gt;
</p>
!! end

!! test
HTML with raw HTML ($wgRawHtml==true)
!! options
wgRawHtml=1
!! wikitext
<html><script>alert(1);</script></html>
!! html/php
<p><script>alert(1);</script>
</p>
!! html/parsoid
<p><script typeof="mw:Extension/html" about="#mwt3" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;script>alert(1);&lt;/script>"}}'>alert(1);</script></p>
!! end

!! test
Empty tag w/ raw HTML ($wgRawHtml==true)
!! options
wgRawHtml=1
!! wikitext
<html />
!! html/php
<p class="mw-empty-elt">
</p>
!! html/parsoid
<p><link typeof="mw:Extension/html" about="#mwt2" data-mw='{"name":"html","attrs":{}}'/></p>
!! end

!! test
Parents of subpages, one level up
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../|L2]]
!! html/php
<p><a href="/index.php?title=Subpage_test/L1/L2&amp;action=edit&amp;redlink=1" class="new" title="Subpage test/L1/L2 (page does not exist)">L2</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/L1/L2" title="Subpage test/L1/L2" data-parsoid='{"stx":"piped","a":{"href":"./Subpage_test/L1/L2"},"sa":{"href":"../"}}' class="new">L2</a></p>
!! end


!! test
Parents of subpages, one level up, not named
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../]]
!! html/php
<p><a href="/index.php?title=Subpage_test/L1/L2&amp;action=edit&amp;redlink=1" class="new" title="Subpage test/L1/L2 (page does not exist)">Subpage test/L1/L2</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/L1/L2" title="Subpage test/L1/L2" data-parsoid='{"stx":"simple","a":{"href":"./Subpage_test/L1/L2"},"sa":{"href":"../"}}' class="new">Subpage test/L1/L2</a></p>
!! end



!! test
Parents of subpages, two levels up
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../../|L1]]2

[[../../|L1]]l
!! html/php
<p><a href="/index.php?title=Subpage_test/L1&amp;action=edit&amp;redlink=1" class="new" title="Subpage test/L1 (page does not exist)">L1</a>2
</p><p><a href="/index.php?title=Subpage_test/L1&amp;action=edit&amp;redlink=1" class="new" title="Subpage test/L1 (page does not exist)">L1l</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/L1" title="Subpage test/L1" data-parsoid='{"stx":"piped","a":{"href":"./Subpage_test/L1"},"sa":{"href":"../../"}}' class="new">L1</a>2</p>

<p><a rel="mw:WikiLink" href="./Subpage_test/L1" title="Subpage test/L1" data-parsoid='{"stx":"piped","a":{"href":"./Subpage_test/L1"},"sa":{"href":"../../"},"tail":"l"}' class="new">L1l</a></p>
!! end

!! test
Parents of subpages, two levels up, without trailing slash or name.
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../..]]
!! html
<p>[[../..]]
</p>
!! end

!! test
Parents of subpages, two levels up, with lots of extra trailing slashes.
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../../////]]
!! html/php
<p><a href="/index.php?title=Subpage_test/L1&amp;action=edit&amp;redlink=1" class="new" title="Subpage test/L1 (page does not exist)">Subpage test/L1</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/L1" title="Subpage test/L1" data-parsoid='{"stx":"simple","a":{"href":"./Subpage_test/L1"},"sa":{"href":"../../////"}}' class="new">Subpage test/L1</a></p>
!! end

!! article
Subpage test/L1/L2/L3Sibling
!! text
Sibling article
!! endarticle

!! test
Transclusion of a sibling page (one level up)
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
{{../L3Sibling}}
!! html
<p>Sibling article
</p>
!! end

!! test
Transclusion of a child page
!! options
subpage title=[[Subpage test/L1/L2]]
!! wikitext
{{/L3Sibling}}
!! html
<p>Sibling article
</p>
!! end

# This is wt2html only in Parsoid because we add <nowiki>
# because of {{..}} and we don't expect to fix that to
# eliminate the nowikis selective for {{..}} markup.
!! test
Non-transclusion because of too many up levels
!! options
subpage title=[[Subpage test/L1/L2/L3]]
parsoid=wt2html
!! wikitext
{{../../../../More than parent}}
!! html/php
<p>{{../../../../More than parent}}
</p>
!! html/parsoid
<p>{{../../../../More than parent}}</p>
!! end

!! test
Definition list code coverage
!! options
parsoid=wt2html,html2html
!! wikitext
;title   :def
;title :def
;title:def
!! html/php
<dl><dt>title</dt>
<dd>def</dd>
<dt>title</dt>
<dd>def</dd>
<dt>title</dt>
<dd>def</dd></dl>
!! html/parsoid
<dl><dt>title   </dt><dd>def</dd>
<dt>title </dt><dd>def</dd>
<dt>title</dt><dd>def</dd></dl>
!! end

!! test
Don't fall for the self-closing div
!! wikitext
<div>hello world</div/>
!! html
<div>hello world</div>
!! end

!! test
MSGNW magic word
!! wikitext
{{MSGNW:msg}}
!! html/php
<p>&#91;&#91;:Template:Msg&#93;&#93;
</p>
!! end

!! test
RAW magic word
!! wikitext
{{RAW:QUERTY}}
!! html
<p><a href="/index.php?title=Template:QUERTY&amp;action=edit&amp;redlink=1" class="new" title="Template:QUERTY (page does not exist)">Template:QUERTY</a>
</p>
!! end

# This isn't needed for XHTML conformance, but would be handy as a fallback security measure
!! test
Always escape literal '>' in output, not just after '<'
!! wikitext
><>
!! html
<p>&gt;&lt;&gt;
</p>
!! end

!! test
Template caching
!! wikitext
{{Test}}
{{Test}}
!! html
<p>This is a test template
This is a test template
</p>
!! end


!! article
MediaWiki:Fake
!! text
==header==
!! endarticle

!! test
Inclusion of !userCanEdit() content
!! wikitext
{{MediaWiki:Fake}}
!! html
<h2><span class="mw-headline" id="header">header</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=MediaWiki:Fake&amp;action=edit&amp;section=T-1" title="Edit section: ">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end


!! test
Out-of-order TOC heading levels
!! wikitext
==2==
======6======
===3===
=1=
=====5=====
==2==
!! html
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#2"><span class="tocnumber">1</span> <span class="toctext">2</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#6"><span class="tocnumber">1.1</span> <span class="toctext">6</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#3"><span class="tocnumber">1.2</span> <span class="toctext">3</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-4"><a href="#1"><span class="tocnumber">2</span> <span class="toctext">1</span></a>
<ul>
<li class="toclevel-2 tocsection-5"><a href="#5"><span class="tocnumber">2.1</span> <span class="toctext">5</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#2_2"><span class="tocnumber">2.2</span> <span class="toctext">2</span></a></li>
</ul>
</li>
</ul>
</div>

<h2><span class="mw-headline" id="2">2</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: 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h6><span class="mw-headline" id="6">6</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: 6">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
<h3><span class="mw-headline" id="3">3</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: 3">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<h1><span class="mw-headline" id="1">1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: 1">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h5><span class="mw-headline" id="5">5</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: 5">edit</a><span class="mw-editsection-bracket">]</span></span></h5>
<h2><span class="mw-headline" id="2_2">2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end


!! test
ISBN with a dummy number
!! wikitext
ISBN ---
!! html
<p>ISBN ---
</p>
!! end


!! test
ISBN with space-delimited number
!! wikitext
ISBN 92 9017 032 8
!! html/php
<p><a href="/wiki/Special:BookSources/9290170328" class="internal mw-magiclink-isbn">ISBN 92 9017 032 8</a>
</p>
!! html/parsoid
<p><a href="./Special:BookSources/9290170328" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 92 9017 032 8</a></p>
!! end


!! test
ISBN with multiple spaces, no number
!! wikitext
ISBN  foo
!! html
<p>ISBN  foo
</p>
!! end


!! test
ISBN length
!! wikitext
ISBN 123456789

ISBN 1234567890

ISBN 12345678901
!! html/php
<p>ISBN 123456789
</p><p><a href="/wiki/Special:BookSources/1234567890" class="internal mw-magiclink-isbn">ISBN 1234567890</a>
</p><p>ISBN 12345678901
</p>
!! html/parsoid
<p>ISBN 123456789</p>

<p><a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a></p>

<p>ISBN 12345678901</p>
!! end


!! test
ISBN with trailing year (T9110)
!! wikitext
ISBN 1-234-56789-0 - 2006

ISBN 1 234 56789 0 - 2006
!! html/php
<p><a href="/wiki/Special:BookSources/1234567890" class="internal mw-magiclink-isbn">ISBN 1-234-56789-0</a> - 2006
</p><p><a href="/wiki/Special:BookSources/1234567890" class="internal mw-magiclink-isbn">ISBN 1 234 56789 0</a> - 2006
</p>
!! html/parsoid
<p><a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1-234-56789-0</a> - 2006</p>

<p><a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1 234 56789 0</a> - 2006</p>
!! end


!! test
anchorencode
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
{{anchorencode:foo bar©#%n}}
!! html/php
<p>foo_bar©#%n
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode:foo bar©#%n","function":"anchorencode"},"params":{},"i":0}}]}'>foo_bar©#%n</span></p>
!! end

!! test
anchorencode (legacy)
!! config
wgFragmentMode=[ 'legacy' ]
!! wikitext
{{anchorencode:foo bar©#%n}}
!! html/php
<p>foo_bar.C2.A9.23.25n
</p>
!! end

!! test
anchorencode trims spaces
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
{{anchorencode: __pretty__please__}}
!! html/php
<p>pretty_please
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: __pretty__please__","function":"anchorencode"},"params":{},"i":0}}]}'>pretty_please</span></p>
!! end

!! test
anchorencode deals with links
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
{{anchorencode: [[hello|world]] [[hi]]}}
!! html/php
<p>world_hi
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: [[hello|world]] [[hi]]","function":"anchorencode"},"params":{},"i":0}}]}'>world_hi</span></p>
!! end

!! test
anchorencode deals with templates
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
{{anchorencode: {{Foo}} x}}
!! html/php
<p>FOO_x
</p>
!! html/parsoid
<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: {{Foo}} x","function":"anchorencode"},"params":{},"i":0}}]}'>FOO_x</span></p>
!! end

!! test
anchorencode encodes like the TOC generator: (T20431)
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
===_ +:.3A%3A _ &&amp;]] x===
{{anchorencode: _ +:.3A%3A _ &&amp;]] x}}

__NOEDITSECTION__
!! html/php
<h3><span id=".2B:.3A.253A_.26.26.5D.5D_x"></span><span class="mw-headline" id="+:.3A%3A_&amp;&amp;]]_x">_ +:.3A%3A _ &amp;&amp;]] x</span></h3>
<p>+:.3A%253A_&amp;&amp;&#93;&#93;_x
</p><p><br />
</p>
!! html/parsoid
<h3 id="+:.3A%3A_&amp;&amp;]]_x"><span id=".2B:.3A.253A_.26.26.5D.5D_x" typeof="mw:FallbackId"></span>_ +:.3A%3A _ &amp;<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>]] x</h3>
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: _ +:.3A%3A _ &amp;&amp;amp;]] x","function":"anchorencode"},"params":{},"i":0}}]}'>+:.3A%253A_&amp;&amp;</span><span typeof="mw:Entity" about="#mwt1">]</span><span typeof="mw:Entity" about="#mwt1">]</span><span about="#mwt1">_x</span></p>
<meta property="mw:PageProp/noeditsection"/>
!! end

!! test
anchorencode encodes like the TOC generator: (T20431) (legacy)
!! config
wgFragmentMode=[ 'legacy' ]
!! wikitext
===_ +:.3A%3A&&amp;]]===
{{anchorencode: _ +:.3A%3A&&amp;]] }}
__NOEDITSECTION__
!! html/php
<h3><span class="mw-headline" id=".2B:.3A.253A.26.26.5D.5D">_ +:.3A%3A&amp;&amp;]]</span></h3>
<p>.2B:.3A.253A.26.26.5D.5D
</p>
!! end

!! test
T8200: blockquotes and paragraph formatting
!! wikitext
<blockquote>
foo
</blockquote>

bar

 baz
!! html
<blockquote>
<p>foo
</p>
</blockquote>
<p>bar
</p>
<pre>baz
</pre>
!! end

!! test
T10293: Use of center tag ruins paragraph formatting
!! wikitext
<center>
foo
</center>

bar

 baz
!! html
<center>
<p>foo
</p>
</center>
<p>bar
</p>
<pre>baz
</pre>
!! end

!!test
Parsing of overlapping (improperly nested) inline html tags
!! wikitext
<span><s>x</span></s>
!! html
<p><span><s>x</s></span>
</p>
!!end

###
### Language variants related tests
###

# Parsoid does not mark self-links.
# Parsoid does not convert links; PHP will do any necessary redirects.

!! test
Self-link in language variants
!! options
title=[[Dunav]] language=sr
!! wikitext
Both [[Dunav]] and [[Дунав]] are names for this river.
!! html/php
<p>Both <a class="mw-selflink selflink">Dunav</a> and <a class="mw-selflink selflink">Дунав</a> are names for this river.
</p>
!! html/parsoid
<p>Both <a rel="mw:WikiLink" href="./Dunav" title="Dunav" class="new">Dunav</a> and <a rel="mw:WikiLink" href="./Дунав" title="Дунав" class="new">Дунав</a> are names for this river.</p>
!! end

!! article
Дуна
!! text
content
!! endarticle

# T258856: Parsoid doesn't handle redlink processing correctly in this case
!! test
Link to another existing title shouldn't be parsed as self-link even if it's a variant of this title
!! options
title=[[Duna]] language=sr
!! wikitext
[[Дуна]] is not a self-link while [[Duna]] and [[Dуна]] are still self-links.
!! html/php
<p><a href="/wiki/%D0%94%D1%83%D0%BD%D0%B0" title="Дуна">Дуна</a> is not a self-link while <a class="mw-selflink selflink">Duna</a> and <a class="mw-selflink selflink">Dуна</a> are still self-links.
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Дуна" title="Дуна">Дуна</a> is not a self-link while <a rel="mw:WikiLink" href="./Duna" title="Duna" class="new">Duna</a> and <a rel="mw:WikiLink" href="./Dуна" title="Dуна" class="new">Dуна</a> are still self-links.</p>
!! end

# T258856: Parsoid doesn't handle redlink processing correctly in this case
!! test
Link to a section of a variant of this title shouldn't be parsed as self-link
!! options
title=[[Duna]] language=sr
!! wikitext
[[Dуна]] is a self-link while [[Dunа#Foo]] and [[Dуна#Foo]] are not self-links.
!! html/php
<p><a class="mw-selflink selflink">Dуна</a> is a self-link while <a href="/wiki/%D0%94%D1%83%D0%BD%D0%B0" title="Дуна">Dunа#Foo</a> and <a href="/wiki/%D0%94%D1%83%D0%BD%D0%B0" title="Дуна">Dуна#Foo</a> are not self-links.
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Dуна" title="Dуна" class="new">Dуна</a> is a self-link while <a rel="mw:WikiLink" href="./Dunа#Foo" title="Dunа" class="new">Dunа#Foo</a> and <a rel="mw:WikiLink" href="./Dуна#Foo" title="Dуна" class="new">Dуна#Foo</a> are not self-links.</p>
!! end

# T258856: Parsoid doesn't handle redlink processing correctly in this case
!! test
Link to pages in language variants
!! options
language=sr
!! wikitext
Main Page can be written as [[Маин Паге]]
!! html/php
<p>Main Page can be written as <a href="/wiki/Main_Page" title="Main Page">Маин Паге</a>
</p>
!! html/parsoid
<p>Main Page can be written as <a rel="mw:WikiLink" href="./Маин_Паге" title="Маин Паге" class="new">Маин Паге</a></p>
!! end


# T258856: Parsoid doesn't handle redlink processing correctly in this case
!! test
Multiple links to pages in language variants
!! options
language=sr
!! wikitext
[[Main Page]] can be written as [[Маин Паге]] same as [[Маин Паге]].
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a> can be written as <a href="/wiki/Main_Page" title="Main Page">Маин Паге</a> same as <a href="/wiki/Main_Page" title="Main Page">Маин Паге</a>.
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a> can be written as <a rel="mw:WikiLink" href="./Маин_Паге" title="Маин Паге" class="new">Маин Паге</a> same as <a rel="mw:WikiLink" href="./Маин_Паге" title="Маин Паге" class="new">Маин Паге</a>.</p>
!! end


!! test
Simple template in language variants
!! options
language=sr
!! wikitext
{{тест}}
!! html/php
<p>This is a test template
</p>
!! end


!! test
Template with explicit namespace in language variants
!! options
language=sr
!! wikitext
{{Template:тест}}
!! html/php
<p>This is a test template
</p>
!! end


!! test
Basic test for template parameter in language variants
!! options
language=sr
!! wikitext
{{парамтест|param=foo}}
!! html/php
<p>This is a test template with parameter foo
</p>
!! end

!! test
Simple category in language variants
!! options
language=sr cat
!! wikitext
[[Category:МедиаWики Усер'с Гуиде]]
!! html/php
cat=МедиаWики_Усер'с_Гуиде sort=
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Категорија:МедиаWики_Усер'с_Гуиде" data-parsoid='{"stx":"simple","a":{"href":"./Категорија:МедиаWики_Усер&#39;с_Гуиде"},"sa":{"href":"Category:МедиаWики Усер&#39;с Гуиде"}}'/>
!! end

!! article
Category:分类
!! text
blah
!! endarticle

!! article
Category:分類
!! text
blah
!! endarticle

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
!! test
Don't convert blue categorylinks to another variant (T35210)
!! options
cat
language=zh
parsoid=wt2html
!! wikitext
[[A]][[Category:分类]]
!! html/php
cat=分类 sort=
!! html/parsoid
<p><a rel="mw:WikiLink" href="./A" title="A" class="new">A</a></p>
<link rel="mw:PageProp/Category" href="./Category:分类"/>
!! end

!! test
Stripping -{}- tags (language variants)
!! options
language=sr
!! wikitext
Latin proverb: -{Ne nuntium necare}-
!! html/php
<p>Latin proverb: Ne nuntium necare
</p>
!! html/parsoid
<p>Latin proverb: <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"Ne nuntium necare"}}'></span></p>
!! end


!! test
Prevent conversion with -{}- tags (language variants)
!! options
language=sr variant=sr-ec
!! wikitext
Latinski: -{Ne nuntium necare}-
!! html/php
<p>Латински: Ne nuntium necare
</p>
!! html/parsoid
<p>Latinski: <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"Ne nuntium necare"}}'></span></p>
!! end


!! test
Prevent conversion of text with -{}- tags (language variants)
!! options
language=sr variant=sr-ec
!! wikitext
Latinski: -{Ne nuntium necare}-
!! html/php
<p>Латински: Ne nuntium necare
</p>
!! html/parsoid
<p>Latinski: <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"Ne nuntium necare"}}'></span></p>
!! end


!! test
Prevent conversion of links with -{}- tags (language variants)
!! options
language=sr variant=sr-ec
!! wikitext
-{[[Main Page]]}-
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"&lt;a rel=\"mw:WikiLink\" href=\"./Main_Page\" title=\"Main Page\" data-parsoid=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"./Main_Page\"},\"sa\":{\"href\":\"Main Page\"},\"dsr\":[2,15,2,2]}&#39;>Main Page&lt;/a>"}}'></span></p>
!! end


!! test
-{}- tags within headlines (within html for parserConvert())
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! options
language=sr variant=sr-ec
!! wikitext
==-{Naslov}-==

Note that even an unprotected headline ID is not affected by language
conversion:

==Latinski==
!! html/php
<h2><span id="-.7BNaslov.7D-"></span><span class="mw-headline" id="-{Naslov}-">Naslov</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Уредите одељак „Naslov”">уреди</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Ноте тхат евен ан унпротецтед хеадлине ИД ис нот аффецтед бy лангуаге
цонверсион:
</p>
<h2><span class="mw-headline" id="Latinski">Латински</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Уредите одељак „Латински”">уреди</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<h2 id="-{Naslov}-"><span id="-.7BNaslov.7D-" typeof="mw:FallbackId"></span><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"Naslov"}}'></span></h2>

<p>Note that even an unprotected headline ID is not affected by language
conversion:</p>

<h2 id="Latinski">Latinski</h2>
!! end

!! test
Explicit definition of language variant alternatives
!! options
language=zh variant=zh-tw
!! wikitext
-{zh:China;zh-tw:Taiwan}-, not China
!! html/php
<p>Taiwan, not China
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-parsoid='{"tSp":[6]}' data-mw-variant='{"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'></span>, not China</p>
!! end

!! test
Explicit definition of language variant alternatives (BCP 47 codes)
!! options
language=zh variant=zh-tw
!! wikitext
-{zh:China;zh-Hant-TW:Taiwan}-, not China
!! html/php
<p>Taiwan, not China
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-parsoid='{"tSp":[6]}' data-mw-variant='{"twoway":[{"l":"zh","t":"China"},{"l":"zh-Hant-TW","t":"Taiwan"}]}'></span>, not China</p>
!! end

!! test
Filter syntax for language variants
!! options
language=zh variant=zh-tw
!! wikitext
foo-{zh;zh-hans;zh-hant|blog, WEBJOURNAL, WEBLOG}-quux
!! html/php
<p>fooblog, WEBJOURNAL, WEBLOGquux
</p>
!! html/parsoid
<p>foo<span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["zh","zh-hans","zh-hant"],"t":"blog, WEBJOURNAL, WEBLOG"}}'></span>quux</p>
!! end

# Note that Parsoid post-processing for language variants needs to
# update the `title` attribute here, based on the mw:ExpandedAttrs property
!! test
Conversion around HTML tags
!! options
language=sr variant=sr-ec
!! wikitext
-{H|span=>sr-ec:script;title=>sr-ec:src}-
<span title="La-{sr-el:L;sr-ec:C}-tin">ski</span>
!! html/php
<p>
<span title="ЛаCтин">ски</span>
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-parsoid='{"tSp":[8]}' data-mw-variant='{"add":true,"oneway":[{"f":"span","l":"sr-ec","t":"script"},{"f":"title","l":"sr-ec","t":"src"}]}'/>
<span title="Latin" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"title"},{"html":"La&lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&#39;{\"twoway\":[{\"l\":\"sr-el\",\"t\":\"L\"},{\"l\":\"sr-ec\",\"t\":\"C\"}]}&#39; data-parsoid=&#39;{\"fl\":[],\"tSp\":[6],\"dsr\":[57,76,null,2]}&#39;>&lt;/span>tin"}]]}'>ski</span></p>
!! end

!! test
Explicit session-wise two-way language variant mapping (A flag and - flag)
!! options
language=zh variant=zh-tw
!! wikitext
This is -{zh:China; zh-tw:Taiwan}-, but we'll forget that now.

Taiwan is not China.

But -{A|zh:China; zh-tw:Taiwan}- is China,

(This-{-|zh:China; zh-tw:Taiwan}- should be stripped!)

and -{China}- is China.
!! html/php
<p>This is Taiwan, but we'll forget that now.
</p><p>Taiwan is not China.
</p><p>But Taiwan is Taiwan,
</p><p>(This should be stripped!)
</p><p>and China is China.
</p>
!! html/parsoid
<p>This is <span typeof="mw:LanguageVariant" data-mw-variant='{"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'></span>, but we'll forget that now.</p>
<p>Taiwan is not China.</p>
<p>But <span typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'></span> is China,</p>
<p>(This<meta typeof="mw:LanguageVariant" data-mw-variant='{"remove":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/> should be stripped!)</p>
<p>and <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"China"}}'></span> is China.</p>
!! end

!! test
Explicit session-wise one-way language variant mapping (A flag and - flag)
!! options
language=zh variant=zh-tw
!! wikitext
This is -{COUNTRY=>zh:China;COUNTRY=>zh-tw:Taiwan}-, but we'll forget that now.

COUNTRY is China or Taiwan.

But -{A|COUNTRY=>zh:China;COUNTRY=>zh-tw:Taiwan}- is COUNTRY,

(This-{-|COUNTRY=>zh:China;COUNTRY=>zh-tw:Taiwan}- should be stripped!)

and -{COUNTRY}- is COUNTRY.
!! html/php
<p>This is Taiwan, but we'll forget that now.
</p><p>COUNTRY is China or Taiwan.
</p><p>But Taiwan is Taiwan,
</p><p>(This should be stripped!)
</p><p>and COUNTRY is COUNTRY.
</p>
!! html/parsoid
<p>This is <span typeof="mw:LanguageVariant" data-mw-variant='{"oneway":[{"f":"COUNTRY","l":"zh","t":"China"},{"f":"COUNTRY","l":"zh-tw","t":"Taiwan"}]}'></span>, but we'll forget that now.</p>
<p>COUNTRY is China or Taiwan.</p>
<p>But <span typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"COUNTRY","l":"zh","t":"China"},{"f":"COUNTRY","l":"zh-tw","t":"Taiwan"}]}'></span> is COUNTRY,</p>
<p>(This<meta typeof="mw:LanguageVariant" data-mw-variant='{"oneway":[{"f":"COUNTRY","l":"zh","t":"China"},{"f":"COUNTRY","l":"zh-tw","t":"Taiwan"}],"remove":true}'/> should be stripped!)</p>
<p>and <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"COUNTRY"}}'></span> is COUNTRY.</p>
!! end

!! test
Explicit session-wise two-way language variant mapping (H flag for hide)
!! options
language=zh variant=zh-tw
!! wikitext
(This-{H|zh:China;zh-tw:Taiwan}- should be stripped!)

Taiwan is China.
!! html/php
<p>(This should be stripped!)
</p><p>Taiwan is Taiwan.
</p>
!! html/parsoid
<p>(This<meta typeof="mw:LanguageVariant" data-parsoid='{"tSp":[6]}' data-mw-variant='{"add":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/> should be stripped!)</p>
<p>Taiwan is China.</p>
!! end

!! test
Explicit session-wise one-way language variant mapping (H flag for hide)
!! options
language=zh variant=zh-tw
!! wikitext
(This-{H|COUNTRY=>zh:China;COUNTRY=>zh-tw:Taiwan}- should be stripped!)

COUNTRY is Taiwan or China.
!! html/php
<p>(This should be stripped!)
</p><p>Taiwan is Taiwan or China.
</p>
!! html/parsoid
<p>(This<meta typeof="mw:LanguageVariant" data-parsoid='{"tSp":[8]}' data-mw-variant='{"add":true,"oneway":[{"f":"COUNTRY","l":"zh","t":"China"},{"f":"COUNTRY","l":"zh-tw","t":"Taiwan"}]}'/> should be stripped!)</p>
<p>COUNTRY is Taiwan or China.</p>
!! end

## Note that parsoid test runner does not support 'showtitle' option.
!! test
Adding explicit conversion rule for title (T flag)
!! options
language=zh variant=zh-tw showtitle
!! wikitext
Should be stripped-{T|zh:China;zh-tw:Taiwan}-!

Taiwan is China.
!! html/php
Taiwan
<p>Should be stripped!
</p><p>Taiwan is China.
</p>
!! html/parsoid
<p>Should be stripped<meta typeof="mw:LanguageVariant" data-parsoid='{"tSp":[6]}' data-mw-variant='{"title":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/>!</p>
<p>Taiwan is China.</p>
!! end

!! test
Code coverage: T combined with H flag
!! options
language=zh variant=zh-tw showtitle
!! wikitext
Should be stripped-{T;H|zh:China; zh-tw:Taiwan}-!

Taiwan is China.
!! html/php
Taiwan
<p>Should be stripped!
</p><p>Taiwan is Taiwan.
</p>
!! html/parsoid
<p>Should be stripped<meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"title":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/>!</p>
<p>Taiwan is China.</p>
!! end

!! test
Code coverage: T with no variants
!! options
language=zh variant=zh-tw showtitle
!! wikitext
-{H|zh:China; zh-tw:Taiwan}-
Taiwan is China.-{T|Taiwan is China}-
!! html/php
Taiwan is China
<p>
Taiwan is Taiwan.
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/>
Taiwan is China.<meta typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"Taiwan is China"},"title":true}'/></p>
!! end

!! test
Code coverage: rules with no variants
!! options
language=zh variant=zh-tw
!! wikitext
-{H|zh:China; zh-tw:Taiwan}-
Taiwan is China.
-{H|China}-
Taiwan is China.
!! html/php
<p>
Taiwan is Taiwan.

Taiwan is China.
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/>
Taiwan is China.
<meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"*","t":"China"}]}'/>
Taiwan is China.</p>
!! end


!! test
Code coverage: D flag for conversion rule
!! options
language=zh variant=zh-tw
!! wikitext
-{D|zh-cn:XA; zh-tw:YA}-
-{A;D|zh-cn:XB; zh-tw:YB}-
-{D;H|zh-cn:XC; zh-tw:YC}-

-{D;H|FOO=>zh-tw:BAR;FOO=>zh-cn:BAT}-

-{D|0=>zh-tw:1}-
-{A;D|2=>zh-tw:3}-
-{D;H|4=>zh-tw:5}-

XA XB XC YA YB YC FOO BAR BAT 012345
!! html/php
<p>大陆：XA；台灣：YA；

大陆：XC；台灣：YC；
</p><p>FOO⇒台灣：BAR；FOO⇒大陆：BAT；
</p><p>0⇒台灣：1；

4⇒台灣：5；
</p><p>XA YB YC YA YB YC BAR BAR BAT 013355
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"describe":true,"twoway":[{"l":"zh-cn","t":"XA"},{"l":"zh-tw","t":"YA"}]}'></span>
<meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"describe":true,"twoway":[{"l":"zh-cn","t":"XB"},{"l":"zh-tw","t":"YB"}]}'/>
<span typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"describe":true,"twoway":[{"l":"zh-cn","t":"XC"},{"l":"zh-tw","t":"YC"}]}'></span></p>
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"describe":true,"oneway":[{"f":"FOO","l":"zh-tw","t":"BAR"},{"f":"FOO","l":"zh-cn","t":"BAT"}]}'></span></p>
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"describe":true,"oneway":[{"f":"0","l":"zh-tw","t":"1"}]}'></span>
<meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"describe":true,"oneway":[{"f":"2","l":"zh-tw","t":"3"}]}'/>
<span typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"describe":true,"oneway":[{"f":"4","l":"zh-tw","t":"5"}]}'></span></p>
<p>XA XB XC YA YB YC FOO BAR BAT 012345</p>
!! end

!! test
Code coverage: N flag for conversion rule
!! options
language=zh variant=zh-cn
!! wikitext
-{N|zh-cn}-

-{N|zh-tw}-

-{N|sr-ec}-
!! html/php
<p>大陆
</p><p>台灣
</p><p>српски (ћирилица)
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"name":{"t":"zh-cn"}}'></span></p>
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"name":{"t":"zh-tw"}}'></span></p>
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"name":{"t":"sr-ec"}}'></span></p>
!! end

# html2wt suppresses the bogus 'D' flag, so this is wt2html only
!! test
Code coverage: N flag for conversion rule (wt2html only)
!! options
language=zh variant=zh-cn
parsoid=wt2html,html2html
!! wikitext
-{D;N|en}-
!! html/php
<p>English
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"name":{"t":"en"}}' data-parsoid='{"fl":["D","N"]}'></span></p>
!! end

!! test
Testing that changing the language variant here in the tests actually works
!! options
language=zh variant=zh showtitle
!! wikitext
Should be stripped-{T|zh:China; zh-tw:Taiwan}-!
!! html/php
China
<p>Should be stripped!
</p>
!! html/parsoid
<p>Should be stripped<meta typeof="mw:LanguageVariant" data-mw-variant='{"title":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/>!</p>
!! end

!! test
Recursive conversion of alt and title attrs shouldn't clear converter state
!! options
language=zh variant=zh-cn
showtitle
!! wikitext
-{H|zh-cn:Exclamation; zh-tw:exclamation}-
Should be stripped-{T|zh-cn:China; zh-tw:Taiwan}-<span title="exclamation">!</span>
!! html/php
China
<p>
Should be stripped<span title="Exclamation">!</span>
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh-cn","t":"Exclamation"},{"l":"zh-tw","t":"exclamation"}]}'/>
Should be stripped<meta typeof="mw:LanguageVariant" data-mw-variant='{"title":true,"twoway":[{"l":"zh-cn","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/><span title="exclamation">!</span></p>
!! end

!! test
T26072: more test on conversion rule for title
!! options
language=zh variant=zh-tw showtitle
!! wikitext
This should be stripped-{T|zh:China; zh-tw:Taiwan}-!

This won't take interferes with the title rule-{H|zh:Beijing; zh-tw:Taipei}-.
!! html/php
Taiwan
<p>This should be stripped!
</p><p>This won't take interferes with the title rule.
</p>
!! html/parsoid
<p>This should be stripped<meta typeof="mw:LanguageVariant" data-mw-variant='{"title":true,"twoway":[{"l":"zh","t":"China"},{"l":"zh-tw","t":"Taiwan"}]}'/>!</p>
<p>This won't take interferes with the title rule<meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh","t":"Beijing"},{"l":"zh-tw","t":"Taipei"}]}'/>.</p>
!! end

!! test
Partly disable title conversion if variant == main language code
!! options
language=zh variant=zh title=[[ZH]] showtitle
!! wikitext
-{T|zh-cn:CN;zh-tw:TW}-
!! html/php
ZH
<p class="mw-empty-elt">
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-parsoid='{"tSp":[6]}' data-mw-variant='{"title":true,"twoway":[{"l":"zh-cn","t":"CN"},{"l":"zh-tw","t":"TW"}]}'/></p>
!! end

!! test
Partly disable title conversion if variant == main language code, more
!! options
language=zh variant=zh title=[[ZH]] showtitle
!! wikitext
-{T|TW}-
!! html/php
ZH
<p class="mw-empty-elt">
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"TW"},"title":true}'/></p>
!! end

!! test
Raw output of variant escape tags (R flag)
!! options
language=zh variant=zh-tw
!! wikitext
Raw: -{R|zh:China;zh-tw:Taiwan}-
!! html/php
<p>Raw: zh:China;zh-tw:Taiwan
</p>
!! html/parsoid
<p>Raw: <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"zh:China;zh-tw:Taiwan"}}'></span></p>
!! end

# html2wt suppresses the bogus 'D' flags, so this is wt2html only
!! test
Raw output of variant escape tags (R flag) (wt2html only)
!! options
language=zh variant=zh-tw
parsoid=wt2html,html2html
!! wikitext
-{Variant}- -{D|syntax}- -{D;R|options}-
!! html/php
<p>Variant syntax options
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"Variant"}}'></span> <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"syntax"}}'></span> <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"options"}}'></span></p>
!! end

!! test
Nested markup inside raw output of variant escape tags (R flag)
!! options
language=zh variant=zh-tw
!! wikitext
Nested raw: -{R|nested -{zh:China;zh-tw:Taiwan}- nested}-
!! html/php
<p>Nested raw: nested Taiwan nested
</p>
!! html/parsoid
<p>Nested raw: <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"nested &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&#39;{\"twoway\":[{\"l\":\"zh\",\"t\":\"China\"},{\"l\":\"zh-tw\",\"t\":\"Taiwan\"}]}&#39; data-parsoid=&#39;{\"fl\":[],\"tSp\":[6],\"dsr\":[23,48,null,2]}&#39;>&lt;/span> nested"}}'></span></p>
!! end

!! test
Nested markup and spaces inside raw output of variant escape tags (R flag)
!! options
language=zh variant=zh-tw
!! wikitext
X-{ outer -{ inner }- outer }-X
!! html/php
<p>X outer  inner  outer X
</p>
!! html/parsoid
<p>X<span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":" outer &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&#39;{\"disabled\":{\"t\":\" inner \"}}&#39; data-parsoid=&#39;{\"fl\":[],\"dsr\":[10,21,null,2]}&#39;>&lt;/span> outer "}}'></span>X</p>
!! end

!! test
Templates inside raw output of variant escape tags (R flag)
!! options
language=zh variant=zh-tw
!! wikitext
Nested raw: -{R|nested {{1x|hi}} templates}-
!! html/php
<p>Nested raw: nested hi templates
</p>
!! html/parsoid
<p>Nested raw: <span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"nested &lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"hi\"}},\"i\":0}}]}&#39;>hi&lt;/span> templates"}}'></span></p>
!! end

!! test
Strings evaluating false shouldn't be ignored by Language converter (T51072)
!! options
language=zh variant=zh-cn
!! wikitext
-{zh-cn:0;zh-sg:1;zh-tw:2;zh-hk:3}-
!! html/php
<p>0
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-parsoid='{"tSp":[12]}' data-mw-variant='{"twoway":[{"l":"zh-cn","t":"0"},{"l":"zh-sg","t":"1"},{"l":"zh-tw","t":"2"},{"l":"zh-hk","t":"3"}]}'></span></p>
!! end

!! test
Conversion rules from [numeric-only string] to [something else] (T48634)
!! options
language=zh variant=zh-cn
!! wikitext
-{H|0=>zh-cn:B}--{H|0=>zh-cn:C;0=>zh-cn:D}--{H|0=>zh-hans:A}-012345-{A|zh-tw:0;zh-cn:E;}-012345
!! html/php
<p>D12345EE12345
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"0","l":"zh-cn","t":"B"}]}'/><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"0","l":"zh-cn","t":"C"},{"f":"0","l":"zh-cn","t":"D"}]}'/><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"0","l":"zh-hans","t":"A"}]}'/>012345<span typeof="mw:LanguageVariant" data-parsoid='{"fl":["A"],"tSp":[7]}' data-mw-variant='{"add":true,"twoway":[{"l":"zh-tw","t":"0"},{"l":"zh-cn","t":"E"}]}'></span>012345</p>
!! end

!! test
Two-way converter rule entries with an empty value should be ignored (T53551)
!! options
language=zh variant=zh-cn
!! wikitext
-{H|zh-cn:foo;zh-tw:;}-foobar
!! html/php
<p>foobar
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-parsoid='{"tSp":[7]}' data-mw-variant='{"add":true,"twoway":[{"l":"zh-cn","t":"foo"},{"l":"zh-tw","t":""}]}'/>foobar</p>
!! end

!! test
One-way converter rule entries with an empty "from" string should be ignored (T53551)
!! options
language=zh variant=zh-cn
!! wikitext
-{H|=>zh-cn:foo;}-foobar
!! html/php
<p>foobar
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-parsoid='{"tSp":[5]}' data-mw-variant='{"add":true,"oneway":[{"f":"","l":"zh-cn","t":"foo"}]}'/>foobar</p>
!! end

!! test
Empty converter rule entries shouldn't be inserted into the conversion table (T53551)
!! options
language=zh variant=zh-cn
!! wikitext
-{H|}-foobar
!! html/php
<p>foobar
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"*","t":""}]}'/>foobar</p>
!! end

!! test
Nested using of manual convert syntax
!! options
language=zh variant=zh-hk
!! wikitext
Nested: -{zh-hans:Hi -{zh-cn:China;zh-sg:Singapore;}-;zh-hant:Hello -{zh-tw:Taiwan;zh-hk:H-{ong}- K-{}-ong;}-;}-!
!! html/php
<p>Nested: Hello Hong Kong!
</p>
!! html/parsoid
<p>Nested: <span typeof="mw:LanguageVariant" data-parsoid='{"tSp":[7]}' data-mw-variant='{"twoway":[{"l":"zh-hans","t":"Hi &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&apos;{\"twoway\":[{\"l\":\"zh-cn\",\"t\":\"China\"},{\"l\":\"zh-sg\",\"t\":\"Singapore\"}]}&apos; data-parsoid=&apos;{\"fl\":[],\"tSp\":[7],\"dsr\":[21,53,2,2]}&apos;>&lt;/span>"},{"l":"zh-hant","t":"Hello &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&apos;{\"twoway\":[{\"l\":\"zh-tw\",\"t\":\"Taiwan\"},{\"l\":\"zh-hk\",\"t\":\"H&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"ong\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[90,97,2,2]}&amp;apos;>&amp;lt;/span> K&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[99,103,2,2]}&amp;apos;>&amp;lt;/span>ong\"}]}&apos; data-parsoid=&apos;{\"fl\":[],\"tSp\":[7],\"dsr\":[68,109,2,2]}&apos;>&lt;/span>"}]}'></span>!</p>
!! end

!! test
HTML markups with conversion syntax in attribs, nested in other conversion blocks
!! options
language=zh variant=zh-cn
!! wikitext
-{zh;zh-hans;zh-hant|<span title="-{X}-">A</span>}-
!! html/php
<p><span title="X">A</span>
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["zh","zh-hans","zh-hant"],"t":"&lt;span title=\"\" about=\"#mwt1\" typeof=\"mw:ExpandedAttrs\" data-parsoid=&#39;{\"stx\":\"html\",\"a\":{\"title\":\"\"},\"sa\":{\"title\":\"-{X}-\"},\"dsr\":[21,49,20,7]}&#39; data-mw=&#39;{\"attribs\":[[{\"txt\":\"title\"},{\"html\":\"&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"X\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[34,39,2,2]}&amp;apos;>&amp;lt;/span>\"}]]}&#39;>A&lt;/span>"}}'></span></p>
!! end

!! test
HTML markups with conversion syntax in attribs, nested in other conversion blocks (not working yet in PHP parser)
!! options
language=zh variant=zh-cn
!! wikitext
-{<span title="-{X}-">A</span>}-
!! html/php+disabled
<p><span title="X">A</span>
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"&lt;span title=\"\" about=\"#mwt1\" typeof=\"mw:ExpandedAttrs\" data-parsoid=&#39;{\"stx\":\"html\",\"a\":{\"title\":\"\"},\"sa\":{\"title\":\"-{X}-\"},\"dsr\":[2,30,20,7]}&#39; data-mw=&#39;{\"attribs\":[[{\"txt\":\"title\"},{\"html\":\"&amp;lt;span typeof=\\\"mw:LanguageVariant\\\" data-mw-variant=&amp;apos;{\\\"disabled\\\":{\\\"t\\\":\\\"X\\\"}}&amp;apos; data-parsoid=&amp;apos;{\\\"fl\\\":[],\\\"dsr\\\":[15,20,2,2]}&amp;apos;>&amp;lt;/span>\"}]]}&#39;>A&lt;/span>"}}'></span></p>
!! end

# Parsoid and PHP disagree on how to parse this example: Parsoid
# insists that the content of a language converter element be a valid
# DOM fragment or attribute string
!! test
Language converter markup with block content
!! options
language=zh variant=zh-cn
!! wikitext
<span>a-{b<div>c}-d

<span>a-{zh;zh-hans;zh-hant|b<div>c}-d

<span>a-{H|0=>zh-cn:x<span>y;0=>zh-tw:b<div>c}-d
!! html/php+tidy
<span>ab<div>cd
<span>ab<div>cd
<span>ad</span></div></span></div></span>
!! html/parsoid
<span data-parsoid='{"stx":"html","autoInsertedEnd":true}'>a<div typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"b&lt;div data-parsoid=&apos;{\"stx\":\"html\",\"autoInsertedEnd\":true,\"dsr\":[10,16,5,0]}&apos;>c&lt;/div>"}}'></div>d

<span data-parsoid='{"stx":"html","autoInsertedEnd":true}'>a<div typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["zh","zh-hans","zh-hant"],"t":"b&lt;div data-parsoid=&apos;{\"stx\":\"html\",\"autoInsertedEnd\":true,\"dsr\":[50,56,5,0]}&apos;>c&lt;/div>"}}'></div>d

<p><span data-parsoid='{"stx":"html","autoInsertedEnd":true}'>a<meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"0","l":"zh-cn","t":"x&lt;span data-parsoid=&apos;{\"stx\":\"html\",\"autoInsertedEnd\":true,\"dsr\":[82,89,6,0]}&apos;>y&lt;/span>"},{"f":"0","l":"zh-tw","t":"b&lt;div data-parsoid=&apos;{\"stx\":\"html\",\"autoInsertedEnd\":true,\"dsr\":[100,106,5,0]}&apos;>c&lt;/div>"}]}'/>d</span></p></span></span>
!! end

!! test
LanguageConverter selser (1)
!! options
language=zh variant=zh-cn
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["span[typeof]", "attr", "data-mw-variant", "{\"disabled\":{\"t\":\"edited\"}}"]
  ]
}
!! wikitext
-{raw}-
!! wikitext/edited
-{edited}-
!! end

!! test
LanguageConverter selser (2)
!! options
language=zh variant=zh-cn
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["span[class='x']", "contents", "text", "-{foo}-"],
    ["a", "contents", "text", "-{"],
    ["span[typeof]", "attr", "data-mw", "{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"-{\"}},\"i\":0}}]}"]
  ]
}
!! wikitext
<span class="x">TEXT1</span>
[http://example.com TEXT2]
[[Foo|TEXT3]]
{{1x|TEXT4}}
!! wikitext/edited
<span class="x"><nowiki>-{foo}-</nowiki></span>
[http://example.com -{]
[[Foo|<nowiki>-{</nowiki>]]
{{1x|<nowiki>-{</nowiki>}}
!! end

# Tests LanguageVariantText in ConstrainedText
!! test
LanguageConverter selser (3)
!! options
language=zh variant=zh-cn
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["td > span", "attr", "typeof", "mw:LanguageVariant"],
    ["td > span", "attr", "data-mw-variant", "{\"disabled\":{\"t\":\"edited\"}}"]
  ]
}
!! wikitext
{|
|-
|<span>Foo</span>
|}
!! wikitext/edited
{|
|-
|<nowiki/>-{edited}-
|}
!! end

# Tests LanguageVariantText._fromSelSer
!! test
LanguageConverter selser (4)
!! options
language=zh variant=zh-cn
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["td > span.x", "remove"]
  ]
}
!! wikitext
{|
|-
|<span class="x">Foo</span>-{Bar}-
||<span class="x">Foo</span>-{Bar}-
|}
!! wikitext/edited
{|
|-
|<nowiki/>-{Bar}-
||-{Bar}-
|}
!! end

# Since Parsoid is starting to emit canonical wikitext for links,
# [http://example.com http://example.com] will not RT back to that
# form anymore.
# Parsoid does not language-convert links (it is done in a
# post-processing step)
!! test
Proper conversion of text in external links
!! options
language=sr variant=sr-ec
parsoid=wt2html
!! wikitext
http://www.google.com
gopher://www.google.com
[http://www.google.com http://www.google.com]
[gopher://www.google.com gopher://www.google.com]
[https://www.google.com irc://www.google.com]
[ftp://www.google.com www.google.com/ftp://dir]
[//www.google.com www.google.com]
!! html/php
<p><a rel="nofollow" class="external free" href="http://www.google.com">http://www.google.com</a>
<a rel="nofollow" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
<a rel="nofollow" class="external text" href="http://www.google.com">http://www.google.com</a>
<a rel="nofollow" class="external text" href="gopher://www.google.com">gopher://www.google.com</a>
<a rel="nofollow" class="external text" href="https://www.google.com">irc://www.google.com</a>
<a rel="nofollow" class="external text" href="ftp://www.google.com">www.гоогле.цом/фтп://дир</a>
<a rel="nofollow" class="external text" href="//www.google.com">www.гоогле.цом</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.google.com" class="external free">http://www.google.com</a>
<a rel="mw:ExtLink" href="gopher://www.google.com" class="external free">gopher://www.google.com</a>
<a rel="mw:ExtLink" href="http://www.google.com" class="external text">http://www.google.com</a>
<a rel="mw:ExtLink" href="gopher://www.google.com" class="external text">gopher://www.google.com</a>
<a rel="mw:ExtLink" href="https://www.google.com" class="external text">irc://www.google.com</a>
<a rel="mw:ExtLink" href="ftp://www.google.com" class="external text">www.google.com/ftp://dir</a>
<a rel="mw:ExtLink" href="//www.google.com" class="external text">www.google.com</a></p>
!! end

!! test
Do not convert roman numbers to language variants
!! options
language=sr variant=sr-ec
!! wikitext
Fridrih IV je car.
!! html/php
<p>Фридрих IV је цар.
</p>
!! html/parsoid
<p>Fridrih IV je car.</p>
!! end

!! test
Unclosed language converter markup "-{"
!! options
language=sr
!! wikitext
-{T|hello
!! html
<p>-{T|hello
</p>
!! end

!! test
Don't convert raw rule "-{R|=&gt;}-" to "=>"
!! options
language=sr
!! wikitext
-{R|=&gt;}-
!! html/php
<p>=&gt;
</p>
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"=&lt;span typeof=\"mw:Entity\" data-parsoid=&#39;{\"src\":\"&amp;amp;gt;\",\"srcContent\":\">\",\"dsr\":[5,9,null,null]}&#39;>>&lt;/span>"}}'></span></p>
!!end

!! test
Don't break link parsing if language converter markup is in the caption.
!! options
language=sr variant=sr-ec
!! wikitext
[[Main Page|-{R|main page}-]]
!! html/php
<p><a href="/wiki/Main_Page" title="Маин Паге">main page</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page"><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"main page"}}' data-parsoid='{"fl":["R"]}'></span></a></p>
!! end

!! test
T146304: Don't break template parsing if language converter markup is in the parameter.
!! options
language=sr variant=sr-ec
!! wikitext
{{1x|-{R|foo}-}}
!! html/php
<p>foo
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"foo"}}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Шаблон:1x"},"params":{"1":{"wt":"-{R|foo}-"}},"i":0}}]}'></span></p>
!! end

!! test
T153135: Don't break list handling if language converter markup is in the item.
!! options
language=zh variant=zh-cn
!! wikitext
;-{zh-cn:AAA;zh-tw:BBB}-
;-{R|foo:bar}-
!! html/php
<dl><dt>AAA</dt>
<dt>foo:bar</dt></dl>
!! html/parsoid
<dl><dt data-parsoid='{}'><span typeof="mw:LanguageVariant" data-parsoid='{"tSp":[6]}' data-mw-variant='{"twoway":[{"l":"zh-cn","t":"AAA"},{"l":"zh-tw","t":"BBB"}]}'></span></dt>
<dt data-parsoid='{}'><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"foo:bar"}}'></span></dt>
</dl>
!! end

# Note that parsoid does not protect colons unless language converter
# markup is properly nested, because it is a backtracking parser.
!! test
T153135: Unclosed markup in definition list (code coverage)
!! options
language=zh variant=zh-cn
!! wikitext
;<b>foo:bar
;-{zh-cn:AAA
!! html/php+tidy
<dl><dt><b>foo:bar</b></dt><b>
<dt>-{zh-cn:AAA</dt></b></dl>
!! html/parsoid
<dl><dt data-parsoid='{}'><b data-parsoid='{"stx":"html","autoInsertedEnd":true}'>foo:bar</b></dt><b data-parsoid='{"stx":"html","autoInsertedEnd":true,"autoInsertedStart":true}'>
<dt data-parsoid='{}'>-{zh-cn</dt><dd data-parsoid='{"stx":"row"}'>AAA</dd></b></dl>
!! end

!! test
T153135: Nested language converter markup in definition list (code coverage)
!! options
language=zh variant=zh-cn
!! wikitext
;-{|zh-cn:AAA -{zh-hans|foo:bar}- -{R|bat:baz}-}-:def
!! html/php
<dl><dt>AAA foo:bar bat:baz</dt>
<dd>def</dd></dl>
!! html/parsoid
<dl><dt data-parsoid='{}'><span typeof="mw:LanguageVariant" data-mw-variant='{"twoway":[{"l":"zh-cn","t":"AAA &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&#39;{\"filter\":{\"l\":[\"zh-hans\"],\"t\":\"foo:bar\"}}&#39; data-parsoid=&#39;{\"fl\":[\"zh-hans\"],\"dsr\":[14,33,null,2]}&#39;>&lt;/span> &lt;span typeof=\"mw:LanguageVariant\" data-mw-variant=&#39;{\"disabled\":{\"t\":\"bat:baz\"}}&#39; data-parsoid=&#39;{\"fl\":[\"R\"],\"dsr\":[34,47,null,2]}&#39;>&lt;/span>"}]}'></span></dt>
<dd data-parsoid='{"stx":"row"}'>def</dd>
</dl>
!! end

# html2wt mode disabled due to <nowiki> insertion.
!! test
T153140: Don't break table handling if language converter markup is in the cell.
!! options
language=sr variant=sr-ec
parsoid=wt2html,wt2wt,html2html
!! wikitext
{|
|-
| -{R|B}-
|}
!! html/php
<table>

<tbody><tr>
<td>B
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody>
<tr>
<td><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"B"}}'></span></td>
</tr>
</tbody>
</table>
!! end

!! test
Language converter tricky html2wt cases (1)
!! options
language=sr
parsoid=html2wt,wt2wt
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"}-"}}'></span></p>
!! wikitext
-{<nowiki>}-</nowiki>}-
!! html/php
<p>&#125;-
</p>
!! end

!! test
Language converter tricky html2wt cases (2)
!! options
language=sr
parsoid=html2wt,wt2wt
!! html/parsoid
<p>-{foo}-</p>
!! wikitext
<nowiki>-{foo}-</nowiki>
!! html/php
<p>-&#123;foo&#125;-
</p>
!! end

!! test
Language converter tricky html2wt cases (3)
!! options
language=sr
parsoid=html2wt,wt2wt
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"|"}}'></span></p>
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"R|raw"}}'></span></p>
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"-{foo}-"}}'></span></p>
!! wikitext
-{R||}-

-{R|R|raw}-

-{<nowiki>-{foo}-</nowiki>}-
!! html/php
<p>|
</p><p>R|raw
</p><p>-&#123;foo&#125;-
</p>
!! end

!! test
Language converter tricky html2wt cases (4)
!! options
language=sr
parsoid=html2wt,wt2wt
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"hey\"}},\"i\":0}}]}&#39;>hey&lt;/span>"}}'></span></p>
!! wikitext
-{R|{{1x|hey}}}-
!! html/php
<p>hey
</p>
!! end

# Note that the <nowiki> escaping added by parsoid for source text,
# destination text, and language names only works on the PHP side
# for *destination text*.  (HTML entity escaping wouldn't work
# any better.)  This is probably a bug, at least for source texts.
# (For language names PHP uses a precise regexp based on the languages
# it currently knows have variants, which is fragile since this set
# can grow/shrink over time.)
!! test
Language converter tricky html2wt cases (5)
!! options
language=zh variant=zh-cn
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"a:b=>c","l":"zh-cn","t":"x;foo=>zh-cn:boo"},{"f":"bar","l":"zh-cn","t":"bat;xyz=>zh-cn:abc"}]}'/>foobar</p>
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"A","l":"bo:g;us","t":"B"}]}'/></p>
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh-tw","t":"xyz"},{"l":"zh-cn","t":"0;zh-tw:bar"}]}'></span></p>
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"twoway":[{"l":"bo:g;us","t":"xyz"},{"l":"zh-cn","t":"abc"}]}'></span></p>
<p>a:b=>c xyz</p>
!! wikitext
-{H|<nowiki>a:b=>c</nowiki>=>zh-cn:<nowiki>x;foo=>zh-cn:boo</nowiki>;bar=>zh-cn:<nowiki>bat;xyz=>zh-cn:abc</nowiki>}-foobar

-{H|A=><nowiki>bo:g;us</nowiki>:B}-

-{A|zh-tw:xyz; zh-cn:<nowiki>0;zh-tw:bar</nowiki>}-

-{<nowiki>bo:g;us</nowiki>:xyz; zh-cn:abc}-

a:b=>c xyz
!! html/php+disabled
<p>foobat;xyz=&gt;zh-cn:abc
</p><p>A
</p><p>0;zh-tw:bar
</p><p>abc
</p><p>a:b=&gt;c 0;zh-tw:bar
</p>
!! end

!! test
T239806: Trailing garbage in language converter rules (1)
!! options
language=zh variant=zh-hans
parsoid=wt2html,html2html
!! wikitext
-{H|zh-cn:约翰·塞纳; zh-hk:莊·先拿; zh-tw:約翰·希南; ;}-
-{H|zh-cn:泰瑞斯·吉布森; zh-hk:泰列斯·吉遜; zh-tw:泰瑞斯·吉布森; ;}-
-{H|zh-cn:金·米尔福特; zh-tw:金·米爾福特; 真·米爾福特;}-
!! html/php+tidy
<p class="mw-empty-elt">


</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh-cn","t":"约翰·塞纳"},{"l":"zh-hk","t":"莊·先拿"},{"l":"zh-tw","t":"約翰·希南"}]}'/>
<meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh-cn","t":"泰瑞斯·吉布森"},{"l":"zh-hk","t":"泰列斯·吉遜"},{"l":"zh-tw","t":"泰瑞斯·吉布森"}]}'/>
<meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh-cn","t":"金·米尔福特"},{"l":"zh-tw","t":"金·米爾福特"}]}'/></p>
!! end

!! test
T239806: Trailing garbage in language converter rules (2)
!! options
language=zh variant=zh-hans
parsoid=wt2html,html2html
!! wikitext
-{H|zh-cn:玛格特·罗比; zh-tw:瑪格·羅比; zh-hk:瑪歌·羅比; zh-sg:玛格·罗比; ;}-
!! html/php+tidy
<p class="mw-empty-elt">
</p>
!! html/parsoid
<p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"zh-cn","t":"玛格特·罗比"},{"l":"zh-tw","t":"瑪格·羅比"},{"l":"zh-hk","t":"瑪歌·羅比"},{"l":"zh-sg","t":"玛格·罗比"}]}'/></p>
!! end

!! test
T179579: Nowiki and lc interaction
!! options
parsoid=wt2html
language=sr
!! wikitext
-{</nowiki>123}-

-{123<nowiki>|</nowiki>456}-
!! html/parsoid
<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"&amp;lt;/nowiki>123"}}' data-parsoid='{"fl":[],"src":"-{&lt;/nowiki>123}-"}'></span></p>

<p><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"123&lt;span typeof=\"mw:Nowiki\" data-parsoid=&#39;{\"dsr\":[23,41,8,9]}&#39;>|&lt;/span>456"}}' data-parsoid='{"fl":[],"src":"-{123&lt;nowiki>|&lt;/nowiki>456}-"}'></span></p>
!! end

!! test
Balinese language conversion
!! options
language=ban variant=ban-x-palmleaf
!! wikitext
ᬫᬦ᭄ᬢ᭄ᬭ -{ban-x-palmleaf:AAA;ban:BBB}-
!! html/php
<p>mantra AAA
</p>
!! end

!! test
T2529: Uncovered bullet
!! wikitext
*Foo {{bullet}}
!! html
<ul><li>Foo</li>
<li>Bar</li></ul>
!! end

!! test
T2529: Uncovered bullet in a deeply nested list
!! wikitext
*******Foo {{bullet}}
!! html
<ul><li><ul><li><ul><li><ul><li><ul><li><ul><li><ul><li>Foo</li></ul></li></ul></li></ul></li></ul></li></ul></li></ul></li>
<li>Bar</li></ul>
!! end

!! test
T2529: Uncovered table already at line-start
!! wikitext
x

{{table}}
y
!! html
<p>x
</p>
<table>
<tbody><tr>
<td>1</td>
<td>2
</td></tr>
<tr>
<td>3</td>
<td>4
</td></tr></tbody></table>
<p>y
</p>
!! end

!! test
T2529: Uncovered bullet in parser function result
!! wikitext
*Foo {{lc:{{bullet}} }}
!! html
<ul><li>Foo</li>
<li>bar</li></ul>
!! end

!! test
T7678: Double-parsed template argument
!! wikitext
{{lc:{{{1}}}|hello}}
!! html
<p>{{{1}}}
</p>
!! end

!! test
T7678: Double-parsed template invocation
!! wikitext
{{lc:{{paramtest {{!}} param = hello }} }}
!! html
<p>{{paramtest | param = hello }}
</p>
!! end

!! test
Case insensitivity of parser functions for non-ASCII characters (T10143)
!! options
language=cs
title=[[Main Page]]
!! wikitext
{{PRVNÍVELKÉ:ěščř}}
{{prvnívelké:ěščř}}
{{PRVNÍMALÉ:ěščř}}
{{prvnímalé:ěščř}}
{{MALÁ:ěščř}}
{{malá:ěščř}}
{{VELKÁ:ěščř}}
{{velká:ěščř}}
!! html
<p>Ěščř
Ěščř
ěščř
ěščř
ěščř
ěščř
ĚŠČŘ
ĚŠČŘ
</p>
!! end

!! test
Morwen/13: Unclosed link followed by heading
!! wikitext
[[link
==heading==
!! html
<p>[[link
</p>
<h2><span class="mw-headline" id="heading">heading</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: heading">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
HHP2.1: Heuristics for headings in preprocessor parenthetical structures
!! wikitext
{{foo|
=heading=
!! html
<p>{{foo|
</p>
<h1><span class="mw-headline" id="heading">heading</span></h1>
!! end

!! test
HHP2.2: Heuristics for headings in preprocessor parenthetical structures
!! wikitext
{{foo|
==heading==
!! html
<p>{{foo|
</p>
<h2><span class="mw-headline" id="heading">heading</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: heading">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
Tildes in comments
!! options
pst
!! wikitext
<!-- ~~~~ -->
!! html/php
<!-- ~~~~ -->
!! end

!! test
Paragraphs inside divs (no extra line breaks)
!! wikitext
<div>Line one

Line two</div>
!! html
<div>Line one
Line two</div>
!! end

!! test
Paragraphs inside divs (extra line break on open)
!! wikitext
<div>
Line one

Line two</div>
!! html
<div>
<p>Line one
</p>
Line two</div>
!! end

!! test
Paragraphs inside divs (extra line break on close)
!! wikitext
<div>Line one

Line two
</div>
!! html
<div>Line one
<p>Line two
</p>
</div>
!! end

!! test
Paragraphs inside divs (extra line break on open and close)
!! wikitext
<div>
Line one

Line two
</div>
!! html
<div>
<p>Line one
</p><p>Line two
</p>
</div>
!! end

# doBlockLevels screws up this output and Remex cleans up as much as it can.
!! test
Nesting tags, paragraphs on lines which begin with <div>
!! wikitext
<div></div><strong>A
B</strong>
!! html/php+tidy
<div></div><p><strong>A
</strong></p><strong></strong><p><strong>B</strong>
</p>
!! html/parsoid
<div data-parsoid='{"stx":"html"}'></div><p><strong data-parsoid='{"stx":"html","autoInsertedEnd":true}'>A</strong></p>
<p><strong data-parsoid='{"stx":"html","autoInsertedStart":true}'>B</strong></p>
!! end

# T8200: <blockquote> should behave like <div> with respect to line breaks
!! test
T8200: paragraphs inside blockquotes (no extra line breaks)
!! wikitext
<blockquote>Line one

Line two</blockquote>
!! html+untidy
<blockquote>Line one
Line two</blockquote>
!! html+tidy
<blockquote><p>Line one
Line two</p></blockquote>
!! end

!! test
T8200: paragraphs inside blockquotes (extra line break on open)
!! wikitext
<blockquote>
Line one

Line two</blockquote>
!! html+untidy
<blockquote>
<p>Line one
</p>
Line two</blockquote>
!! html+tidy
<blockquote>
<p>Line one
</p><p>
Line two</p></blockquote>
!! end

!! test
T8200: paragraphs inside blockquotes (extra line break on close)
!! wikitext
<blockquote>Line one

Line two
</blockquote>
!! html+untidy
<blockquote>Line one
<p>Line two
</p>
</blockquote>
!! html+tidy
<blockquote><p>Line one
</p><p>Line two
</p>
</blockquote>
!! end

!! test
T8200: paragraphs inside blockquotes (extra line break on open and close)
!! wikitext
<blockquote>
Line one

Line two
</blockquote>
!! html
<blockquote>
<p>Line one
</p><p>Line two
</p>
</blockquote>
!! end

## This is a corner case interaction between the paragraph wrapping in the
## php parser's BlockLevelPass and Remex.  `doBlockLevels` has a notion of
## some tags which close paragraphs (and thus prevent wrapping on their line),
## of which "div" is one, but do p-wrapping inside them.  These are referred
## to as "never suppressing".  Remex, for its part, doesn't traverse into
## "div"s to p-wrap.  Hence, we only get this partial wrapping.
!! test
Paragraphs inside blockquotes/divs (no extra line breaks)
!! wikitext
<blockquote><div>Line one

Line two</div></blockquote>
!! html
<blockquote><div>Line one
Line two</div></blockquote>
!! end

!! test
Paragraphs inside blockquotes/divs (extra line break on open)
!! wikitext
<blockquote><div>
Line one

Line two</div></blockquote>
!! html
<blockquote><div>
<p>Line one
</p>
Line two</div></blockquote>
!! end

!! test
Paragraphs inside blockquotes/divs (extra line break on close)
!! wikitext
<blockquote><div>Line one

Line two
</div></blockquote>
!! html
<blockquote><div>Line one
<p>Line two
</p>
</div></blockquote>
!! end

!! test
Paragraphs inside blockquotes/divs (extra line break on open and close)
!! wikitext
<blockquote><div>
Line one

Line two
</div></blockquote>
!! html
<blockquote><div>
<p>Line one
</p><p>Line two
</p>
</div></blockquote>
!! end

!! test
Interwiki links trounced by handleExternalLinks after early LinkHolderArray expansion
!! options
wgLinkHolderBatchSize=0
!! wikitext
[[meatball:1]]
[[meatball:2]]
[[meatball:3]]
!! html
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?1" class="extiw" title="meatball:1">meatball:1</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?2" class="extiw" title="meatball:2">meatball:2</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?3" class="extiw" title="meatball:3">meatball:3</a>
</p>
!! end

!! test
T17196: localised external link numbers
!! options
language=fa
!! wikitext
[http://en.wikipedia.org/]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://en.wikipedia.org/">[۱]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://en.wikipedia.org/" class="external autonumber"></a></p>
!! end

!! test
Multibyte character in padleft
!! wikitext
{{padleft:-Hello|7|Æ}}
!! html/php
<p>Æ-Hello
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padleft:-Hello","function":"padleft"},"params":{"1":{"wt":"7"},"2":{"wt":"Æ"}},"i":0}}]}'>Æ-Hello</span></p>
!! end

!! test
Multibyte character in padright
!! wikitext
{{padright:Hello-|7|Æ}}
!! html/php
<p>Hello-Æ
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:Hello-","function":"padright"},"params":{"1":{"wt":"7"},"2":{"wt":"Æ"}},"i":0}}]}'>Hello-Æ</span></p>
!! end

!!test
formatdate parser function
!! wikitext
{{#formatdate:2009-03-24}}
!! html
<p><span class="mw-formatted-date" title="2009-03-24">2009-03-24</span>
</p>
!! end

!!test
formatdate parser function, with default format
!! wikitext
{{#formatdate:2009-03-24|mdy}}
!! html
<p><span class="mw-formatted-date" title="2009-03-24">March 24, 2009</span>
</p>
!! end

!! test
Spacing of numbers in formatted dates
!! wikitext
{{#formatdate:January 15}}
!! html
<p><span class="mw-formatted-date" title="01-15">January 15</span>
</p>
!! end

!! test
formatdate parser function, with default format and on a page of which the content language is always English and different from the wiki content language
!! options
language=nl title=[[MediaWiki:Common.css]]
!! wikitext
{{#formatdate:2009-03-24|dmy}}
!! html
<p><span class="mw-formatted-date" title="2009-03-24">24 March 2009</span>
</p>
!! end

!! test
formatdate with invalid month
!! wikitext
{{#formatdate:2019-22-22|dmy}}
!! html
<p>2019-22-22
</p>
!! end

!! test
formatdate: dots in month name do not match any char (T220563)
!! options
language=de
!! wikitext
{{#formatdate:jun. 3|dmy}}
{{#formatdate:junx 3|dmy}}
!! html
<p><span class="mw-formatted-date" title="06-03">3 Juni</span>
junx 3
</p>
!! end

!! test
formatdate uses correct capitalisation in French
!! options
language=fr
!! wikitext
{{#formatdate:Juin 3|dmy}}
!! html
<p><span class="mw-formatted-date" title="06-03">3 juin</span>
</p>
!! end

!! test
formatdate uses correct capitalisation in English
!! wikitext
{{#formatdate:june 3|dmy}}
!! html
<p><span class="mw-formatted-date" title="06-03">3 June</span>
</p>
!! end


#
#
#

#
# Edit comments
#

!! test
Edit comment with link
!! options
comment
!! wikitext
I like the [[Main Page]] a lot
!! html/php
I like the <a href="/wiki/Main_Page" title="Main Page">Main Page</a> a lot
!!end

!! test
Edit comment with link and link text
!! options
comment
!! wikitext
I like the [[Main Page|best pages]] a lot
!! html/php
I like the <a href="/wiki/Main_Page" title="Main Page">best pages</a> a lot
!!end

!! test
Edit comment with link and link text with suffix
!! options
comment
!! wikitext
I like the [[Main Page|best page]]s a lot
!! html/php
I like the <a href="/wiki/Main_Page" title="Main Page">best pages</a> a lot
!!end

!! test
Edit comment with section link (non-local, eg in history list)
!! options
comment title=[[Main Page]]
!! wikitext
/* External links */ removed bogus entries
!! html/php
<span dir="auto"><span class="autocomment"><a href="/wiki/Main_Page#External_links" title="Main Page">→‎External links</a>: </span> removed bogus entries</span>
!!end

!! test
Edit comment with section link and text before it (non-local, eg in history list)
!! options
comment title=[[Main Page]]
!! wikitext
pre-comment text /* External links */ removed bogus entries
!! html/php
pre-comment text <span dir="auto"><span class="autocomment"><a href="/wiki/Main_Page#External_links" title="Main Page">→‎External links</a>: </span> removed bogus entries</span>
!!end

!! test
Edit comment with section link (local, eg in diff view)
!! options
comment local title=[[Main Page]]
!! wikitext
/* External links */ removed bogus entries
!! html/php
<span dir="auto"><span class="autocomment"><a href="#External_links">→‎External links</a>: </span> removed bogus entries</span>
!!end

!! test
Edit comment with section link that has a link in it
!! options
comment local title=[[Main Page]]
!! wikitext
/* [[A link]] */
!! html/php
<span dir="auto"><span class="autocomment"><a href="#A_link">→‎&#91;[A link]]</a></span></span>
!! end

!! test
Edit comment with section link that has a template in it
!! options
comment local title=[[Main Page]]
!! wikitext
/* {{foobar|param}} */
!! html/php
<span dir="auto"><span class="autocomment"><a href="#.7B.7Bfoobar.7Cparam.7D.7D">→‎{{foobar|param}}</a></span></span>
!! end

!! test
Edit comment with subpage link (T16080)
!! options
comment
subpage
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage]] here...
!! html/php
Poked at a <a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">/subpage</a> here...
!!end

!! test
Edit comment with subpage link and link text (T16080)
!! options
comment
subpage
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage|neat little page]] here...
!! html/php
Poked at a <a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">neat little page</a> here...
!!end

!! test
Edit comment with bogus subpage link in non-subpage NS (T16080)
!! options
comment
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage]] here...
!! html/php
Poked at a <a href="/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> here...
!!end

!! test
Edit comment with bare anchor link (local, as on diff)
!! options
comment
local
title=[[Main Page]]
!! wikitext
[[#section]]
!! html/php
<a href="#section">#section</a>
!! end

!! test
Edit comment with bare anchor link (non-local, as on history)
!! options
comment
title=[[Main Page]]
!! wikitext
[[#section]]
!! html/php
<a href="/wiki/Main_Page#section" title="Main Page">#section</a>
!! end

!! test
Anchor starting with underscore
!! options
title=[[Foo]]
!! wikitext
[[#_ref|One]]
!! html/php
<p><a href="#_ref">One</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo#_ref" data-parsoid='{"stx":"piped","a":{"href":"./Foo#_ref"},"sa":{"href":"#_ref"}}'>One</a></p>
!! end

!! test
Id starting with underscore
!! wikitext
<div id="_ref"></div>
!! html/*
<div id="_ref"></div>
!! end

!! test
Edit comment with link with more than one pipe (T99346)
!! options
comment
!! wikitext
[[Main Page|Many|pipes]]
!! html/php
<a href="/wiki/Main_Page" title="Main Page">Many|pipes</a>
!! end

!! test
Complex edit comment with link with more than one pipe (T99346)
!! options
comment
!! wikitext
Created page with "<noinclude>[[Category:Requests for permissions/Bot|{{subst:#titleparts:{{subst:PAGENAME}}|1|3}}]]</noinclude> === [[User:MineoBot|]] 8=== {{Request for permissions/links|Mineo..."
!! html/php
Created page with &quot;&lt;noinclude&gt;<a href="/index.php?title=Category:Requests_for_permissions/Bot&amp;action=edit&amp;redlink=1" class="new" title="Category:Requests for permissions/Bot (page does not exist)">{{subst:#titleparts:{{subst:PAGENAME}}|1|3}}</a>&lt;/noinclude&gt; === <a href="/index.php?title=User:MineoBot&amp;action=edit&amp;redlink=1" class="new" title="User:MineoBot (page does not exist)">User:MineoBot</a> 8=== {{Request for permissions/links|Mineo...&quot;
!! end

!! test
Space normalisation on autocomment (T24784)
!! options
comment
title=[[Main Page]]
!! wikitext
/* __hello__world__ */
!! html/php
<span dir="auto"><span class="autocomment"><a href="/wiki/Main_Page#hello_world" title="Main Page">→‎__hello__world__</a></span></span>
!! end

!! test
percent-encoding and + signs in comments (T28410)
!! options
comment
!! wikitext
[[ABC%33D% ++]] [[ABC%33D% ++|+%20]]
!! html/php
<a href="/index.php?title=ABC3D%25_%2B%2B&amp;action=edit&amp;redlink=1" class="new" title="ABC3D% ++ (page does not exist)">ABC3D% ++</a> <a href="/index.php?title=ABC3D%25_%2B%2B&amp;action=edit&amp;redlink=1" class="new" title="ABC3D% ++ (page does not exist)">+%20</a>
!! end

# Parsoid doesn't support this yet: see T75581
# but it *should* omit the 'src' attribute if the image is bad.
# PHP side of tests was disabled in
# mediawiki/core:6bd31e7d95161a6e88fa86df60871051da997c3c
# because of issues in the PHP parserTests infrastructure
# (but the output below is indeed what the PHP side emits)
!! test
Bad images - basic functionality
!! wikitext
[[File:Bad.jpg]]
!! html/php+disabled
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Bad.jpg"><span resource="./File:Bad.jpg">File:Bad.jpg</span></a></span></p>
!! end

!! test
Bad images - T18039: text after bad image disappears
!! wikitext
Foo bar
[[File:Bad.jpg]]
Bar foo
!! html/php+disabled
<p>Foo bar
</p><p>Bar foo
</p>
!! html/parsoid
<p>Foo bar
<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Bad.jpg"><span resource="./File:Bad.jpg">File:Bad.jpg</span></a></span>
Bar foo</p>
!! end

!! test
Verify that displaytitle works (T24501) no displaytitle
!! options
showtitle
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! wikitext
this is not the title
!! html/php
Parser test
<p>this is not the title
</p>
!! end

!! test
Verify that displaytitle works (T24501) RestrictDisplayTitle=false
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! wikitext
this is not the title
{{DISPLAYTITLE:whatever}}
!! html/php
whatever
<p>this is not the title
</p>
!! end

!! test
Verify that displaytitle works (T24501) RestrictDisplayTitle=true mismatch
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:whatever}}
!! html/php
Screen
<p>this is not the title
</p>
!! end

!! test
Verify that displaytitle works (T24501) RestrictDisplayTitle=true matching
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:screen}}
!! html/php
screen
<p>this is not the title
</p>
!! end

!! test
Verify that displaytitle works (T24501) AllowDisplayTitle=false
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=false
!! wikitext
this is not the title
{{DISPLAYTITLE:screen}}
!! html/php
Screen
<p>this is not the title
<a href="/index.php?title=Template:DISPLAYTITLE:screen&amp;action=edit&amp;redlink=1" class="new" title="Template:DISPLAYTITLE:screen (page does not exist)">Template:DISPLAYTITLE:screen</a>
</p>
!! end

!! test
Verify that displaytitle works (T24501) AllowDisplayTitle=false no DISPLAYTITLE
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=false
!! wikitext
this is not the title
!! html/php
Screen
<p>this is not the title
</p>
!! end

!! test
Verify that displaytitle handles inline CSS styles (T28547) - rejected value
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:<span style="display: none;">s</span>creen}}
!! html/php
<span style="/* attempt to bypass $wgRestrictDisplayTitle */">s</span>creen
<p>this is not the title
</p>
!! end

!! test
Verify that displaytitle handles inline CSS styles (T28547) - accepted value
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:<span style="color: red;">s</span>creen}}
!! html/php
<span style="color: red;">s</span>creen
<p>this is not the title
</p>
!! end

!! test
Page status indicators: Empty name is invalid
!! options
showindicators
!! wikitext
<indicator name=" "></indicator>
<indicator></indicator>
!! html/php
<p><span class="error"><strong>Error:</strong> Page status indicators' <code>name</code> attribute must not be empty.</span>
<span class="error"><strong>Error:</strong> Page status indicators' <code>name</code> attribute must not be empty.</span>
</p>
!! end

!! test
Page status indicators: Weird syntaxes that are okay
!! options
showindicators
!! wikitext
<indicator name="empty" />
<indicator name="name"></indicator>
!! html/php
empty=
name=
<p><br />
</p>
!! end

!! test
Page status indicators: Torture test
!! options
showindicators
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
<indicator name="01">hello world</indicator>
<indicator name="02">[[Main Page]]</indicator>
<indicator name="03">[[File:Foobar.jpg|25px|link=]]</indicator>
<indicator name="04">[[File:Foobar.jpg|25px]]</indicator>
<indicator name="05">*foo
*bar</indicator>
<indicator name="06"><nowiki>foo</nowiki></indicator>
<indicator name="07"> Preformatted</indicator>
<indicator name="08"><div>Broken tag</indicator>
<indicator name="09">{| class=wikitable
|cell
|}</indicator>
<indicator name="10">Two

paragraphs</indicator>
!! html/php
01=hello world
02=<a href="/wiki/Main_Page" title="Main Page">Main Page</a>
03=<span typeof="mw:Image"><span><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/25px-Foobar.jpg" decoding="async" width="25" height="3" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/38px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg 2x" /></span></span>
04=<span typeof="mw:Image"><a href="/wiki/File:Foobar.jpg"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/25px-Foobar.jpg" decoding="async" width="25" height="3" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/38px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg 2x" /></a></span>
05=<ul><li>foo</li>
<li>bar</li></ul>
06=foo
07=<pre>Preformatted
</pre>
08=<div>Broken tag</div>
09=<table class="wikitable">
<tbody><tr>
<td>cell
</td></tr></tbody></table>
10=<p>Two
</p><p>paragraphs
</p>
<p><br />
</p><p><br />
</p><p><br />
</p><p><br />
</p><p><br />
</p>
!! end

!! test
preload: check <noinclude> and <includeonly>
!! options
preload
!! wikitext
Hello <noinclude>cruel</noinclude><includeonly>kind</includeonly> world.
!! html/php
Hello kind world.
!! end

!! test
preload: check <onlyinclude>
!! options
preload
!! wikitext
Goodbye <onlyinclude>Hello world</onlyinclude>
!! html/php
Hello world
!! end

!! test
preload: can pass tags through if we want to
!! options
preload
!! wikitext
<includeonly><</includeonly>includeonly>Hello world<includeonly><</includeonly>/includeonly>
!! html/php
<includeonly>Hello world</includeonly>
!! end

!! test
preload: check that it doesn't try to do tricks
!! options
preload
!! wikitext
* <!-- Hello --> ''{{world}}'' {{<includeonly>subst:</includeonly>How are you}}{{ {{{|safesubst:}}} #if:1|2|3}}
!! html/php
* <!-- Hello --> ''{{world}}'' {{subst:How are you}}{{ {{{|safesubst:}}} #if:1|2|3}}
!! end

!! test
Play a bit with r67090 and T5158
!! wikitext
<div style="width:50% !important">&nbsp;</div>
<div style="width:50%&nbsp;!important">&nbsp;</div>
<div style="width:50%&#160;!important">&nbsp;</div>
<div style="border : solid;">&nbsp;</div>
!! html/php
<div style="width:50% !important">&#160;</div>
<div style="width:50%&#160;!important">&#160;</div>
<div style="width:50%&#160;!important">&#160;</div>
<div style="border : solid;">&#160;</div>
!! html/parsoid
<div style="width:50% !important" data-parsoid='{"stx":"html"}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
<div style="width:50% !important" data-parsoid='{"stx":"html","a":{"style":"width:50% !important"},"sa":{"style":"width:50%&amp;nbsp;!important"}}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
<div style="width:50% !important" data-parsoid='{"stx":"html","a":{"style":"width:50% !important"},"sa":{"style":"width:50%&amp;#160;!important"}}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
<div style="border : solid;" data-parsoid='{"stx":"html"}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
!! end

!! test
French spaces in wikitext
!! wikitext
foo ! bar ? bat 50 % is less than 75 %.

Hello : this ; is « something ‹ else › again »
!! html/php
<p>foo&#160;! bar&#160;? bat 50&#160;% is less than 75&#160;%.
</p><p>Hello&#160;: this&#160;; is «&#160;something ‹&#160;else&#160;› again&#160;»
</p>
!! html/parsoid
<p>foo<span typeof="mw:DisplaySpace"> </span>! bar<span typeof="mw:DisplaySpace"> </span>? bat 50<span typeof="mw:DisplaySpace"> </span>% is less than 75<span typeof="mw:DisplaySpace"> </span>%.</p>

<p>Hello<span typeof="mw:DisplaySpace"> </span>: this<span typeof="mw:DisplaySpace"> </span>; is «<span typeof="mw:DisplaySpace"> </span>something ‹<span typeof="mw:DisplaySpace"> </span>else<span typeof="mw:DisplaySpace"> </span>› again<span typeof="mw:DisplaySpace"> </span>»</p>
!! end

!! test
Corner case: french spaces in definition list
!! options
parsoid=wt2html,html2html
!! wikitext
;foo : bar
!! html+tidy
<dl><dt>foo</dt>
<dd>bar</dd></dl>
!! end

!! test
T5158: Test for French spaces in attributes
!! wikitext
<br style=" clear : both ; " />
!! html/php
<p><br style="clear : both ;" />
</p>
!! end

!! test
HTML5 data attributes
!! wikitext
<span data-foo="bar">Baz</span>
<p data-abc-def_hij="">Quuz</p>
!! html/php
<p><span data-foo="bar">Baz</span>
</p>
<p data-abc-def_hij="">Quuz</p>
!! html/parsoid
<p><span data-foo="bar" data-parsoid='{"stx":"html"}'>Baz</span></p>
<p data-abc-def_hij="" data-parsoid='{"stx":"html"}'>Quuz</p>
!! end

!! test
Strip reserved data attributes
!! wikitext
<div data-mw="foo" data-parsoid="bar" data-mw-someext="baz" data-ok="fred" data-object-id="123" data-ooui="xyzzy" data-bad:ns="ns">d</div>
!! html/php
<div data-ok="fred" data-object-id="123">d</div>
!! html/parsoid
<div data-x-data-mw="foo" data-x-data-parsoid="bar" data-x-data-mw-someext="baz" data-ok="fred" data-x-data-object-id="123" data-parsoid='{"stx":"html","a":{"data-ooui":null,"data-bad:ns":null},"sa":{"data-ooui":"xyzzy","data-bad:ns":"ns"}}'>d</div>
!! end

!! test
percent-encoding and + signs in internal links (T28410)
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
[[User:+%]] [[Page+title%]]
[[%+]] [[%+|%20]] [[%+ ]] [[%+r]]
[[%]] [[+]] [[File:%+abc%39|foo|[[bar]]]]
[[%33%45]] [[%33%45+]]
!! html/php
<p><a href="/index.php?title=User:%2B%25&amp;action=edit&amp;redlink=1" class="new" title="User:+% (page does not exist)">User:+%</a> <a href="/index.php?title=Page%2Btitle%25&amp;action=edit&amp;redlink=1" class="new" title="Page+title% (page does not exist)">Page+title%</a>
<a href="/index.php?title=%25%2B&amp;action=edit&amp;redlink=1" class="new" title="%+ (page does not exist)">%+</a> <a href="/index.php?title=%25%2B&amp;action=edit&amp;redlink=1" class="new" title="%+ (page does not exist)">%20</a> <a href="/index.php?title=%25%2B&amp;action=edit&amp;redlink=1" class="new" title="%+ (page does not exist)">%+ </a> <a href="/index.php?title=%25%2Br&amp;action=edit&amp;redlink=1" class="new" title="%+r (page does not exist)">%+r</a>
<a href="/index.php?title=%25&amp;action=edit&amp;redlink=1" class="new" title="% (page does not exist)">%</a> <a href="/index.php?title=%2B&amp;action=edit&amp;redlink=1" class="new" title="+ (page does not exist)">+</a> <span class="mw-default-size" typeof="mw:Error mw:Image"><a href="/index.php?title=Special:Upload&amp;wpDestFile=%25%2Babc9" class="new" title="File:%+abc9"><span>File:%+abc9</span></a></span>
<a href="/index.php?title=3E&amp;action=edit&amp;redlink=1" class="new" title="3E (page does not exist)">3E</a> <a href="/index.php?title=3E%2B&amp;action=edit&amp;redlink=1" class="new" title="3E+ (page does not exist)">3E+</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./User:+%25" title="User:+%" data-parsoid='{"stx":"simple","a":{"href":"./User:+%25"},"sa":{"href":"User:+%"}}' class="new">User:+%</a> <a rel="mw:WikiLink" href="./Page+title%25" title="Page+title%" data-parsoid='{"stx":"simple","a":{"href":"./Page+title%25"},"sa":{"href":"Page+title%"}}' class="new">Page+title%</a>
<a rel="mw:WikiLink" href="./%25+" title="%+" data-parsoid='{"stx":"simple","a":{"href":"./%25+"},"sa":{"href":"%+"}}' class="new">%+</a> <a rel="mw:WikiLink" href="./%25+" title="%+" data-parsoid='{"stx":"piped","a":{"href":"./%25+"},"sa":{"href":"%+"}}' class="new">%20</a> <a rel="mw:WikiLink" href="./%25+" title="%+" data-parsoid='{"stx":"simple","a":{"href":"./%25+"},"sa":{"href":"%+ "}}' class="new">%+ </a> <a rel="mw:WikiLink" href="./%25+r" title="%+r" data-parsoid='{"stx":"simple","a":{"href":"./%25+r"},"sa":{"href":"%+r"}}' class="new">%+r</a>
<a rel="mw:WikiLink" href="./%25" title="%" data-parsoid='{"stx":"simple","a":{"href":"./%25"},"sa":{"href":"%"}}' class="new">%</a> <a rel="mw:WikiLink" href="./+" title="+" data-parsoid='{"stx":"simple","a":{"href":"./+"},"sa":{"href":"+"}}' class="new">+</a> <span class="mw-default-size" typeof="mw:Error mw:Image" data-parsoid='{"optList":[{"ck":"bogus","ak":"foo"},{"ck":"caption","ak":"[[bar]]"}]}' data-mw='{"caption":"&lt;a rel=\"mw:WikiLink\" href=\"./Bar\" title=\"Bar\" data-parsoid=&apos;{\"stx\":\"simple\",\"a\":{\"href\":\"./Bar\"},\"sa\":{\"href\":\"bar\"},\"dsr\":[94,101,2,2]}&apos;>bar&lt;/a>","errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/%25+abc9"><span resource="./File:%25+abc9" data-parsoid='{"a":{"resource":"./File:%25+abc9"},"sa":{"resource":"File:%+abc%39"}}'>File:%+abc9</span></a></span>
<a rel="mw:WikiLink" href="./3E" title="3E" data-parsoid='{"stx":"simple","a":{"href":"./3E"},"sa":{"href":"%33%45"}}' class="new">3E</a> <a rel="mw:WikiLink" href="./3E+" title="3E+" data-parsoid='{"stx":"simple","a":{"href":"./3E+"},"sa":{"href":"%33%45+"}}' class="new">3E+</a></p>
!! end

!! test
Confirm that 'apos' named character reference doesn't make it to output (not legal in HTML 4)
!! wikitext
Text&apos;s been normalized?
!! html
<p>Text&#39;s been normalized?
</p>
!! end

!! test
T21052 U+3000 IDEOGRAPHIC SPACE should terminate free external links
!! wikitext
http://www.example.org/　<-- U+3000 (vim: ^Vu3000)
!! html
<p><a rel="nofollow" class="external free" href="http://www.example.org/">http://www.example.org/</a>　&lt;-- U+3000 (vim: ^Vu3000)
</p>
!! end

!! test
T21052 U+3000 IDEOGRAPHIC SPACE should terminate bracketed external links
!! wikitext
[http://www.example.org/　ideograms]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.org/">ideograms</a>
</p>
!! end

!! test
T21052 U+3000 IDEOGRAPHIC SPACE should terminate external images links
!! wikitext
http://www.example.org/pic.png　<-- U+3000 (vim: ^Vu3000)
!! html
<p><img src="http://www.example.org/pic.png" alt="pic.png" />　&lt;-- U+3000 (vim: ^Vu3000)
</p>
!! end

!! article
Mediawiki:loop1
!! text
{{Identical|A}}
!! endarticle

!! article
Mediawiki:loop2
!! text
{{Identical|B}}
!! endarticle

!! article
Template:Identical
!! text
{{int:loop1}}
{{int:loop2}}
!! endarticle

!! test
T33098 Template which includes system messages which includes the template
!! wikitext
{{Identical}}
!! html
<p><span class="error">Template loop detected: <a href="/wiki/Template:Identical" title="Template:Identical">Template:Identical</a></span>
<span class="error">Template loop detected: <a href="/wiki/Template:Identical" title="Template:Identical">Template:Identical</a></span>
</p>
!! end

!! test
T33490 Turkish: ucfirst 'blah'
!! options
language=tr
!! wikitext
{{ucfirst:blah}}
!! html
<p>Blah
</p>
!! end

!! test
T33490 Turkish: ucfirst 'ix'
!! options
language=tr
!! wikitext
{{ucfirst:ix}}
!! html
<p>İx
</p>
!! end

!! test
T33490 Turkish: lcfirst 'BLAH'
!! options
language=tr
!! wikitext
{{lcfirst:BLAH}}
!! html
<p>bLAH
</p>
!! end

!! test
T33490 Turkish: ucfırst (with a dotless i)
!! options
language=tr
!! wikitext
{{ucfırst:blah}}
!! html
<p><a href="/index.php?title=%C5%9Eablon:Ucf%C4%B1rst:blah&amp;action=edit&amp;redlink=1" class="new" title="Şablon:Ucfırst:blah (sayfa mevcut değil)">Şablon:Ucfırst:blah</a>
</p>
!! end

!! test
T33490 ucfırst (with a dotless i) with English language
!! options
language=en
!! wikitext
{{ucfırst:blah}}
!! html
<p><a href="/index.php?title=Template:Ucf%C4%B1rst:blah&amp;action=edit&amp;redlink=1" class="new" title="Template:Ucfırst:blah (page does not exist)">Template:Ucfırst:blah</a>
</p>
!! end

# Note that Parsoid doesn't emit an explicit TOC.
# Note also that the html2wt direction tends to emit an extra newline
# between the __TOC__ magicword and the first heading unless *both*
# the <meta> and the <h2> have a data-parsoid attribute set (even if
# it's "{}").

!! test
T28375: TOC with italics
!! options
title=[[Main Page]]
!! wikitext
__TOC__
==''Lost'' episodes==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Lost_episodes"><span class="tocnumber">1</span> <span class="toctext"><i>Lost</i> episodes</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Lost_episodes"><i>Lost</i> episodes</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Lost episodes">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Lost_episodes" data-parsoid='{}'><i>Lost</i> episodes</h2>
!! end

!! test
T28375: TOC with bold
!! options
title=[[Main Page]]
!! wikitext
__TOC__
=='''should be bold''' then normal text==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#should_be_bold_then_normal_text"><span class="tocnumber">1</span> <span class="toctext"><b>should be bold</b> then normal text</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="should_be_bold_then_normal_text"><b>should be bold</b> then normal text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: should be bold then normal text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="should_be_bold_then_normal_text" data-parsoid='{}'><b>should be bold</b> then normal text</h2>
!! end

!! test
T35845: Headings become cursive in TOC when they contain an image
!! options
title=[[Main Page]]
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
__TOC__
==Image [[Image:foobar.jpg]]==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Image"><span class="tocnumber">1</span> <span class="toctext">Image</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Image">Image <span class="mw-default-size" typeof="mw:Image"><a href="/wiki/File:Foobar.jpg"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" /></a></span></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Image">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Image" data-parsoid='{}'>Image <span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://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></h2>
!! end

!! test
T35845 (2): Headings become bold in TOC when they contain a blockquote
!! options
title=[[Main Page]]
!! wikitext
__TOC__
==<blockquote>Quote</blockquote>==
!! html/php+untidy
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Quote"><span class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Quote"><blockquote>Quote</blockquote></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Quote">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/php+tidy
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Quote"><span class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Quote"><blockquote><p>Quote</p></blockquote></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Quote">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Quote" data-parsoid='{}'><blockquote><p>Quote</p></blockquote></h2>
!! end

!! test
Unclosed tags in TOC
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! options
title=[[Main Page]]
!! wikitext
__TOC__
==Proof: 2 < 3==
<small>Hanc marginis exiguitas non caperet.</small>
QED
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Proof:_2_&lt;_3"><span class="tocnumber">1</span> <span class="toctext">Proof: 2 &lt; 3</span></a></li>
</ul>
</div>

<h2><span id="Proof:_2_.3C_3"></span><span class="mw-headline" id="Proof:_2_&lt;_3">Proof: 2 &lt; 3</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: Proof: 2 &lt; 3">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p><small>Hanc marginis exiguitas non caperet.</small>
QED
</p>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Proof:_2_&lt;_3" data-parsoid='{}'><span id="Proof:_2_.3C_3" typeof="mw:FallbackId"></span>Proof: 2 &lt; 3</h2>
<p><small>Hanc marginis exiguitas non caperet.</small>
QED</p>
!! end

!! test
Multiple tags in TOC
!! wikitext
__TOC__
==<i>Foo</i> <b>Bar</b>==

==<i>Foo</i> <blockquote>Bar</blockquote>==
!! html/php+untidy
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none"/><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_Bar"><span class="tocnumber">1</span> <span class="toctext"><i>Foo</i> <b>Bar</b></span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext"><i>Foo</i> Bar</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Foo_Bar"><i>Foo</i> <b>Bar</b></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Foo_Bar_2"><i>Foo</i> <blockquote>Bar</blockquote></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/php+tidy
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_Bar"><span class="tocnumber">1</span> <span class="toctext"><i>Foo</i> <b>Bar</b></span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext"><i>Foo</i> Bar</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Foo_Bar"><i>Foo</i> <b>Bar</b></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Foo_Bar_2"><i>Foo</i> <blockquote><p>Bar</p></blockquote></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Foo_Bar" data-parsoid='{}'><i data-parsoid='{"stx":"html"}'>Foo</i> <b data-parsoid='{"stx":"html"}'>Bar</b></h2>

<h2 id="Foo_Bar_2" data-parsoid='{}'><i data-parsoid='{"stx":"html"}'>Foo</i> <blockquote><p>Bar</p></blockquote></h2>
!! end

# Don't expect Parsoid to roundtrip this until the php parser comes closer to
# html5 tag parsing.
!! test
Tags with parameters in TOC
!! options
parsoid=wt2html
!! wikitext
__TOC__
==<sup class="in-h2">Hello</sup>==

==<sup class="a > b">Evilbye</sup>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Hello"><span class="tocnumber">1</span> <span class="toctext"><sup>Hello</sup></span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#b.22.3EEvilbye"><span class="tocnumber">2</span> <span class="toctext"><sup> b"&gt;Evilbye</sup></span></a></li>
</ul>
</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 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>
!! html/parsoid
<meta property="mw:PageProp/toc" />
<h2 id="Hello"><sup class="in-h2" data-parsoid='{"stx":"html"}'>Hello</sup></h2>

<h2 id='b">Evilbye'><span id="b.22.3EEvilbye" typeof="mw:FallbackId"></span><sup class="a " data-parsoid='{"stx":"html"}'> b">Evilbye</sup></h2>
!! end

!! test
span tags with directionality in TOC
!! wikitext
__TOC__
==<span dir="ltr">C++</span>==

==<span dir="rtl">זבנג!</span>==

==<span style="font-style: italic">The attributes on these span tags must be deleted from the TOC</span>==

==<span style="font-style: italic" dir="ltr">All attributes on these span tags must be deleted from the TOC</span>==

==<span dir="ltr" style="font-style: italic">Attributes after dir on these span tags must be deleted from the TOC</span>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#C.2B.2B"><span class="tocnumber">1</span> <span class="toctext"><span dir="ltr">C++</span></span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#.D7.96.D7.91.D7.A0.D7.92.21"><span class="tocnumber">2</span> <span class="toctext"><span dir="rtl">זבנג!</span></span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#The_attributes_on_these_span_tags_must_be_deleted_from_the_TOC"><span class="tocnumber">3</span> <span class="toctext"><span>The attributes on these span tags must be deleted from the TOC</span></span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#All_attributes_on_these_span_tags_must_be_deleted_from_the_TOC"><span class="tocnumber">4</span> <span class="toctext"><span>All attributes on these span tags must be deleted from the TOC</span></span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#Attributes_after_dir_on_these_span_tags_must_be_deleted_from_the_TOC"><span class="tocnumber">5</span> <span class="toctext"><span dir="ltr">Attributes after dir on these span tags must be deleted from the TOC</span></span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="C.2B.2B"><span dir="ltr">C++</span></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: C++">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id=".D7.96.D7.91.D7.A0.D7.92.21"><span dir="rtl">זבנג!</span></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: זבנג!">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="The_attributes_on_these_span_tags_must_be_deleted_from_the_TOC"><span style="font-style: italic">The attributes on these span tags must be deleted from the TOC</span></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: The attributes on these span tags must be deleted from the TOC">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="All_attributes_on_these_span_tags_must_be_deleted_from_the_TOC"><span style="font-style: italic" dir="ltr">All attributes on these span tags must be deleted from the TOC</span></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: All attributes on these span tags must be deleted from the TOC">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Attributes_after_dir_on_these_span_tags_must_be_deleted_from_the_TOC"><span dir="ltr" style="font-style: italic">Attributes after dir on these span tags must be deleted from the TOC</span></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Attributes after dir on these span tags must be deleted from the TOC">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="C++" data-parsoid='{}'><span id="C.2B.2B" typeof="mw:FallbackId"></span><span dir="ltr">C++</span></h2>
<h2 id="זבנג!"><span id=".D7.96.D7.91.D7.A0.D7.92.21" typeof="mw:FallbackId"></span><span dir="rtl">זבנג!</span></h2>
<h2 id="The_attributes_on_these_span_tags_must_be_deleted_from_the_TOC"><span style="font-style: italic">The attributes on these span tags must be deleted from the TOC</span></h2>
<h2 id="All_attributes_on_these_span_tags_must_be_deleted_from_the_TOC"><span style="font-style: italic" dir="ltr">All attributes on these span tags must be deleted from the TOC</span></h2>
<h2 id="Attributes_after_dir_on_these_span_tags_must_be_deleted_from_the_TOC"><span dir="ltr" style="font-style: italic">Attributes after dir on these span tags must be deleted from the TOC</span></h2>
!! end

!! test
T74884: bdi element in ToC
!! wikitext
__TOC__
==<bdi>test</bdi>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#test"><span class="tocnumber">1</span> <span class="toctext"><bdi>test</bdi></span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="test"><bdi>test</bdi></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: test">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="test" data-parsoid='{}'><bdi>test</bdi></h2>
!! end

!! test
T35715: s/strike element in ToC
!! wikitext
__TOC__
==<s>test</s> test <strike>test</strike>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#test_test_test"><span class="tocnumber">1</span> <span class="toctext"><s>test</s> test <strike>test</strike></span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="test_test_test"><s>test</s> test <strike>test</strike></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: test test test">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="test_test_test" data-parsoid='{}'><s>test</s> test <strike>test</strike></h2>
!! end

!! test
T198618: style element in ToC
!! options
styletag=1
!! wikitext
__TOC__
==<style>.foo {}</style>Style<style>.bar {}</style>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Style"><span class="tocnumber">1</span> <span class="toctext">Style</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Style"><style>.foo {}</style>Style<style>.bar {}</style></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: Style">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid="{}"/>
<h2 id="Style" data-parsoid="{}"><style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo {}"}}'>.foo {}</style>Style<style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".bar {}"}}'>.bar {}</style></h2>
!! end

!! test
T198618: script element in ToC
!! options
wgRawHtml=1
!! wikitext
__TOC__
==<html><script>alert(1);</script></html>Script<html><script>alert(1);</script></html>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Script"><span class="tocnumber">1</span> <span class="toctext">Script</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Script"><script>alert(1);</script>Script<script>alert(1);</script></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: Script">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Script" data-parsoid='{}'><script typeof="mw:Extension/html" about="#mwt4" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;script>alert(1);&lt;/script>"}}'>alert(1);</script>Script<script typeof="mw:Extension/html" about="#mwt6" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;script>alert(1);&lt;/script>"}}'>alert(1);</script></h2>
!! end

!! test
Empty <p> tag in TOC, removed by Sanitizer (T92892)
!! wikitext
__TOC__
==x==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#x"><span class="tocnumber">1</span> <span class="toctext">x</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="x">x</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: x">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="x" data-parsoid='{}'>x</h2>
!! end

!! article
MediaWiki:T34057
!! text
== {{int:ok}} ==
!! endarticle

!! test
T34057: Title needed when expanding <h> nodes.
!! options
title=[[Main Page]]
!! wikitext
{{int:T34057}}
!! html
<h2><span class="mw-headline" id="OK">OK</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: OK">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
Title needed when expanding templates.
!! options
title=[[Main Page]]
!! wikitext
{{Template with pagename}}
!! html/php+tidy
<p>This is Main Page.
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Template with pagename","href":"./Template:Template_with_pagename"},"params":{},"i":0}}]}'>This is Main Page.</span></p>
!! end

!! test
Strip marker in urlencode
!! wikitext
{{urlencode:x<nowiki/>y}}
{{urlencode:x<nowiki/>y|wiki}}
{{urlencode:x<nowiki/>y|path}}
{{urlencode:x<pre id="one">two</pre>y}}
!! html/php
<p>xy
xy
xy
xy
</p>
!! end

!! test
Strip marker in lc
!! wikitext
{{lc:x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
Strip marker in uc
!! wikitext
{{uc:x<nowiki/>y}}
!! html
<p>XY
</p>
!! end

!! test
Strip marker in formatNum
!! wikitext
{{formatnum:1<nowiki/>2}}
{{formatnum:1<nowiki/>2|R}}
!! html
<p>12
12
</p>
!! end

!! test
Check noCommafy in formatNum
!! options
language=be-tarask
!! wikitext
{{formatnum:123456.78}}
{{formatnum:123456.78|NOSEP}}
!! html
<p>123&#160;456,78
123456.78
</p>
!! end

!! test
Wrong option for formatNum (T58199)
!! wikitext
{{formatnum:1,234.56|Random}}
{{formatnum:1,234.56|EVERYTHING}}
{{formatnum:1234.56|any argument that has the string 'NOSEP'}}
!! html
<p>1,234.56
1,234.56
1,234.56
</p>
!! end

!! test
Strip marker in grammar
!! options
language=fi
!! wikitext
{{grammar:elative|foo<nowiki/>bar}}
!! html
<p>foobarista
</p>
!! end

!! test
Strip marker in padleft
!! wikitext
{{padleft:|2|x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
Strip marker in padright
!! wikitext
{{padright:|2|x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
Strip marker in anchorencode
!! wikitext
{{anchorencode:x<nowiki/>y}}
!! html/php
<p>xy
</p>
!! html/parsoid
<p><span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode:x&lt;nowiki/>y","function":"anchorencode"},"params":{},"i":0}}]}'>xy</span></p>
!! end

!! test
nowiki inside link inside heading (T20295)
!! wikitext
==[[foo|x<nowiki>y</nowiki>z]]==
!! html
<h2><span class="mw-headline" id="xyz"><a href="/wiki/Foo" title="Foo">xyz</a></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: xyz">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! test
new support for bdi element (T33817)
!! wikitext
<p dir="rtl" lang="he">ולדימיר לנין (ברוסית: <bdi lang="ru">Владимир Ленин</bdi>, 24 באפריל 1870–22 בינואר 1924) הוא מנהיג פוליטי קומוניסטי רוסי.</p>
!! html
<p dir="rtl" lang="he">ולדימיר לנין (ברוסית: <bdi lang="ru">Владимир Ленин</bdi>, 24 באפריל 1870–22 בינואר 1924) הוא מנהיג פוליטי קומוניסטי רוסי.</p>
!! end

!! test
Ignore pipe between table row attributes
!! wikitext
{|
|quux
|- id=foo | style='color: red'
|bar
|}
!! html
<table>
<tbody><tr>
<td>quux
</td></tr>
<tr id="foo" style="color: red">
<td>bar
</td></tr></tbody></table>
!! end

!!test
Language parser function
!! wikitext
{{#language:ar}}
!! html
<p>العربية
</p>
!! end

!!test
Padleft and padright (default 0-padding)
!! wikitext
{{padleft:xyz|5}}
{{padright:xyz|5}}
!! html/php
<p>00xyz
xyz00
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padleft:xyz","function":"padleft"},"params":{"1":{"wt":"5"}},"i":0}}]}'>00xyz</span>
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:xyz","function":"padright"},"params":{"1":{"wt":"5"}},"i":0}}]}'>xyz00</span></p>
!! end

!!test
Padleft and padright (partial fill)
!! wikitext
{{padleft:xyz|6|ab}}
{{padright:xyz|6|ab}}
!! html/php
<p>abaxyz
xyzaba
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padleft:xyz","function":"padleft"},"params":{"1":{"wt":"6"},"2":{"wt":"ab"}},"i":0}}]}'>abaxyz</span>
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:xyz","function":"padright"},"params":{"1":{"wt":"6"},"2":{"wt":"ab"}},"i":0}}]}'>xyzaba</span></p>
!! end

!!test
Padleft and padright as substr
!! wikitext
{{padleft:|3|abcde}}
{{padright:|3|abcde}}
!! html/php
<p>abc
abc
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padleft:","function":"padleft"},"params":{"1":{"wt":"3"},"2":{"wt":"abcde"}},"i":0}}]}'>abc</span>
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:","function":"padright"},"params":{"1":{"wt":"3"},"2":{"wt":"abcde"}},"i":0}}]}'>abc</span></p>
!! end

!! test
Padleft and padright with non-numerical length (T180403)
!! wikitext
{{padleft:abcdef|junk}}
{{padright:abcdef|junk}}
!! html/php
<p>abcdef
abcdef
</p>
!! end

!!test
Special parser function
!! wikitext
{{#special:RandomPage}}
{{#special:BaDtItLe}}
{{#special:Foobar}}
!! html
<p>Special:Random
Special:Badtitle
Special:Foobar
</p>
!! end

!! test
Langconvert tag: crh-latn to crh-cyrl
!! wikitext
<langconvert from="crh-latn" to="crh-cyrl">test</langconvert>
!! html/php
<p>тест
</p>
!! end

!! test
Langconvert tag: en to en-x-piglatin
!! config
wgUsePigLatinVariant=true
!! wikitext
<langconvert from="en" to="en-x-piglatin">test</langconvert>
!! html/php
<p>esttay
</p>
!! end

!! test
Langconvert tag: gan-hans to gan-hant
!! wikitext
<langconvert from="gan-hans" to="gan-hant">爱</langconvert>
!! html/php
<p>愛
</p>
!! end

!! test
Langconvert tag: kk-latn to kk-cyrl
!! wikitext
<langconvert from="kk-latn" to="kk-cyrl">test</langconvert>
!! html/php
<p>тест
</p>
!! end

!! test
Langconvert tag: ku-latn to ku-arab
!! wikitext
<langconvert from="ku-latn" to="ku-arab">test</langconvert>
!! html/php
<p>تەست
</p>
!! end

!! test
Langconvert tag: shi-latn to shi-tfng
!! wikitext
<langconvert from="shi-latn" to="shi-tfng">test</langconvert>
!! html/php
<p>ⵜⴻⵙⵜ
</p>
!! end

!! test
Langconvert tag: sr-latn to sr-cyrl
!! wikitext
<langconvert from="sr-latn" to="sr-cyrl">zdravo</langconvert>
!! html/php
<p>здраво
</p>
!! end

!! test
Langconvert tag: sr-el to sr-ec (should fail)
!! wikitext
<langconvert from="sr-el" to="sr-ec">zdravo</langconvert>
!! html/php
<p><span class="error"><strong>Error:</strong> Langconvert tag's <code>from</code> and <code>to</code> attributes must not be empty and must contain BCP 47 codes for convertible variants of the same language.</span>
</p>
!! end

!! test
Langconvert tag: tg to tg-latn
!! wikitext
<langconvert from="tg" to="tg-latn">тест</langconvert>
!! html/php
<p>test
</p>
!! end

!! test
Langconvert tag: uz-cyrl to uz-latn
!! wikitext
<langconvert from="uz-cyrl" to="uz-latn">тест</langconvert>
!! html/php
<p>test
</p>
!! end

!! test
Langconvert tag: zh-hans to zh-hant
!! wikitext
<langconvert from="zh-hans" to="zh-hant">爱</langconvert>
!! html/php
<p>愛
</p>
!! end

!! test
Langconvert tag: self-closed
!! wikitext
x<langconvert from="crh-latn" to="crh-cyrl"/>x
!! html/php
<p>xx
</p>
!! end

# {{=}} will be converted to a parser function which expands to `=`
# If you have it defined as a Template that expands to `=` that's ok;
# and using it explicitly as {{Template:=}} (regardless of what it
# expands to) is also ok and will not generate a tracking category.
# T91154
!! test
Using {{=}} when it expands to "=" should not create a tracking category
!! wikitext
This uses {{=}} and {{Template:=}}.
!! html
<p>This uses = and =.
</p>
!! end

# Repeat the test, looking at categories.  Note: none should be emitted!
!! test
Using {{=}} when it expands to "=" should not create a tracking category (cat)
!! options
cat
!! wikitext
This uses {{=}} and {{Template:=}}.
!! html/php
!! end

!!test
T36939 - Case insensitive link parsing ([HttP://])
!! wikitext
[HttP://MediaWiki.Org/]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="HttP://MediaWiki.Org/">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="HttP://MediaWiki.Org/" class="external autonumber"></a></p>
!! end

!!test
T36939 - Case insensitive link parsing ([HttP:// title])
!! wikitext
[HttP://MediaWiki.Org/ MediaWiki]
!! html
<p><a rel="nofollow" class="external text" href="HttP://MediaWiki.Org/">MediaWiki</a>
</p>
!! end

!!test
T36939 - Case insensitive link parsing (HttP://)
!! wikitext
HttP://MediaWiki.Org/
!! html/php
<p><a rel="nofollow" class="external free" href="HttP://MediaWiki.Org/">HttP://MediaWiki.Org/</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="HttP://MediaWiki.Org/" class="external free">HttP://MediaWiki.Org/</a></p>
!! end

!!test
Disable TOC
!! options
notoc
!! wikitext
Lead
==Section 1==
==Section 2==
==Section 3==
==Section 4==
==Section 5==
!! html
<p>Lead
</p>

<h2><span class="mw-headline" id="Section_1">Section 1</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: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Section_2">Section 2</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: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Section_3">Section 3</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Section 3">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Section_4">Section 4</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Section 4">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Section_5">Section 5</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Section 5">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end


###
### Parsoid-specific tests
### Parsoid-PHP parser incompatibilities
###
!!test
1. SOL-sensitive wikitext tokens as template-args
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{1x|*a}}
{{1x|#a}}
{{1x|:a}}
!! html/php+tidy
<ul><li>a</li></ul>
<ol><li>a</li></ol>
<dl><dd>a</dd></dl>
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion">
</span><ul about="#mwt1"><li>a</li>
</ul>
<span about="#mwt2" typeof="mw:Transclusion">
</span><ol about="#mwt2"><li>a</li>
</ol>
<span about="#mwt3" typeof="mw:Transclusion">
</span><dl about="#mwt3"><dd>a</dd>
</dl>
!!end

#### -----------------------------------------------------------------
#### Parsoid-specific functionality tests
#### -----------------------------------------------------------------

## Just a regression test
!! test
Wikilink with only closing tag in target
!! options
parsoid=wt2html
!! wikitext
[[Test|</span>]]
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Test" title="Test" class="new"></a></p>
!! end

#### ----------------------------------------------------------------
#### Parsoid-only testing of Parsoid's impl of LST
#### Not implemented yet, see
#### https://www.mediawiki.org/wiki/Parsoid/HTML_based_LST
#### ----------------------------------------------------------------

## We still need to support serializing the older format while content is stored.
!! test
LST Sections: Backwards compatibility
!! options
parsoid={
  "suppressErrors": true,
  "modes": ["html2wt"]
}
!! wikitext
<section begin="2011-05-16" />
<section end="2014-04-10 (MW 1.23wmf22)" />
!! html/parsoid
<p><meta typeof="mw:Extension/LabeledSectionTransclusion/begin" content="2011-05-16"/>
<meta typeof="mw:Extension/LabeledSectionTransclusion/end" content="2014-04-10 (MW 1.23wmf22)"/></p>
!! end

!! test
LST Sections: Newfangled approach
!! wikitext
<section begin="2011-05-16" />
<section end="2014-04-10 (MW 1.23wmf22)" />
!! html/parsoid
<p><span typeof="mw:Extension/section" about="#mwt4" data-mw='{"name":"section","attrs":{"begin":"2011-05-16"}}'>
</span>
<span typeof="mw:Extension/section" about="#mwt6" data-mw='{"name":"section","attrs":{"end":"2014-04-10 (MW 1.23wmf22)"}}'>
</span></p>
!! end

#--------- Test stripping of empty nodes in template content ----------

!! test
Empty LI and TR nodes should be stripped from template content
!! wikitext
{{EmptyLITest}}
{{EmptyTRTest}}
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"EmptyLITest","href":"./Template:EmptyLITest"},"params":{},"i":0}}]}'>
<li>a</li>
<li>b</li>
</ul>
<table about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"EmptyTRTest","href":"./Template:EmptyTRTest"},"params":{},"i":0}}]}'>
<tbody>
<tr>
<td>foo</td>
</tr>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

!! test
Empty LI and TR nodes should not be stripped from top-level content
!! wikitext
*a
*
*b

{|
|-
|-
|foo
|}
!! html/parsoid
<ul>
<li>a</li>
<li class='mw-empty-elt'></li>
<li>b</li>
</ul>
<table>
<tbody>
<tr class='mw-empty-elt'></tr>
<tr>
<td>foo</td>
</tr>
</tbody>
</table>
!! end

!! test
Empty TR nodes should not be stripped if they have any attributes set
!! wikitext
{{EmptyTRWithHTMLAttrTest}}
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"EmptyTRWithHTMLAttrTest","href":"./Template:EmptyTRWithHTMLAttrTest"},"params":{},"i":0}}]}'>
<tr align='center'></tr>
<tr><td>foo</td></tr>
<tr align='center'></tr>
<tr><td>bar</td></tr>
</table>
!! end

#### ----------------------------------------------------------------
#### The following section of tests are primarily to test
#### wikitext escaping capabilities of Parsoid.  Given that
#### escaping can be done any number of ways, the wikitext (input)
#### is always adjusted to reflect how Parsoid adds nowiki
#### escape tags.
####
#### We are marking several tests as parsoid-only since the
#### HTML in the result section is different from what the
#### PHP parser generates for it.
#### ----------------------------------------------------------------


#### --------------- Headings ---------------
#### 0. Unnested
#### 1. Nested inside html <h1>=foo=</h1>
#### 2. Outside heading nest on a single line <h1>foo</h1>*bar
#### 3. Nested inside html with wikitext split by html tags
#### 4. No escape needed
#### 5. Empty headings <h1></h1>
#### 6. Heading chars in SOL context
#### ----------------------------------------
!! test
Headings: 0. Unnested
!! options
parsoid=html2wt
!! html/parsoid
<p>=foo=</p>

<p> =foo=
<!--cmt-->
=foo=</p>

<p>=foo<i>a</i>=</p>
!! wikitext
<nowiki>=foo=</nowiki>

<nowiki> </nowiki>=foo=
<!--cmt-->
<nowiki>=foo=</nowiki>

=foo''a''<nowiki>=</nowiki>
!!end

# New headings and existing headings are handled differently
!! test
Headings: 1. Nested inside html
!! options
parsoid=html2wt
!! html/parsoid
<h1>=foo=</h1>
<h2>=foo=</h2>
<h3>=foo=</h3>

<h1 data-parsoid='{}'>=foo=</h1>
<h2 data-parsoid='{}'>=foo=</h2>
<h3 data-parsoid='{}'>=foo=</h3>
<h4 data-parsoid='{}'>=foo=</h4>
<h5 data-parsoid='{}'>=foo=</h5>
<h6 data-parsoid='{}'>=foo=</h6>
!! wikitext
= =foo= =

== =foo= ==

=== =foo= ===

=<nowiki>=foo=</nowiki>=
==<nowiki>=foo=</nowiki>==
===<nowiki>=foo=</nowiki>===
====<nowiki>=foo=</nowiki>====
=====<nowiki>=foo=</nowiki>=====
======<nowiki>=foo=</nowiki>======
!! end

!! test
Headings: 2. Outside heading nest on a single line <h1>foo</h1>*bar
!! options
parsoid=html2wt
!! html/parsoid
<h1>foo</h1>*bar
<h1>foo</h1>=bar
<h1>foo</h1>=bar=
!! wikitext
= foo =
<nowiki>*</nowiki>bar

= foo =
=bar

= foo =
<nowiki>=bar=</nowiki>
!!end

!! test
Headings: 3. Nested inside html with wikitext split by html tags
!! options
parsoid=html2wt
!! html/parsoid
<h1>=<b>bold</b>foo=</h1>
!! wikitext
= ='''bold'''foo= =
!!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 =

= foo= =

= =foo= =

= =foo= bar =

== =foo ==

== foo= ==

= = =

= ''=''foo= =
!!end

!! test
Headings: 4b. No escaping needed (inside p-tags)
!! options
parsoid=html2wt
!! html/parsoid
<p>=foo= x
=foo= <s></s>
</p>
!! wikitext
=foo= x
=foo= <s></s>
!! html/php
<p>=foo= x
=foo= <s></s>
</p>
!!end

!! test
Headings: 4c. Short headings (1)
!! options
parsoid=html2wt
!! html/parsoid
<p>===
</p>
!! wikitext
<nowiki>===</nowiki>
!! html/php
<p>===
</p>
!! end

# in the html2wt direction we emit '= = =' or '=<nowiki>=</nowiki>='
!! test
Headings: 4d. Short headings (2)
!! options
parsoid=wt2html,html2html
!! wikitext
=
==
===
====
=====
!! html/php
<p>=
==
</p>
<h1><span class="mw-headline" id=".3D">=</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: =">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h1><span class="mw-headline" id=".3D.3D">==</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: ==">edit</a><span class="mw-editsection-bracket">]</span></span></h1>
<h2><span class="mw-headline" id=".3D_2">=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: =">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! html/parsoid
<p>=
==</p>
<h1 id="="><span id=".3D" typeof="mw:FallbackId"></span>=</h1>
<h1 id="=="><span id=".3D.3D" typeof="mw:FallbackId"></span>==</h1>
<h2 id="=_2"><span id=".3D_2" typeof="mw:FallbackId"></span>=</h2>
!! end

!! 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/>=

==<nowiki/>==

===<nowiki/>===

====<nowiki/>====

=====<nowiki/>=====

======<nowiki/>======
!!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>	
!!end

!! test
Headings: 6b. Heading chars in SOL context (with trailing newlines)
!! options
parsoid=html2wt
!! html/parsoid
<p>=a=
b</p>

<p>=a= 
b</p>

<p>=a=	
b</p>
!! wikitext
<nowiki>=a=</nowiki>
b

<nowiki>=a=</nowiki> 
b

<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>
!!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-->
!!end

!! test
Headings: 6d. Heading chars in SOL context (No escaping needed)
!! options
parsoid=html2wt
!! html/parsoid
=a=<div>b</div>
!! wikitext
=a=<div>b</div>
!!end

!! test
Headings: 7. Insert a newline between new content and headings
!! options
parsoid=html2wt
!! html/parsoid
<h2>NEW</h2>
<p>new</p>
<h2 data-parsoid='{}'>A</h2>
<p data-parsoid='{}'>a</p>
!! wikitext
== NEW ==
new

==A==
a
!! end

!! test
Headings: Used as horizontal rule
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! options
parsoid=wt2html
!! wikitext
===============
!! html/php
<h6><span id=".3D.3D.3D"></span><span class="mw-headline" id="===">===</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: ===">edit</a><span class="mw-editsection-bracket">]</span></span></h6>
!! html/parsoid
<h6 id="==="><span id=".3D.3D.3D" typeof="mw:FallbackId"></span>===</h6>
!! end

#### --------------- Lists ---------------
#### 0. Outside nests (*foo, etc.)
#### 1. Nested inside html <ul><li>*foo</li></ul>
#### 2. Inside definition lists
#### 3. Only bullets at start should be escaped
#### 4. No escapes needed
#### 5. No unnecessary escapes
#### 6. Escape bullets in SOL position
#### 7. Escape bullets in a multi-line context
#### ----------------------------------------

!! 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>;</nowiki>Foo<nowiki>:</nowiki>bar
!!end

## Making these next 3 tests Parsoid-only since they are html2wt tests
## to test wikitext escaping, and insignificant whitespace diffs
## cause PHP parser tests to barf
!! test
Lists: 1. Nested inside html (No unnecessary escapes)
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>*foo</li>
<li>#foo</li>
<li>:foo</li>
<li>;foo</li>
<li data-parsoid='{}'>*foo</li>
<li data-parsoid='{}'>#foo</li>
<li data-parsoid='{}'>:foo</li>
<li data-parsoid='{}'>;foo</li>
</ul>

<ol>
<li>*foo</li>
<li>#foo</li>
<li>:foo</li>
<li>;foo</li>
<li data-parsoid='{}'>*foo</li>
<li data-parsoid='{}'>#foo</li>
<li data-parsoid='{}'>:foo</li>
<li data-parsoid='{}'>;foo</li>
</ol>
!! wikitext
* *foo
* #foo
* :foo
* ;foo
*<nowiki>*foo</nowiki>
*<nowiki>#foo</nowiki>
*<nowiki>:foo</nowiki>
*<nowiki>;foo</nowiki>

# *foo
# #foo
# :foo
# ;foo
#<nowiki>*foo</nowiki>
#<nowiki>#foo</nowiki>
#<nowiki>:foo</nowiki>
#<nowiki>;foo</nowiki>
!!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
; ;foo

; <nowiki>:foo</nowiki>

; <nowiki>:foo</nowiki>
: bar

: :foo
!!end

!! test
Lists: 3. Only bullets at start of text in wikitext-generated HTML should be escaped
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>*foo*bar</li>
<li data-parsoid='{}'>*foo<i>it</i>*bar</li>
</ul>
!! wikitext
* *foo*bar
*<nowiki>*foo</nowiki>''it''*bar
!!end

!! test
Lists: 4. No escapes needed
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>foo*bar
</li>
</ul>
<ul>
<li><i>foo</i>*bar
</li>
</ul>
<ul>
<li><a rel="mw:WikiLink" href="Foo" title="Foo">Foo</a>: bar
</li>
</ul>
<ul>
<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>

* =bar <span><nowiki>[[foo]]</nowiki></span>

* [[bar <span><nowiki>[[foo]]</nowiki></span>

* ]]bar <span><nowiki>[[foo]]</nowiki></span>

* =bar <span>foo]]</span>=

* <s></s>: a

* ''* foo''
!!end

!! test
Lists: 6. Escape bullets in SOL position
!! options
parsoid=html2wt
!! html/parsoid
<p><!--cmt-->*foo</p>
!! wikitext
<!--cmt--><nowiki>*</nowiki>foo
!!end

!! test
Lists: 7. Escape bullets in a multi-line context
!! 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/parsoid
<dl><dt>a:b<i>c:d</i></dt></dl>
!! wikitext
; <nowiki>a:b</nowiki>''c:d''
!! end

#### --------------- HRs ---------------
#### 1. Single line
#### -----------------------------------

!! test
HRs: 1. Single line
!! options
parsoid=html2wt
!! html/parsoid
<hr />----
<hr />=foo=
<hr />*foo
!! wikitext
----<nowiki>----</nowiki>
----=foo=
----*foo
!! end

#### --------------- Tables ---------------
#### 1a. Simple example
#### 1b. No escaping needed (!foo)
#### 1c. No escaping needed (|foo)
#### 1d. No escaping needed (|}foo)
####
#### 2a. Nested in td (<td>foo|bar</td>)
#### 2b. Nested in td (<td>foo||bar</td>)
#### 2c. Nested in td -- no escaping needed(<td>foo!!bar</td>)
####
#### 3a. Nested in th (<th>foo!bar</th>)
#### 3b. Nested in th (<th>foo!!bar</th>)
#### 3c. Nested in th -- no escaping needed(<th>foo||bar</th>)
####
#### 4a. Escape -
#### 4b. Escape +
#### 4c. No escaping needed
#### --------------------------------------

!! test
Tables: 1a. Simple example
!! options
parsoid=html2wt
!! html/parsoid
<p>{|
|}
</p>
!! wikitext
<nowiki>{|</nowiki>
|}
!! end

!! test
Tables: 1b. No escaping needed
!! options
parsoid=html2wt
!! html/parsoid
<p>!foo
</p>
!! wikitext
!foo
!! end

!! test
Tables: 1c. No escaping needed
!! options
parsoid=html2wt
!! html/parsoid
<p>|foo
</p>
!! wikitext
|foo
!! end

!! test
Tables: 1d. No escaping needed
!! options
parsoid=html2wt
!! html/parsoid
<p>|}foo
</p>
!! wikitext
|}foo
!! end

!! test
Tables: 2a. Nested in td
!! options
parsoid=html2wt
!! html/parsoid
<table><tbody><tr>
<td>foo|bar</td></tr>
<tr><td>x<div>a|b</div></td>
</tbody></table>
!! wikitext
{|
|<nowiki>foo|bar</nowiki>
|-
|x<div><nowiki>a|b</nowiki></div>
|}
!! html/php+tidy
<table>
<tbody><tr>
<td>foo|bar
</td></tr>
<tr>
<td>x<div>a|b</div>
</td></tr></tbody></table>
!! end

!! test
Tables: 2b. Nested in td
!! options
parsoid=html2wt
!! html/parsoid
<table><tbody><tr>
<td>foo||bar</td>
<td>a<i>b||c</i></td>
<td>a<i><div>b||c</div></i></td>
</tr></tbody></table>
!! wikitext
{|
|<nowiki>foo||bar</nowiki>
|a''<nowiki>b||c</nowiki>''
|a''<div><nowiki>b||c</nowiki></div>''
|}
!! html/php
<table>
<tbody><tr>
<td>foo||bar
</td>
<td>a<i>b||c</i>
</td>
<td>a<i><div>b||c</div></i>
</td></tr></tbody></table>
!! end

!! test
Tables: 2c. Nested in td -- no escaping needed
!! options
parsoid=html2wt
!! html/*
<table>
<tbody><tr>
<td>foo!!bar
</td></tr></tbody></table>
!! wikitext
{|
|foo!!bar
|}
!! end

!! test
Tables: 3a. Nested in th
!! options
parsoid=html2wt
!! html/*
<table>
<tbody><tr>
<th>foo!bar
</th></tr></tbody></table>
!! wikitext
{|
!foo!bar
|}
!! end

!! test
Tables: 3b. Nested in th
!! options
parsoid=html2wt
!! html/parsoid
<table><tbody>
<tr><th>foo!!bar</th>
<th><i>foo|bar</i></th>
<th><i>foo!!bar</i></th>
<th><i><span>foo!!bar</span></i></th>
</tr></tbody></table>
!! wikitext
{|
!<nowiki>foo!!bar</nowiki>
!''<nowiki>foo|bar</nowiki>''
!''<nowiki>foo!!bar</nowiki>''
!''<span><nowiki>foo!!bar</nowiki></span>''
|}
!! html/php
<table>
<tbody><tr>
<th>foo!!bar
</th>
<th><i>foo|bar</i>
</th>
<th><i>foo!!bar</i>
</th>
<th><i><span>foo!!bar</span></i>
</th></tr></tbody></table>
!! end

!! test
Tables: 3c. Nested in th
!! options
parsoid=html2wt
!! html/parsoid
<table><tbody>
<tr><th>foo||bar</th>
<th><span typeof="mw:Nowiki">foo||bar</span></th>
</tr></tbody></table>
!! wikitext
{|
!<nowiki>foo||bar</nowiki>
!<nowiki>foo||bar</nowiki>
|}
!! html/php
<table>
<tbody><tr>
<th>foo||bar
</th>
<th>foo||bar
</th></tr></tbody></table>
!! end

!! test
Tables: 4a. Escape -
!! options
parsoid=html2wt
!! html/*
<table>
<tbody><tr>
<th>-bar
</th></tr>
<tr>
<td>-bar
</td></tr></tbody></table>
!! wikitext
{|
!-bar
|-
|<nowiki>-bar</nowiki>
|}
!! end

!! test
Tables: 4b. Escape +
!! options
parsoid=html2wt
!! html/*
<table>
<tbody><tr>
<th>+bar
</th></tr>
<tr>
<td>+bar
</td></tr></tbody></table>
!! wikitext
{|
!+bar
|-
|<nowiki>+bar</nowiki>
|}
!! end

!! 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
|foo+bar
|-
|''foo''-bar
|''foo''+bar
|-
|foo
bar|baz
+bar
-bar
|-
|x
<div>a|b</div>
|}
!! html/php
<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></tr></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
||+1
||-2
|}
!! html/php
<table>
<tbody><tr>
<td><a href="/wiki/Foo" title="Foo">Foo</a>-bar
</td>
<td>+1
</td>
<td>-2
</td></tr></tbody></table>
!! end

!! test
Tables: 4e. Escape }
!! options
parsoid=html2wt
!! html/parsoid
<table>
<tr><td>}</td></tr>
<tr><td>x</td><td data-parsoid='{"stx":"row"}'>}</td></tr></table>
</table>
!! wikitext
{|
|<nowiki>}</nowiki>
|-
|x||}
|}
!! html/php
<table>
<tbody><tr>
<td>}
</td></tr>
<tr>
<td>x</td>
<td>}
</td></tr></tbody></table>
!! end

!! test
Tables: 5. Empty table cells should get whitespace to avoid need for nowikis
!! options
parsoid=html2wt
!! html/parsoid
<table><tr><td></td><td align="center" data-parsoid='{"stx":"row"}'></td><td data-parsoid='{"stx":"row"}'></td></tr></table>

<table><tr><td></td><td align="center"></td><td></td></tr></table>

<table><tr><td></td><td align="center" data-parsoid='{"stx":"row", "startTagSrc":"{{!}}{{!}}"}'></td><td data-parsoid='{"stx":"row"}'></td></tr></table>

<table><tr><th></th><th align="center" data-parsoid='{"stx":"row"}'></th><th data-parsoid='{"stx":"row"}'></th></tr></table>
!! wikitext
{|
| || align="center" | ||
|}

{|
|
| align="center" |
|
|}

{|
| {{!}}{{!}} align="center" | ||
|}

{|
! !! align="center" | !!
|}
!! html/php+tidy
<table>
<tbody><tr>
<td></td>
<td align="center"></td>
<td>
</td></tr></tbody></table>
<table>
<tbody><tr>
<td>
</td>
<td align="center">
</td>
<td>
</td></tr></tbody></table>
<table>
<tbody><tr>
<td></td>
<td align="center"></td>
<td>
</td></tr></tbody></table>
<table>
<tbody><tr>
<th></th>
<th align="center"></th>
<th>
</th></tr></tbody></table>
!! end

!! test
T97430: Don't emit empty nowiki pairs around marker meta tags
!! options
parsoid=html2wt
!! 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
<nowiki>*</nowiki>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.
!! end

!! 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
| bar>
|}
!! html/php
<table>
<tbody><tr>
<td>&lt;foo
</td>
<td>bar&gt;
</td></tr></tbody></table>
!! end

#### --------------- Links ----------------
#### 1. Quote marks in link text
#### 2. Wikilinks: Escapes needed
#### 3. Wikilinks: No escapes needed
#### 4. Extlinks: Escapes needed
#### 5. Extlinks: No escapes needed
#### --------------------------------------
!! 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]]]
[[Foo|x [Foobar] x]]
!! html/php
<p><a href="/wiki/Foo" title="Foo">Foo<i>boo</i></a>
<a href="/wiki/Foo" title="Foo">[Foobar]</a>
<a href="/wiki/Foo" title="Foo">x [Foobar] x</a>
</p>
!! end

!! test
Links 2. WikiLinks: Escapes needed
!! options
parsoid=html2wt
!! html/parsoid
<a href="Foo" rel="mw:WikiLink">Foobar]</a>
<a href="Foo" rel="mw:WikiLink">x [http://google.com g] x</a>
<a href="Foo" rel="mw:WikiLink">[[Bar]]</a>
<a href="Foo" rel="mw:WikiLink">x [[Bar]] x</a>
<a href="Foo" rel="mw:WikiLink">|Bar</a>
<a href="Foo" rel="mw:WikiLink">]]bar</a>
<a href="Foo" rel="mw:WikiLink">[[bar</a>
<a href="Foo" rel="mw:WikiLink">x [[ y</a>
<a href="Foo" rel="mw:WikiLink">x ]] y</a>
<a href="Foo" rel="mw:WikiLink">x ]] y [[ z</a>
!! wikitext
[[Foo|<nowiki>Foobar]</nowiki>]]
[[Foo|x <nowiki>[http://google.com g]</nowiki> x]]
[[Foo|<nowiki>[[Bar]]</nowiki>]]
[[Foo|<nowiki>x [[Bar]] x</nowiki>]]
[[Foo||Bar]]
[[Foo|<nowiki>]]bar</nowiki>]]
[[Foo|<nowiki>[[bar</nowiki>]]
[[Foo|<nowiki>x [[ y</nowiki>]]
[[Foo|<nowiki>x ]] y</nowiki>]]
[[Foo|<nowiki>x ]] y [[ z</nowiki>]]
!! html/php
<p><a href="/wiki/Foo" title="Foo">Foobar]</a>
<a href="/wiki/Foo" title="Foo">x [http://google.com g] x</a>
<a href="/wiki/Foo" title="Foo">[[Bar]]</a>
<a href="/wiki/Foo" title="Foo">x [[Bar]] x</a>
<a href="/wiki/Foo" title="Foo">|Bar</a>
<a href="/wiki/Foo" title="Foo">]]bar</a>
<a href="/wiki/Foo" title="Foo">[[bar</a>
<a href="/wiki/Foo" title="Foo">x [[ y</a>
<a href="/wiki/Foo" title="Foo">x ]] y</a>
<a href="/wiki/Foo" title="Foo">x ]] y [[ z</a>
</p>
!! end

!! 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]]
!! html/php
<p><a href="/wiki/Foo" title="Foo">[Foobar</a>
<a href="/wiki/Foo" title="Foo">foo|bar</a>
</p>
!! end

!! test
Links 4. ExtLinks: Escapes needed
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://google.com">[google]</a>
<a rel="mw:ExtLink" href="http://google.com">google]</a>
<a rel="mw:ExtLink" href="http://google.com">goog] le</a></p>
<p>[http://google.com]</p>
<p>[http://google.com google]</p>
<p>[<a rel="mw:ExtLink" href="http://google.com">http://google.com</a>]</p>
<p>[<a rel="mw:ExtLink" href="http://google.com" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"http://google.com"}},"i":0}}]}'>http://google.com</a>]</p>
!! wikitext
[http://google.com <nowiki>[google]</nowiki>]
[http://google.com <nowiki>google]</nowiki>]
[http://google.com <nowiki>goog] le</nowiki>]

<nowiki>[http://google.com]</nowiki>

<nowiki>[http://google.com google]</nowiki>

[http://google.com<nowiki>]</nowiki>

[{{1x|http://google.com}}<nowiki>]</nowiki>
!! html/php
<p><a rel="nofollow" class="external text" href="http://google.com">[google]</a>
<a rel="nofollow" class="external text" href="http://google.com">google]</a>
<a rel="nofollow" class="external text" href="http://google.com">goog] le</a>
</p><p>[http://google.com]
</p><p>[http://google.com google]
</p><p>[<a rel="nofollow" class="external free" href="http://google.com">http://google.com</a>]
</p><p>[<a rel="nofollow" class="external free" href="http://google.com">http://google.com</a>]
</p>
!! end

!! test
Links 5. ExtLinks: No escapes needed
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://google.com">[google</a></p>
<p>[<a ref="mw:ExtLink" href="http://google.com"></a>]</p>
!! wikitext
[http://google.com [google]

[[http://google.com]]
!! html/php
<p><a rel="nofollow" class="external text" href="http://google.com">[google</a>
</p><p>[<a rel="nofollow" class="external autonumber" href="http://google.com">[1]</a>]
</p>
!! end

!! test
Links 6. Add <nowiki/>s between text-nodes and url-links when required (T66300)
!! 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
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>&amp;x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>'x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>,x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>.x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>;x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>:x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>;x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>!x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>=x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>(x)
<a rel="mw:ExtLink" href="http://example.com(x" data-parsoid='{"stx":"url"}'>http://example.com(x</a>)
</p>
!! wikitext
x<nowiki/>http://example.com<nowiki/>y
http://example.com<nowiki/>?x
http://example.com<nowiki/>&x
http://example.com<nowiki/>'x
http://example.com<nowiki/>,x
http://example.com<nowiki/>.x
http://example.com<nowiki/>;x
http://example.com<nowiki/>:x
http://example.com<nowiki/>;x
http://example.com<nowiki/>!x
http://example.com<nowiki/>=x
http://example.com<nowiki/>(x)
http://example.com(x<nowiki/>)
!! end

!! test
Links 7a. Don't add spurious <nowiki/>s between text-nodes and url-links (T66300)
!! 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>"
(<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>)
(<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>) foo
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>,
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>, foo
</p>
!! wikitext
x
http://example.com
y
"http://example.com"
(http://example.com)
(http://example.com) foo
http://example.com,
http://example.com, foo
!! html/php
<p>x
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
y
"<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>"
(<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>)
(<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>) foo
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>,
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>, foo
</p>
!! end

!! test
Links 7b. Don't add spurious <nowiki/>s between text-nodes and url-links (T66300)
!! 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>
!! wikitext
http://example.com.,;:!?\
-http://example.com:
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>.,;:!?\
-<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>:
</p>
!! end

!! test
Links 8. Add <nowiki/>s between text-nodes and RFC-links when required (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="https://tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>4
<a href="https://tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>y
X<a href="https://tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>y</p>
!! wikitext
RFC 123<nowiki/>4
RFC 123<nowiki/>y
X<nowiki/>RFC 123<nowiki/>y
!! end

!! test
Links 9. Don't add spurious <nowiki/>s between text-nodes and RFC-links (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="https://tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>?foo
<a href="https://tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>&amp;foo
-<a href="https://tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>-
</p>
!! wikitext
RFC 123?foo
RFC 123&foo
-RFC 123-
!! html/php
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc123">RFC 123</a>?foo
<a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc123">RFC 123</a>&amp;foo
-<a class="external mw-magiclink-rfc" rel="nofollow" href="https://tools.ietf.org/html/rfc123">RFC 123</a>-
</p>
!! end

!! test
Links 10. Add <nowiki/>s between text-nodes and PMID-links when required (T66300)
!! 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
X<a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>y
!! wikitext
PMID 123<nowiki/>4
PMID 123<nowiki/>y
X<nowiki/>PMID 123<nowiki/>y
!! end

!! test
Links 11. Don't add spurious <nowiki/>s between text-nodes and PMID-links (T66300)
!! 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
-<a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>-
</p>
!! wikitext
PMID 123?foo
PMID 123&foo
-PMID 123-
!! html/php
<p><a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract">PMID 123</a>?foo
<a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract">PMID 123</a>&amp;foo
-<a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract">PMID 123</a>-
</p>
!! end

!! test
Links 12. Add <nowiki/>s between text-nodes and ISBN-links when required (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<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
ISBN 1234567890<nowiki/>x
a<nowiki/>ISBN 1234567890<nowiki/>b
!! end

!! test
Links 13. Don't add spurious <nowiki/>s between text-nodes and ISBN-links (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p>-<a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>'s
!! wikitext
-ISBN 1234567890's
!! html/php
<p>-<a href="/wiki/Special:BookSources/1234567890" class="internal mw-magiclink-isbn">ISBN 1234567890</a>'s
</p>
!! end

!! test
Links 14. Protect link-like plain text. (Parsoid bug T78425)
!! options
parsoid=html2wt
!! html/*
<p>this is not a link: http://example.com
</p>
!! wikitext
this is not a link: <nowiki>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>
!! end

# This example actually from lnwiki, but arwiki has the same link
# prefix and equivalent link trail for this purpose.
!! test
Links 17. Link trails (T236183)
!! options
language=ar
!! wikitext
[[Likalo]]&nbsp;·
[[Pusupúsu]]&nbsp;·
!! html/php+tidy
<p><a href="/index.php?title=Likalo&amp;action=edit&amp;redlink=1" class="new" title="Likalo (الصفحة غير موجودة)">Likalo</a>&#160;·
<a href="/index.php?title=Pusup%C3%BAsu&amp;action=edit&amp;redlink=1" class="new" title="Pusupúsu (الصفحة غير موجودة)">Pusupúsu</a>&#160;·
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Likalo" title="Likalo" data-parsoid='{"stx":"simple","a":{"href":"./Likalo"},"sa":{"href":"Likalo"}}' class="new">Likalo</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>·
<a rel="mw:WikiLink" href="./Pusupúsu" title="Pusupúsu" data-parsoid='{"stx":"simple","a":{"href":"./Pusupúsu"},"sa":{"href":"Pusupúsu"}}' class="new">Pusupúsu</a><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>·</p>
!! end

#### --------------- Quotes ---------------
#### 1. Quotes inside <b> and <i>
#### 2. Link fragments separated by <i> and <b> tags
#### 3. Link fragments inside <i> and <b>
#### 4. No escaping needed
#### --------------------------------------
!! test
1a. Quotes inside <b> and <i>
!! options
parsoid=html2wt
!! html/*
<p><i>'foo'</i>
<i>''foo''</i>
<i>'''foo'''</i>
<i>foo</i>'s
<b>'foo'</b>
<b>''foo''</b>
<b>'''foo'''</b>
<b>foo'<i>bar'</i>baz</b>
<b>foo</b>'s
'<i>foo</i>
<i>foo</i>'
<i>foo'</i>'
'<i>foo</i>'
'<b>foo</b>
<b>foo</b>'
'<b>foo</b>'
<i>fools'<span> errand</span></i>
<i><span>fool</span>'s errand</i>
'<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
!! 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":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[bar]]"}},"i":0}}]}'>bar</a></b>
<a rel="mw:WikiLink" href="Foo" title="Foo">foo</a> x'<i><a href="Bar" rel="mw:WikiLink" title="Bar">bar</a></i>
'<i>foo</i> <span class="mw-ref reference" id="cite_ref-1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="./Main_Page#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
'<i>foo</i> <div title="name">test</div>
'<i>foo</i> and <br data-parsoid='{"stx":"html","noClose":true}'/> bar
<ol class="mw-references 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="./Main_Page#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 '''{{1x|[[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>
!! 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>
!! end

!! test
4. No escaping needed
!! options
parsoid=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 ---------------
#### 1. No unnecessary escapes
#### --------------------------------------

!! 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>

=bar <span><nowiki>[[foo]]</nowiki></span>

[[bar <span><nowiki>[[foo]]</nowiki></span>

]]bar <span><nowiki>[[foo]]</nowiki></span>

=bar <span>foo]]</span><nowiki>=</nowiki>
!!end

#### ----------------------- PRE --------------------------
!! test
1. Leading whitespace in SOL context should be escaped
!! options
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

	a(tab)

<nowiki> </nowiki>	a
<!--cmt-->
<nowiki>  </nowiki>a

a
<nowiki> </nowiki>b

a
	b

a
	 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=html2wt
!! html/parsoid
<p>foo <span about="#mwt2" class="mw-ref 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="./Main_Page#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"><i>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=html2wt
!! html/parsoid
<blockquote>
<p>
 a
 <span>b</span>
 c</p>
</blockquote>
!! wikitext
<blockquote>
 a
 <span>b</span>
 c
</blockquote>
!! end

!! test
4. Leading whitespace in indent-pre suppressing contexts should not be escaped
!! options
parsoid=html2wt
!! html/parsoid
 <figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://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/parsoid
<pre>==foo==</pre>
!! wikitext
 ==foo==
!! end

!! test
T95794: nowiki escaping should account for leading space at start-of-line in an indent-pre block
!! options
parsoid=html2wt
!! html/parsoid
<pre>
* foo
* bar
</pre>
!! wikitext
 * foo
 * bar
!! end

!! test
Whitespace scrubbing in SOL position should account for SOL-sensitive wikitext markup
!! options
parsoid = {
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<p> foo</p>
<p> %foo</p>
<p> *foo</p>
<p> #foo</p>
<p> =foo=</p>
<p><link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid="{}"> *foo</p>
<p> <link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid="{}">*foo</p>
<p> <!--boo-->*foo</p>
<p><!--boo--> *foo</p>
<p><!--a--> <!--b--> <!--c--> <!--d--> <!--e--> foo</p>
<p><!--a--> <!--b--> <!--c--> <!--d--> <!--e--> *foo</p>
!! wikitext
foo

%foo

<nowiki/>*foo

<nowiki/>#foo

<nowiki/>=foo=

[[Category:Foo]]
<nowiki/>*foo

 [[Category:Foo]]
<nowiki>*</nowiki>foo

<nowiki/><!--boo-->*foo

<!--boo--><nowiki/>*foo

<!--a--><!--b--><!--c--><!--d--><!--e-->foo

<!--a--><nowiki/><!--b--><!--c--><!--d--><!--e-->*foo
!! end

#### --------------- Behavior Switches --------------------

!! test
1. Valid behavior switches should be escaped
!! options
parsoid=html2wt
!! html/parsoid
__TOC__
<i>__TOC__</i>
!! wikitext
<nowiki>__TOC__</nowiki>
''<nowiki>__TOC__</nowiki>''
!! end

!! test
2. Invalid behavior switches should not be escaped
!! options
parsoid=html2wt
!! html/parsoid
__TOO__
__|__
!! wikitext
__TOO__
__|__
!! end

# We use indent-pre as an indirect way to test for sol-transparent behavior.
!! test
Behavior switches should be SOL-transparent
!! options
parsoid=html2wt
!! html/parsoid
 <meta property="mw:PageProp/toc" />

 <!-- this one's bogus -->
<pre>__TOO__</pre>

<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

# last two <meta> tags test case-insensitivity
!! test
During serialization, escape output when given a SOL-transparent prefix
!! options
parsoid=html2wt
!! html/parsoid
<p> x</p>
<p><meta property="mw:PageProp/notoc" data-parsoid='{"src":"__NOTOC__","magicSrc":"__NOTOC__"}'/> y</p>
<p><meta property="mw:PageProp/notoc" data-parsoid='{"src":"__NotoC__","magicSrc":"__NotoC__"}'/> z</p>
<p><meta property="mw:PageProp/notoc" data-parsoid='{"src":"__notoc__","magicSrc":"__notoc__"}'/> p</p>
!! wikitext
<nowiki> </nowiki>x

__NOTOC__<nowiki> </nowiki>y

__NOTOC__<nowiki> </nowiki>z

__notoc__<nowiki> </nowiki>p
!! end

#### --------------- HTML tags ---------------
#### 1. a tags
#### 2. other tags
#### 3. multi-line html tag
#### 4. extension tags
#### -----------------------------------------
!! test
1. a tags
!! options
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>
!! end

!! test
2. other tags
!! 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
!! 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>
!! end

!! test
Parsoid: newline inducing block nodes don't suppress <nowiki>
!! options
parsoid=html2wt
!! html/parsoid
 a<h1>foo</h1>
!! wikitext
<nowiki> </nowiki>a

= foo =
!! end

#### --------------- Others ---------------
!! test
Escaping nowikis
!! 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
(T54035) Nowiki-escaping should not get tripped by " :" in text
!! options
parsoid=html2wt
!! html/parsoid
<p>foo's bar :</p>
!! wikitext
foo's bar :
!! end

#----------- End of wikitext escaping tests --------------

!! test

Tag-like HTML structures are passed through as text
!! wikitext
<x y>

<x.y>

<x-y>

1>2

x<y

a>b

1<d e>f
!! html
<p>&lt;x y&gt;
</p><p>&lt;x.y&gt;
</p><p>&lt;x-y&gt;
</p><p>1&gt;2
</p><p>x&lt;y
</p><p>a&gt;b
</p><p>1&lt;d e&gt;f
</p>
!! end

!! test
HTML tag with necessary entities in attributes
!! wikitext
<span title="&amp;amp;">foo</span>
!! html
<p><span title="&amp;amp;">foo</span>
</p>
!! end

!! test
HTML tag with 'unnecessary' entity encoding in attributes
!! wikitext
<span title="&amp;">foo</span>
!! html
<p><span title="&amp;">foo</span>
</p>
!! end

!! test
HTML tag with broken attribute value quoting
!! options
parsoid=wt2html,html2html
!! wikitext
<span title="Hello world>Foo</span>
!! html/php
<p><span title="Hello world">Foo</span>
</p>
!! html/parsoid
<p><span title="Hello world">Foo</span></p>
!! end

!! test
Self-closed tag with broken attribute value quoting
!! options
parsoid=wt2html,html2html
!! wikitext
<div title="Hello world />Foo
!! html+tidy
<div title="Hello world">Foo</div>
!! end

!! test
Table with broken attribute value quoting
!! options
parsoid=wt2html,html2html
!! wikitext
{|
| title="Hello world|Foo
|}
!! html/php
<table>
<tbody><tr>
<td title="Hello world">Foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tr>
<td title="Hello world">Foo
</td></tr></table>
!! end

!! test
Table with broken attribute value quoting on consecutive lines
!! options
parsoid=wt2html,html2html
!! wikitext
{|
| title="Hello world|Foo
| style="color:red|Bar
|}
!! html/php
<table>
<tbody><tr>
<td title="Hello world">Foo
</td>
<td style="color:red">Bar
</td></tr></tbody></table>
!! html/parsoid
<table><tbody>
<tr>
<td title="Hello world">Foo
</td><td style="color: red">Bar
</td></tr></tbody></table>
!! end

!!test
Accept empty td cell attribute
!! wikitext
{|
| align="center" |foo||  |
|}
!! html
<table>
<tbody><tr>
<td align="center">foo</td>
<td>
</td></tr></tbody></table>
!! end

!!test
Non-empty attributes in th-cells
!! wikitext
{|
!Foo!! style="color: red" |Bar
|}
!! html
<table>
<tbody><tr>
<th>Foo</th>
<th style="color: red">Bar
</th></tr></tbody></table>
!! end

!!test
Accept empty attributes in th-cells
!! wikitext
{|
!|foo!!|bar
|}
!! html
<table>
<tbody><tr>
<th>foo</th>
<th>bar
</th></tr></tbody></table>
!! end

!!test
Empty table rows go away
!! wikitext
{|
|Hello
|there
|- class="foo"
|-
|}
!! html
<table>
<tbody><tr>
<td>Hello
</td>
<td>there
</td></tr>

</tbody></table>
!! end

###
### Parsoid-centric tests for testing RTing of inter-element separators
### Edge cases not tested by existing parser tests and specific to
### Parsoid-specific serialization strategies.
###

!!test
RT-ed inter-element separators should be valid separators
!! wikitext
{|
|- [[foo]]
|}
!! html/php
<table>

</table>
!! html/parsoid
<table>
<tbody><tr class='mw-empty-elt' data-parsoid='{"startTagSrc":"|-","a":{"[[foo]]":null},"sa":{"[[foo]]":""}}'></tr>
</tbody></table>
!!end

# Parsoid-only test of a DOM pass
!!test
Trailing newlines in a deep dom-subtree that ends a wikitext line should be migrated out
!! wikitext
{|
|<small>foo
bar
|}

{|
|<small>foo<small>
|}
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{}'><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'>foo
<p>bar</p></small></td></tr>
</tbody></table>

<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{}'><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'>foo<small data-parsoid='{"stx":"html","autoInsertedEnd":true}'></small></small></td></tr>
</tbody></table>
!!end

# Note that the "style" attribute is really a template parameter here.
# The = would have to be {{=}} if you wanted the literal.
!!test
Empty TD followed by TD with tpl-generated attribute
!! wikitext
{|
|-
|
|{{1x|style='color:red'}}|foo
|}
!! html
<table>

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

!!test
Indented table with an empty td
!! wikitext
 {|
 |-
 |
 |foo
 |}
!! html
<table>

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

!! test
Indented table with blank lines in between (T85627)
!! wikitext
 {|
 |foo
 
 
 |}
!! html/php
<table>
<tbody><tr>
<td>foo
<p><br /> 
</p>
</td></tr></tbody></table>
!! html/parsoid
 <table>
 <tbody><tr><td>foo
 <p>
 <br /></p></td></tr>
 </tbody></table>
!! end

!!test
Indented block & table
!! wikitext
 <div>foo</div>
 {|
 |foo
 |}
!! html/php
 <div>foo</div>
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
 <div data-parsoid='{"stx":"html"}'>foo</div>
 <table><tbody>
 <tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{}'>foo</td></tr>
 </tbody></table>
!!end

!! test
Indent and comment before table row
!! wikitext
{|
 <!--hi-->|-
 |there
|}
!! html/php
<table>

<tbody><tr>
<td>there
</td></tr></tbody></table>
!! html/parsoid
<table>
 <!--hi--><tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
 <td data-parsoid='{}'> there</td></tr>
</tbody></table>
!! end

# PHP parser omits empty TR
!!test
Empty TR followed by a template-generated TR
!! wikitext
{|
|-
{{1x|<tr><td>foo</td></tr>}}
|}
!! html/php+tidy
<table>

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

## PHP and parsoid output differ for this; as usual PHP omits empty
## elements, and since it strips the comments the TR is empty.
!!test
Empty TR followed by mixed-ws-comment line should RT correctly
!! wikitext
{|
|-
 <!--c-->
|-
<!--c--> <!--d-->
|}
!! html/php+tidy
<table>


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

!!test
Multi-line image caption generated by templates with/without trailing newlines
!! wikitext
[[File:Foobar.jpg|thumb|300x300px|foo\n{{1x|A}}\n{{1x|B}}\n{{1x|C}}]]
[[File:Foobar.jpg|thumb|300x300px|foo\n{{1x|A}}\n{{1x|B}}\n{{1x|C}}\n\n]]
!! html/parsoid
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://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" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/450px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/600px-Foobar.jpg 2x"/></a><figcaption>foo\n<span about="#mwt9" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"A"}},"i":0}}]}'>A</span>\n<span about="#mwt10" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"B"}},"i":0}}]}'>B</span>\n<span about="#mwt11" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"C"}},"i":0}}]}'>C</span></figcaption></figure>
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://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" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/450px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/600px-Foobar.jpg 2x"/></a><figcaption>foo\n<span about="#mwt12" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"A"}},"i":0}}]}'>A</span>\n<span about="#mwt13" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"B"}},"i":0}}]}'>B</span>\n<span about="#mwt14" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"C"}},"i":0}}]}'>C</span>\n\n</figcaption></figure>
!! end

!! test
New element inserted (without intervening newlines) after an old sol-transparent node should serialize correctly
!! options
parsoid=html2wt
!! html/parsoid
<meta typeof="mw:Includes/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>foo&lt;/includeonly>"}' data-mw='{"src":"&lt;includeonly>foo&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><p>new para</p>

<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{}'/><h1>new heading</h1>
!! wikitext
<includeonly>foo</includeonly>
new para

[[Category:Foo]]

= new heading =
!! end

## PHP emits broken html for this, and since this is primarily
## a Parsoid serializer test, marking this Parsoid only
!!test
Improperly nested inline or quotes tags with whitespace in between
!! wikitext
<span> <s>x</span> </s>
''' ''x''' ''
!! html/parsoid
<p><span> <s>x</s></span><s> </s>
<b> <i>x</i></b><i> </i>
</p>
!!end

!!test
Encapsulate protected attributes from wt
!! wikitext
<div typeof="mw:placeholder stuff" data-mw="whoo" data-parsoid="weird" data-parsoid-other="no" about="time" rel="mw:true">foo</div>

{| typeof="mw:placeholder stuff" data-mw="whoo" data-parsoid="weird" data-parsoid-other="no" about="time" rel="mw:true"
|ok
|}
!! html/parsoid
<div data-x-typeof="mw:placeholder stuff" data-x-data-mw="whoo" data-x-data-parsoid="weird" data-x-data-parsoid-other="no" data-x-about="time" data-x-rel="mw:true">foo</div>

<table data-x-typeof="mw:placeholder stuff" data-x-data-mw="whoo" data-x-data-parsoid="weird" data-x-data-parsoid-other="no" data-x-about="time" data-x-rel="mw:true">
<tbody><tr><td data-parsoid='{}'>ok</td></tr>
</tbody></table>
!!end

## Currently the p-wrapper is fragile in how it adds / removes transformations.
## Having nested or stray pre tags results in the attempt to add duplicates,
## causing an assertion fail. This test tries to prevent that situation.
!! test
Ensure ParagraphWrapper can deal with stray closing pre tags
!! options
parsoid=wt2html
!! wikitext
plain text</pre>
!! html/parsoid
<p>plain text</p>
!! end

## Remex doesn't account for fostered content.
!! test
1. Ensure fostered text content is wrapped in element nodes
!! options
parsoid=wt2html
!! wikitext
<table>hi</table><table>ho</table>
!! html/php+tidy
hi<table></table>ho<table></table>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>hi</p><table data-parsoid='{"stx":"html"}'></table><p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>ho</p><table data-parsoid='{"stx":"html"}'></table>
!! end

## Remex doesn't account for fostered content.
!! test
2. Ensure fostered text content is wrapped in element nodes (traps regressions around fostered marker on the element getting lost)
!! options
parsoid=wt2html,wt2wt
!! wikitext
<table>
<tr> || ||
<td> a
</table>
!! html/php+tidy
 || ||
<table>
<tbody><tr><td> a
</td></tr></tbody></table>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'> || ||</p>
<table data-parsoid='{"stx":"html"}'>
<tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'> a
</td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
Encapsulation properly handles null DSR information from foster box
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{1x|<table>foo<tr><td>bar</td></tr></table>}}
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>foo&lt;tr>&lt;td>bar&lt;/td>&lt;/tr>&lt;/table>"}},"i":0}}]}'>foo</p><table about="#mwt1" data-parsoid='{"stx":"html"}'><tbody><tr><td>bar</td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
1. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{1x|foo<tr><td>bar</td></tr>}}</table>
!! html/php+tidy
foo<table><tbody><tr><td>bar</td></tr></tbody></table>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;tr>&lt;td>bar&lt;/td>&lt;/tr>"}},"i":0}},"&lt;/table>"]}'>foo</p><table about="#mwt2" data-parsoid='{"stx":"html"}'><tbody><tr><td>bar</td></tr></tbody></table>
!! end

!! test
2. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table><div>{{1x|foo}}</div><tr><td>bar</td></tr></table>
!! html/parsoid
<div typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><div>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo&quot;}},&quot;i&quot;:0}},&quot;</div><tr><td>bar</td></tr></table>&quot;]}">foo</div>
<table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

!! test
3. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table><div><p>{{1x|foo</p></div><tr><td>}}bar</td></tr></table>
!! html/parsoid
<div typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><div><p>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo</p></div><tr><td>&quot;}},&quot;i&quot;:0}},&quot;bar</td></tr></table>&quot;]}">
<p>foo</p>
</div>
<table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

!! test
4. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table><div><p>{{1x|foo</p></div><tr><td>}}bar</td></tr></table>
!! html/parsoid
<div typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><div><p>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo</p></div><tr><td>&quot;}},&quot;i&quot;:0}},&quot;bar</td></tr></table>&quot;]}">
<p>foo</p>
</div>
<table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

## Remex doesn't account for fostered content.
!! test
5. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table><tr><td><div><p>{{1x|foo</p></div></td>foo}}</tr></table>
!! html/php+tidy
foo<table><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;tr>&lt;td>&lt;div>&lt;p>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;/p>&lt;/div>&lt;/td>foo"}},"i":0}},"&lt;/tr>&lt;/table>"]}'>foo</p><table about="#mwt2" data-parsoid='{"stx":"html"}'><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
6. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table><tr><td><div><p>{{1x|foo</p></div></td>foo</tr></table>}}<p>ok</p>
!! html/php+tidy
foo<table><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table><p>ok</p>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;tr>&lt;td>&lt;div>&lt;p>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;/p>&lt;/div>&lt;/td>foo&lt;/tr>&lt;/table>"}},"i":0}}]}'>foo</p><table about="#mwt2" data-parsoid='{"stx":"html"}'><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table><p data-parsoid='{"stx":"html"}'>ok</p>
!! end

!! test
7. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{1x|<p>foo</p>}}<td>bar</td></table>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;<p>foo</p>&quot;}},&quot;i&quot;:0}},&quot;<td>bar</td></table>&quot;]}">foo</p>
<table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

## Remex doesn't account for fostered content.
# Note that the wt is broken on purpose: the = should be {{=}} if you
# don't want it to be a template parameter key.
!! test
8. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
{{1x|a
}}{|{{1x|style='color:red'}}
|-
|b
|}
!! html/php+tidy
<p>a
</p>
<table>

<tbody><tr>
<td>b
</td></tr></tbody></table>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\n"}},"i":0}}]}'>a</p><span about="#mwt1">
</span><p about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"style","named":true}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"style":{"wt":"&apos;color:red&apos;"}},"i":0}},"\n|-\n|b\n|}"]}'>{{{1}}}</p><table about="#mwt3">
<tbody><tr>
<td>b
</td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
9. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{1x|hi</table>hello}}
!! html/php+tidy
hi<table></table><p>hello</p>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;/table>hello"}},"i":0}}]}'>hi</p><table about="#mwt2"></table><p about="#mwt2">hello</p>
!! end

!! test
Table in fosterable position
!!options
parsoid=wt2html
!! wikitext
{{OpenTable}}
<div>
{|
|}
</div>
|}
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"OpenTable","href":"./Template:OpenTable"},"params":{},"i":0}},"\n&lt;div>\n"]}' data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[]]}'></div><span about="#mwt1">
</span>
<table about="#mwt1" data-parsoid='{"autoInsertedEnd":true}'></table>

<table>
</table>
!! end

# Parsoid only for T66747
# (Also core doesn't define {{#if}} in default install)
!! test
Properly encapsulate empty-content transclusions in fosterable positions
!! wikitext
<table>
{{#if:|
<td>foo</td>
}}
</table>
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["&lt;table>\n",{"template":{"target":{"wt":"#if:","function":"if"},"params":{"1":{"wt":"\n&lt;td>foo&lt;/td>\n"}},"i":0}},"\n&lt;/table>"]}' data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}'>

</table>
!! end

## No longer captures its original intention
!! test
Always encapsulate foster box when template range is expanded to table
!! options
disabled
parsoid=wt2wt
!! wikitext
{|
hello
{{OpenTable}}
|}
!! html/parsoid
!! end

!! test
T115289: Unclosed table
!! wikitext
{{1x|<table>}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Two" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:Two"},"sa":{"href":"Category:Two"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'/><table about="#mwt1" data-parsoid='{"stx":"html","autoInsertedEnd":true}'><!--c--></table>
!! end

!! test
T115289: Don't migrate newlines out of tables with fostered content
!! wikitext
<table><td></td>{{1x|<tr>[[Category:One]]}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:One" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:One"},"sa":{"href":"Category:One"},"fostered":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;td>&lt;/td>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tr>[[Category:One]]"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'/><link rel="mw:PageProp/Category" href="./Category:Two" about="#mwt2"/><table about="#mwt2" data-parsoid='{"stx":"html","autoInsertedEnd":true}'><tbody><tr><td></td></tr><tr><!--c--></tr></tbody></table>
!! end

!! test
T73074: More fostering fun
!! wikitext
<table><td></td>{{1x|<tr>}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Two" data-parsoid='{"stx":"simple","a":{"href":"./Category:Two"},"sa":{"href":"Category:Two"},"fostered":true}'/><table data-parsoid='{"stx":"html","autoInsertedEnd":true}'><tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{"stx":"html"}'></td></tr><tr about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"autoInsertedEnd":true,"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tr>"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'><!--c--></tr></tbody></table>
!! end

!!test
Support <object> element with .data attribute
!!options
parsoid=html2wt
!! html/parsoid
<object data="test.swf"></object>
!! wikitext
<object data="test.swf"></object>
!!end

!! test
T72867: Don't block XML namespace declaration
!! wikitext
<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">MediaWiki</span>
!! html/php
<p><span xmlns:dct="http&#58;//purl.org/dc/terms/" property="dct:title">MediaWiki</span>
</p>
!! html/parsoid
<p><span xmlns:dct="http://purl.org/dc/terms/" data-x-property="dct:title" data-parsoid='{"stx":"html"}'>MediaWiki</span></p>
!! end

# -----------------------------------------------------------------
# The following section of tests are primarily to spec requirements
# around Parsoid's serialization (old, new, edited content)
#
# All these tests are marked Parsoid html2wt and html2html only
# ----------------------------------------------------------------

!! test
Ignore rel attribute in a-tags during serialization to url-links
!! options
parsoid=html2wt
!! html/parsoid
<a href='http://en.wikipedia.org/wiki/Foobar'>http://en.wikipedia.org/wiki/Foobar</a>
<a href='http://en.wikipedia.org/wiki/Foobar' rel='mw:ExtLink'>http://en.wikipedia.org/wiki/Foobar</a>
<a href='http://en.wikipedia.org/wiki/Foobar' rel='mw:WikiLink'>http://en.wikipedia.org/wiki/Foobar</a>
!! wikitext
http://en.wikipedia.org/wiki/Foobar
http://en.wikipedia.org/wiki/Foobar
http://en.wikipedia.org/wiki/Foobar
!! end

# 'mi' is a localinterwiki prefix as well as a language
!! test
Serialize interwiki links pointing to the current wiki as plain wiki links (T67869)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://mi.wikipedia.org/wiki/Foo">Foo</a></p>
!! wikitext
[[Foo]]
!! end

!! test
Parsoid should accept interwiki shortcuts
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel='mw:WikiLink' href='./fr:Foo'>Foo</a>
<a rel='mw:ExtLink' href='./fr:Foo'>Foo</a>
<a href='./fr:Foo'>Foo</a></p>
<p><a rel='mw:WikiLink' href='fr%3AFoo'>Foo</a>
<a rel='mw:ExtLink' href='fr%3AFoo'>Foo</a>
<a href='fr%3AFoo'>Foo</a></p>
<p><a href='FR%3AFoo'>Foo</a>
<a href='./FR:Foo'>Foo</a></p>
!! wikitext
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]

[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]

[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
!! end

!! test
Parsoid should not accept invalid interwiki shortcuts
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel='mw:WikiLink' href='news:Foo'>Foo</a>
<a rel='mw:ExtLink' href='news:Foo'>Foo</a>
<a href='news:Foo'>Foo</a></p>
!! wikitext
[news:Foo Foo]
[news:Foo Foo]
[news:Foo Foo]
!! end

# See T93839
!! test
New wikilinks should be serialized properly
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{}'>Foo</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a>
<a href="//en.wikipedia.org/wiki/Foo">//en.wikipedia.org/wiki/Foo</a>
<a href="http://en.wikipedia.org/wiki/Foo">http://en.wikipedia.org/wiki/Foo</a>
<a href="//en.wikipedia.org/wiki/Foo_bar">//en.wikipedia.org/wiki/Foo bar</a>
!! wikitext
[[Foo]]
[[Foo]]
[[:en:Foo|//en.wikipedia.org/wiki/Foo]]
http://en.wikipedia.org/wiki/Foo
[[:en:Foo_bar|//en.wikipedia.org/wiki/Foo bar]]
!! end

!! test
New wiki links (href variations)
!! options
parsoid=html2wt
!! 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>
<a rel="mw:WikiLink" href="./Toxine_bact%C3%A9rienne">Toxine bactérienne</a>
!! wikitext
[[Foo_bar]]
[[Foo_bar]]
[[Foo_bar]]
[[Toxine bactérienne]]
!! end

!! test
New wiki links (content string variations)
!! options
parsoid=html2wt
!! 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>
!! wikitext
[[Foo_bar]]
[[Foo bar]]
[[Foo_bar|./Foo_bar]]
!! end

!! test
New category links (href variations)
!! options
parsoid=html2wt
!! 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" />
!! wikitext
[[Category:Toxine bactérienne]]
[[Category:Toxine bactérienne]]
[[Category:Toxine bactérienne]]
!! end

!! test
New sol transparent links don't need indent-pre nowiki protection
!! options
parsoid=html2wt
language=de
!! 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" />
!! wikitext
         #WEITERLEITUNG [[Main Page]]
<!-- this is good  -->    [[Category:Good]]
<!-- this is great -->    [[Kategorie:Great]]
!! end

!! test
New interlanguage links (href variations)
!! options
parsoid=html2wt
!! 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" />
!! wikitext
[[es:Toxine bactérienne]]
[[es:Toxine_bactérienne]]
[[es:Toxine_bactérienne]]
!! end

# Regression test for T219023
!! test
Emit simple non-piped link where possible
!! options
parsoid=html2wt
!! html/parsoid
<a rel='mw:WikiLink' href='./VisualEditor'>VisualEditor</a>
<a rel='mw:WikiLink' href='./VisualEditor'>visualEditor</a>
<a rel='mw:WikiLink' href='./VisualEditor link'>VisualEditor link</a>
<a rel='mw:WikiLink' href='./VisualEditor link'>visualEditor link</a>
!! wikitext
[[VisualEditor]]
[[visualEditor]]
[[VisualEditor link]]
[[visualEditor link]]
!! end

!! test
Lists: Serialize correctly even when list content is wrapped in p-tags (like VE does)
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li><p>foo</p></li>
</ul>
!! wikitext
* foo
!! end

!! test
Lists: Serialize correctly even when list tags has unneeded whitespace between tags
!! options
parsoid=html2wt
!! html/parsoid
<ul> <li>foo</li></ul>
!! wikitext
* foo
!! end

!! test
Don't strip leading whitespace when handling indent-pre suppressing tags
!! options
parsoid=html2wt
!! html/parsoid
<table>
  <tr><td> indented row</td></tr>
</table>
<blockquote><p>
 <b>This is very bold of you!</b>
</p>
<table><tr><td>
 indented cell (no pre-wrapping!)
</td></tr></table>
</blockquote>
<p>foo</p>
 <div>bar</div>
!! wikitext
{|
  | indented row
|}
<blockquote>
 '''This is very bold of you!'''

{|
|
 indented cell (no pre-wrapping!)
|}
</blockquote>
foo
 <div>bar</div>
!! end

!! test
Nowiki-wrap leading whitespace when handling indent-pre inducing tags
!! options
parsoid=html2wt
!! html/parsoid
<p>foo</p>
 <span>bar</span>

<span>foo2
 </span>bar2

<div>foo</div>
 <span>bar</span>

<div>
 <span>foo</span>
</div>
!! wikitext
foo
 
<span>bar</span>

<span>foo2
<nowiki> </nowiki></span>bar2

<div>foo</div>
<nowiki> </nowiki><span>bar</span>

<div>
<nowiki> </nowiki><span>foo</span>
</div>
!! end

!! test
Lists: Dont insert newlines in a serialized list item.
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>a<br>b</li><li>c</li></ul>
!! wikitext
* a<br />b
* c
!! end

!! test
1. Headings: Force sol-transparent links and behavior switches to serialize before/after
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! 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 data-parsoid='{}'>howdy<link href="./Category:A5" rel="mw:PageProp/Category" /></h2>

<h2><meta property="mw:PageProp/toc" /> ok</h2>
!! wikitext
== hello there [[Category:A1]] ==

== [[Category:A2]] hi pal ==

== <!--foo-->  [[Category:A3]]    how goes it ==

== it goes well    [[Category:A4]]  <!--bar--> ==

==howdy [[Category:A5]]==

==  __TOC__  ok ==
!! end

!! test
2. Headings: Force sol-transparent links and behavior switches to serialize before/after
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! 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><meta property="mw:PageProp/toc" /> ok</h2>
!! wikitext
== hello there ==
[[Category:A1]]
[[Category:A2]]

== hi pal ==

<!--foo-->[[Category:A3]]

== how goes it ==

== it goes well ==
[[Category:A4]]  <!--bar-->

__TOC__

== ok ==
!! end

!! test
Headings: Don't hoist metas that come from templates
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2><span about="#mwt1" typeof="mw:Transclusion" data-parsoid="{}" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo [[Category:Foo]]"}},"i":0}}]}'>foo </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" data-parsoid="{}" /></h2>
!! wikitext
== {{1x|foo [[Category:Foo]]}} ==
!! end

!! test
Headings: Category in ref isn't hoisted
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2> foo <span about="#mwt2" class="mw-ref 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="./Main_Page#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="./Main_Page#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
== foo <ref>bar 
[[Category:Baz]] </ref> ==

<references />
!! end

!! test
Parsoid: Serialize positional parameters with = in them as named parameter
!! options
parsoid=html2wt
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"}},"i":0}}]}'>foo</p>

<p about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"}, "2":{"wt":"bar"}},"i":0}}]}'>foo</p>

<!--Orig params with data-parsoid has heuristics for handling = chars-->
<!--FIXME: But maybe the heuristic needs fixing to apply to new params as well-->
<p data-parsoid='{"pi":[[{"k":"1"},{"k":"2"}]]}' about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"},"2":{"wt":"bar"}},"i":0}}]}'>foo</p>
!! wikitext
{{1x|1=f=oo}}

{{1x|1=f=oo|2=bar}}

<!--Orig params with data-parsoid has heuristics for handling = chars-->
<!--FIXME: But maybe the heuristic needs fixing to apply to new params as well-->
{{1x|<nowiki>f=oo</nowiki>|bar}}
!! end

!! test
Parsoid: Serialize positional parameters with = in extlink as named parameter
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://stuff?is=ok" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"http://stuff?is=ok"}},"i":0}}]}'>http://stuff?is=ok</a></p>
!! wikitext
{{1x|1=http://stuff?is=ok}}
!! end

!! test
Parsoid: Correctly serialize block-node children when they are a combination of text and p-nodes
!! options
parsoid=html2wt
!! html/parsoid
<div>a<p>b</p></div>
<div>a
<p>b</p></div>
<div>
a
<p>b</p></div>
!! wikitext
<div>a
b
</div>
<div>a
b
</div>
<div>
a

b
</div>
!! end

!! test
Substrings resembling wikitext in hrefs should not get nowiki escapes
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo''bar''baz">Foo''bar''baz</a>
!! wikitext
[[Foo''bar''baz]]
!! end

!! test
Enforce single-line context in the serializer
!! options
parsoid=html2wt
!! 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="mw-ref 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="./Main_Page#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="./Main_Page#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">hello
there</span></li></ol>

<ul><li>asd
sdf</li></ul>

<ul><li>foo
bar
baz</li>
<li>foo <b>bar</b>
baz</li></ul>

<dl><dt>hi
ho </dt><dd data-parsoid='{"stx":"row"}'> hi
ho</dd></dl>

<dl><dd> <table>
<tbody><tr><td> ha
ha
ha</td></tr>
</tbody></table></dd></dl>
!! wikitext
== testing 123 ==

== hi {{bogus|there
you}} ==

== foo <ref>hello
there</ref> ==

<references />

* asd sdf

* foo bar baz
* foo '''bar''' baz

; hi ho : hi ho

: {|
| ha
ha
ha
|}
!! end

# Note that core parser doesn't like newlines in wikilinks in headings.
# But, Parsoid handles it just fine. We'll consider this acceptable divergence.
# We can change behavior if this becomes a real problem (ex: VE users start
# adding newlines in links in headings which then breaks rendering when rendered
# outside of Parsoid, or breaks section editing code). Eventually Parsoid will
# core parser everywhere and this inconsistency will go away.
!! test
Ignore single-line context for wikilinks
!! options
parsoid=html2wt
!! html/parsoid
<ul><li><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">
bar</a></li></ul>
<h2><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">
bar</a></h2>
<ul><li><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">bar
<span style="background-color:green;
color:blue" data-parsoid='{"stx":"html"}'>x</span></a></li></ul>
!! wikitext
* [[Foo|
bar]]

== [[Foo|
bar]] ==

* [[Foo|bar
<span style="background-color:green;
color:blue">x</span>]]
!! end

!! test
Selser: Ignore single-line context for wikilinks
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
     [ "ul > li ", "append", "<ul><li>foo</li></ul>" ]
  ]
}
!! wikitext
* [[Foo|
bar]]
!! wikitext/edited
* [[Foo|
bar]]
** foo
!! end

!! test
Serialize new displayspace spans
!! options
parsoid=html2wt
!! html/parsoid
<p>foo<span typeof="mw:DisplaySpace"> </span>: bar</p>

<p>foo<span typeof="mw:DisplaySpace"> </span>: bar</p>

<span typeof="mw:Extension/ref" data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;body&quot;:{&quot;html&quot;:&quot;foo<span typeof=\&quot;mw:DisplaySpace\&quot;>&amp;nbsp;</span>: bar&quot;}}"><sup>[1]</sup></span>ok</p>

<a href="http://example.com">«<span typeof="mw:DisplaySpace">&nsbp;</span>Tour Eiffel<span typeof="mw:DisplaySpace">&nsbp;</span>»</a>

Hello<span typeof="mw:DisplaySpace">&nbsp;</span>World!

<ul>
<li><span typeof="mw:DisplaySpace">&nbsp;</span>Foo</li>
</ul>
!! wikitext
foo : bar

foo : bar

<ref>foo : bar</ref>ok

[http://example.com « Tour Eiffel »]

Hello World!

*  Foo
!! end


#-----------------------
# Tag minimization tests
#-----------------------

!! test
1. I/B quote minimization: wikitext-only tags should be combined
!! options
parsoid=html2wt
!! 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>
<p><b>A</b><i><b>B</b></i></p>
<p><b>A</b><i><b>B</b><b>C</b></i><b>D</b></p>
<p><i><b>A</b></i><i><b>B</b></i></p>
<p><i><b>A</b></i><b><i>B</i></b></p>
<p><b><i>A</i></b><i><b>B</b></i></p>
!! wikitext
''AB''

'''AB'''

''A'''B'''''

'''A''B'''''

'''A''BC''D'''

'''''AB'''''

'''''AB'''''

'''''AB'''''
!! end

!! test
2. I/B quote minimization: wikitext and html tags should not be combined
!! options
parsoid=html2wt
!! 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
''A''<i>B</i>

''A''<nowiki/>'''<i>B</i>'''
!! end

!! test
3. I/B quote minimization: templated content stops minimization
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"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":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&#39;&#39;&#39;&#39;&#39;B&#39;&#39;&#39;&#39;&#39;"}},"i":0}}]}'><i>B</i></b>
!! wikitext
''A''{{1x|''B''}}

''A''{{1x|'''''B'''''}}
!! end

!! test
4. I/B quote minimization: new content should be mimimized with adjacent old content
!! options
parsoid=html2wt
!! 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>
!! wikitext
''AB''

'''AB'''

''A'''B'''''
!! end

!! test
5a. Merge adjacent quote nodes if they've been edited
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["p", "contents", "remove", ":contains('b')"]
  ]
}
!! wikitext
''a''b''c''
!! wikitext/edited
''ac''
!! end

!! test
5b. Merge adjacent quote nodes if they've been edited
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["#x", "remove"]
  ]
}
!! wikitext
''a''<span id="x">b</span>''c''
!! wikitext/edited
''ac''
!! end

!! test
1. Merge adjacent link nodes as long as at least one element is new
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! 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>
!! wikitext
[[Football]]
[[Football]]
[[Football|Foot]][[Football|ball]]
!! end

!! test
2. Merge adjacent link nodes and enable additional normalizations
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i>Foot</i></a><a rel="mw:WikiLink" href="./Football"><i>ball</i></a>
!! wikitext
''[[Football]]''
!! end

!! test
3. Don't merge adjacent link nodes if scrubWikitext is false
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football">Foot</a><a rel="mw:WikiLink" href="./Football">ball</a>
!! wikitext
[[Football|Foot]][[Football|ball]]
!! end

!! test
1. Move format tags outside of WikiLink
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i>Football</i></a>
<a rel="mw:WikiLink" href="./Football"><i><b>Football</b></i></a>
<a rel="mw:WikiLink" href="./Football"><u><i><b>Football</b></i></u></a>
!! wikitext
''[[Football]]''
'''''[[Football]]'''''
<u>'''''[[Football]]'''''</u>
!! end

!! test
2. Move format tags outside of WikiLink with mergable A tags
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i><b>Foot</b></i></a><a rel="mw:WikiLink" href="./Football"><i><b>ball</b></i></a>
!! wikitext
'''''[[Football]]'''''
!! end

!! test
3. Move format tags outside of WikiLink while preserving formats already outside WikiLink
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<font color="red"><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><u><b>Foo</b></u></a></font>
!! wikitext
<font color="red"><u>'''[[Foo]]'''</u></font>
!! end

!! test
4. Do not move format tags outside of WikiLink which includes attributes color, style and class
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><font color="red">Foo</font></a>
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><span style="color: blue; font-size: 46px;">Foo></span></a>
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><span class="Bar">Foo</span></a>
!! wikitext
[[Foo|<font color="red">Foo</font>]]
[[Foo|<span style="color: blue; font-size: 46px;">Foo></span>]]
[[Foo|<span class="Bar">Foo</span>]]
!! end

!! test
5. T194083 Regression test: Manual edit test that also enables scrubWikitext to move format tags outside wikilinks
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    ["a", "html", "<i>Foo</i>"]
  ]
}
!! wikitext
[[Foo]]
!! wikitext/edited
''[[Foo]]''
!! end

!! test
6. Regression test: Manual edit test to ensure diff markers are not lost
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    ["i", "wrap", "<a href='./Foo' rel='mw:WikiLink'></a>"]
  ]
}
!! wikitext
''Foo''
!! wikitext/edited
''[[Foo]]''
!! end

!! test
7. T194083 Regression test: Manual edit test to ensure nested diff markers aren't inserted
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    ["div", "after", "\n<p><a href='./Foo' rel='mw:WikiLink'>Foo </a>, placeholder</p>"]
  ]
}
!! wikitext
<div>placeholder</div>
!! wikitext/edited
<div>placeholder</div>
[[Foo]] , placeholder
!! end

## No sort-key or templated sort-key
!! test
T192913 Regression test: 1. html2wt of links should not trip on parser functions found in target
!! options
parsoid
!! wikitext
[[Category:Bugs-{{#if:blah|Regression|None}}]]
[[Category:Bugs-{{#if:blah|Regression|None}}|{{#if:blah|2020|None}}-#fragment]]
!! html/parsoid
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}]]}'/>
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression#2020-%23fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}],[{"txt":"mw:sortKey"},{"html":"&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"2020\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>2020&lt;/span>-#fragment"}]]}'/>
!! end

## Untemplated sort-key (wt2html data-mw is missing sort-key information!)
!! test
T192913 Regression test: 2. html2wt of links should not trip on parser functions found in target (2)
!! options
parsoid
!! wikitext
[[Category:Bugs-{{#if:blah|Regression|None}}|fragment]]
[[Category:Bugs-{{#if:blah|Regression|None}}-{{#if:blah|2020|None}}|fragment]]
!! html/parsoid
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression#fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}]]}'/>
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression-2020#fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"2020\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>2020&lt;/span>"}]]}'/>
!! end

#------------------------------
# End of tag minimization tests
#------------------------------

!!test
T56262: New entities
!! options
parsoid=html2wt
!! html/parsoid
<span typeof="mw:Entity">&nbsp;</span>
!! wikitext
&nbsp;
!! end

## Note that there is no wikitext output for 'unknownproperty' ##
## Unknown magic words are silently dropped ##

!! test
Magic words
!! options
parsoid=html2wt
!! html/parsoid
<meta property='mw:PageProp/toc' />
<meta property='mw:PageProp/notoc' />
<meta property='mw:PageProp/forcetoc' />
<meta property='mw:PageProp/index' />
<meta property='mw:PageProp/noindex' />
<meta property='mw:PageProp/nogallery' />
<meta property='mw:PageProp/noeditsection' />
<meta property='mw:PageProp/notitleconvert' />
<meta property='mw:PageProp/nocontentconvert' />
<meta property='mw:PageProp/unknownproperty' />
!! wikitext
__TOC__
__NOTOC__
__FORCETOC__
__INDEX__
__NOINDEX__
__NOGALLERY__
__NOEDITSECTION__
__NOTITLECONVERT__
__NOCONTENTCONVERT__
!! end

!! test
Consecutive <pre>s should not get merged
!! options
parsoid=html2wt,html2html
!! html/parsoid
<pre>a</pre><pre>b</pre>

<pre>c
</pre><pre>
d</pre>

<pre>e

</pre><pre>

f</pre>
!! wikitext
 a

 b

 c

 d

 e
 

 
 f
!! end

!! test
Edited ISBN links not serializable as ISBN links should serialize as wikilinks
!! options
parsoid=html2wt
!! html/parsoid
<a href="./Special:BookSources/1234567890" rel="mw:ExtLink">ISBN 1234567895</a>
!! wikitext
[[Special:BookSources/1234567890|ISBN 1234567895]]
!! end

!! test
Edited RFC links not serializable as RFC links should serialize as extlinks
!! options
parsoid=html2wt
!! html/parsoid
<a href="https://tools.ietf.org/html/rfc123" rel="mw:ExtLink">New RFC</a>
!! wikitext
[https://tools.ietf.org/html/rfc123 New RFC]
!! end

!! test
Edited PMID links not serializable as PMID links should serialize as extlinks
!! options
parsoid=html2wt
!! 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]
!! end

!! test
WTS of autolinks with trailing/surrounding context
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="http://cscott.net">http://cscott.net</a><b>foo</b></p>
<p><a href="http://cscott.net">http://cscott.net</a><b data-parsoid='{"stx":"html"}'>foo</b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a></b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a> </b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a>x</b></p>
<p><a href="http://cscott.net">http://cscott.net</a>x</p>
!! wikitext
http://cscott.net'''foo'''

http://cscott.net<b>foo</b>

'''http://cscott.net'''

'''http://cscott.net '''

'''http://cscott.net<nowiki/>x'''

http://cscott.net<nowiki/>x
!! end

!! test
WTS of autolinks with nowikis (round-trip)
!! wikitext
x<nowiki/>http://cscott.net<nowiki/>x
!! html/parsoid
<p>x<a rel="mw:ExtLink" href="http://cscott.net" class="external free">http://cscott.net</a>x</p>
!! end

# this is the "easy" test because it leaves in place all the
# data-parsoid information indicating this is an autolink
!! test
WTS of autolinks with escapes (editing)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "span", "remove" ]
  ]
}
!! wikitext
x<nowiki/>http://cscott.net<nowiki/>x
!! wikitext/edited
x<nowiki/>http://cscott.net<nowiki/>x
!! end

!! test
WTS of edited autolink-like text (T103364)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "span[typeof]", "removeAttr", "typeof" ]
  ]
}
!! wikitext
Not a link: <nowiki>http://example.com</nowiki>.
!! wikitext/edited
Not a link: <span><nowiki>http://example.com</nowiki></span>.
!! end

!! test
WTS of newly-authored autolink-like text (T103364)
!! options
parsoid=html2wt
!! html/parsoid
<p>http://example.com is not a link.</p>
!! wikitext
<nowiki>http://example.com</nowiki> is not a link.
!! 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</nowiki> is not a link.
!! end

!! test
WTS of an autolink surrounded by square brackets (T220018)
!! options
parsoid=html2wt
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>]</p>
!! wikitext
<nowiki>[</nowiki>http://example.com]
!! end

!! test
WTS of edited autolink surrounded by square brackets (T220018)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "a", "before", "[" ],
    [ "a", "after", "]" ]
  ]
}
!! wikitext
http://example.com
!! wikitext/edited
<nowiki>[</nowiki>http://example.com]
!! end

!! test
WTS of an external link surrounded by square brackets (T220018)
!! options
parsoid=html2wt
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="http://example.com">foo</a>]</p>
!! wikitext
<nowiki>[</nowiki>[http://example.com foo]]
!! end

!! test
WTS of edited external link surrounded by square brackets (T220018)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "a", "before", "[" ],
    [ "a", "after", "]" ]
  ]
}
!! wikitext
[http://example.com foo]
!! wikitext/edited
<nowiki>[</nowiki>[http://example.com foo]]
!! 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" class="external text">http://example.com</a>
<a rel="mw:ExtLink" href="http://foo.com" class="external text">RFC 1234</a>
<a rel="mw:ExtLink" href="http://foo.com" class="external text">PMID 1234</a>
<a rel="mw:ExtLink" href="http://foo.com" class="external text">ISBN 123456789x</a></p>
!! 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/parsoid
<link rel="mw:PageProp/redirect" href="Bar" data-parsoid='{"a":{"href":"./Foo"},"sa":{"href":"Foo"}}'>
!! wikitext
#REDIRECT [[Bar]]
!! end

!! test
T75121: Infer extension name from typeOf if data-mw is not present
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<div typeOf="mw:Extension/foo"></div>
!! wikitext
<foo />
!! end

# Note that the <p> wrapping isn't present in PHP parser output
# The important thing for this test is that P-wrapping doesn't
# interfere with the <nowiki> protection for leading - in <td>
# (which isn't necessary for <th>).
!! test
T88318: p-wrapped dash in table.
!! options
parsoid=html2wt,wt2wt
!! html/parsoid
<table><tbody>
<tr><th><p>-</p></th><th><p>- </p></th></tr>
<tr><td><p>-</p></td><td><p>- </p></td></tr>
<tr><td><small>-</small></td><td><br/><p>-</p></td><td><br/>-</td></tr>
</tbody></table>
!! wikitext
{|
!-
!- 
|-
|<nowiki>-</nowiki>
|<nowiki>- </nowiki>
|-
|<small>-</small>
|<br />
-
|<br />-
|}
!! html/php+tidy
<table>
<tbody><tr>
<th>-
</th>
<th>-
</th></tr>
<tr>
<td>-
</td>
<td>- 
</td></tr>
<tr>
<td><small>-</small>
</td>
<td><br />
<p>-
</p>
</td>
<td><br />-
</td></tr></tbody></table>
!! end

!! test
T149209: WTS: Handle newlines in table cells properly
!! options
parsoid=html2wt
!! html/parsoid
<table>
<tbody>
<tr><td>a
b
</td><td data-parsoid='{"stx":"row"}'>c</td></tr>
<tr><td><p>x</p>
</td><td data-parsoid='{"stx":"row", "startTagSrc": "{{!}}{{!}}"}'>y</td></tr>
</tbody></table>
<table>
<tbody>
<tr><th>a
b
</th><th data-parsoid='{"stx":"row"}'>c</th></tr>
<tr><th><p>x</h>
</th><th data-parsoid='{"stx":"row"}'>y</th></tr>
</tbody></table>
!! wikitext
{|
|a
b
|c
|-
|x
{{!}}y
|}
{|
!a
b
!c
|-
!x
!y
|}
!! end

!! test
T149209: Selser: Handle newlines in table cells properly
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#h1", "html", "a\nb\n" ],
    [ "#h2", "html", "a\nb\n" ],
    [ "#c1", "html", "a\nb\n" ],
    [ "#c2", "html", "<p>a</p>" ],
    [ "#c3", "html", "<p>a</p>" ],
    [ "#c4", "html", "edit-me<p>a</p>" ]
  ]
}
!! wikitext
{|
! id="h1" |edit-me!!1
|-
! id="h2" |edit-me||2
|-
| id="c1" |edit-me||3
|-
| id="c2" |edit-me||4
|-
| id="c3" |edit-me||p||q||r
|-
| id="c4" |edit-me||p||q||r
|}
!! wikitext/edited
{|
! id="h1" |a
b
!1
|-
! id="h2" |a
b
!2
|-
| id="c1" |a
b
|3
|-
| id="c2" |a
|4
|-
| id="c3" |a
|p||q||r
|-
| id="c4" |edit-me
a
|p||q||r
|}
!! end

!! test
HTML id attribute with Parsoid-like element ids should not be serialized to wikitext
!! options
parsoid=html2wt
!! html/parsoid
<table id='mwAb'>
<td id='mwAc'>foo</td>
<td id='serialize-this'>bar</td>
</table>
!! wikitext
{|
|foo
| id="serialize-this" |bar
|}
!! end

!! test
Parsoid-like element ids should not be serialized to wikitext unless shadowed
!! options
parsoid=html2wt
!! html/parsoid
<div id="mwAQ" data-parsoid='{"stx":"html","a":{"id":"mwAQ"},"sa":{"id":"hello"}}'>ok</div>
!! wikitext
<div id="hello">ok</div>
!! end

!! test
Testing serialization after deletion in references
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["#x", "remove"]
  ]
}
!! wikitext
hi <ref><div id="x">ho</div></ref>

<references />
!! wikitext/edited
hi <ref></ref>

<references />
!! end

!!test
Testing serialization after deletion of table cells
!!options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["#x", "remove"]
  ]
}
!!wikitext
{|
!h1 !!h2 !!h3
| id="x" |c1 {{!}}{{!}}{{!}}c2 |||c3
|}
!! wikitext/edited
{|
!h1!!h2!!h3
|c2|||c3
|}
!!end

!! test
Testing selser after addition of new row before first row (T125419)
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    [ "tr", "before", "<tr><td>X</td></tr>" ]
  ]
}
!! wikitext
{|
|a
|}
!! wikitext/edited
{|
|X
|-
|a
|}
!! end

!! test
Serialize new table rows in a HTML table using HTML tags
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    [ "tr", "before", "<tr><td>X</td></tr>" ]
  ]
}
!! wikitext
<table><tr><td>a</td></tr></table>
!! wikitext/edited
<table><tr><td>X</td></tr><tr><td>a</td></tr></table>
!! end

!! test
Serialize new table cells in a HTML row using HTML tags
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    [ "td", "before", "<td>X</td>" ]
  ]
}
!! wikitext
<table><tr><td>a</td></tr></table>
!! wikitext/edited
<table><tr><td>X</td><td>a</td></tr></table>
!! end

!! test
Serialize wikitext list items as HTML list items when embedded in a HTML list
!! options
parsoid=html2wt
!! html/parsoid
<ul data-parsoid='{"stx": "html"}'>
<li data-parsoid='{}'>a</li>
<li>b</li>
</ul>
!! wikitext
<ul>
<li>a</li>
<li>b</li>
</ul>
!! html/php+tidy
<ul>
<li>a</li>
<li>b</li>
</ul>
!! end

# Nested list should be inside <li>, that is
# <ul><li>foo<ul>..</ul></li></ul> instead of
# <ul><li>foo</li><ul>..</ul></ul>
# See https://stackoverflow.com/questions/5899337/proper-way-to-make-html-nested-list
!! test
Wikitext lists can be nested inside HTML lists
!! options
parsoid=html2wt
!! html/parsoid
<ul data-parsoid='{"stx": "html"}'>
<li data-parsoid='{"stx": "html"}'>a
<ul><li>b</li></ul>
</li>
</ul>

<ul data-parsoid='{"stx": "html"}'>
<li>x
<ul><li>y</li></ul>
</li>
</ul>
!! wikitext
<ul>
<li>a
* b
</li>
</ul>

<ul>
<li>x
* y
</li>
</ul>
!! html/php+tidy
<ul>
<li>a
<ul><li>b</li></ul>
</li>
</ul>
<ul>
<li>x
<ul><li>y</li></ul>
</li>
</ul>
!! end

!! test
WTS change modes
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "#xyz", "before", "<b>before</b> stuff " ],
    [ "#xyz", "after", " stuff <i>after</i>" ],
    [ "#xyz", "html", "x <b>y</b> z" ]
  ]
}
!! wikitext
<span id="xyz">hello</span>
!! wikitext/edited
'''before''' stuff <span id="xyz">x '''y''' z</span> stuff ''after''
!! end

!! test
Never serialize a-tag as html, regardless of what data-parsoid has to say
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"html"}'>Foo</a>
!! wikitext
[[Foo]]
!! end

## SSS FIXME: This is broken output nevertheless.
## What might be a reasonable non-broken output for this?
## This is an edge case unlikely to be seen in production
## that I am not wasting more time on this right now.
!! test
Never serialize a-tag as html, no matter what attributes it has
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! 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 misnested links
!! 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

!! test
Catch regression when unpacking misnested links
!! options
parsoid=wt2html
!! wikitext
{{1x|hi}}[http://example.com [[ho]]]
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi"}},"i":0}}]}'>hi</span><a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a><a rel="mw:WikiLink" href="./Ho" title="Ho" data-parsoid='{"misnested":true}' class="new">ho</a></p>
!! end

!! test
Catch regression when unpacking with trailing content
!! wikitext
{{1x|Foo <references/> bar}}
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Foo &lt;references/> bar"}},"i":0}}]}'>Foo </p><ol class="mw-references references" typeof="mw:Extension/references" about="#mwt2" data-mw='{"name":"references","attrs":{}}'></ol><p about="#mwt2"> bar</p>
!! end

!! test
Use data-parsoid.firstWikitextNode to compute newline constraints for template content
!! options
parsoid=html2wt
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span><table about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"a":{"{{1x|c\n{{!}}d\n}}":null},"sa":{"{{1x|c\n{{!}}d\n}}":""},"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"c\n{{!}}d\n"}},"i":0}},"\n|}"]}'>
<tbody><tr><td>d
</td></tr>
</tbody></table>
!! wikitext
{{1x|a}}
{|{{1x|c
{{!}}d
}}
|}
!! end

## This test verifies the presence and computation of this attribute indirectly
## by making an edit and ensuring that the serialization is correct (which it would be
## only if firstWikitextNode is properly set).
!! test
data-parsoid.firstWikitextNode should be computed properly in the presence of fostered content
!! options
parsoid= {
  "modes": ["wt2wt"],
  "changes": [
    [ "div#x", "remove" ],
    [ "div", "before", "<div>new</div>" ]
  ]
}
!! wikitext
<div id="x">foo</div>
{|
{{1x|<div>boo</div>
{{!}}b}}
|c
|}
!! wikitext/edited

<div>new</div>
{|
{{1x|<div>boo</div>
{{!}}b}}
|c
|}
!! end

# --------------------------------------------
# Tests spec'ing wikitext serialization norms |
# --------------------------------------------

!! test
Serialize multi-line indent-pre starting with wikitext syntax
!! options
parsoid=html2wt
!! html/parsoid
<pre>* 1
** 2
* 3</pre>
!! wikitext
 * 1
 ** 2
 * 3
!! end

!! test
1. Categories should always be serialized on their own line
!! options
parsoid=html2wt
!! html/parsoid
foo<link rel="mw:PageProp/Category" href="./Category:Foo">bar
!! wikitext
foo
[[Category:Foo]]
bar
!! end

!! test
2. Categories that are part of templates should not introduce a line break
!! wikitext
foo {{1x|<span>bar</span> [[Category:baz]]}} bar
!! html/parsoid
<p>foo <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;span>bar&lt;/span> [[Category:baz]]"}},"i":0}}]}'>bar</span><span about="#mwt1"> </span><link rel="mw:PageProp/Category" href="./Category:Baz" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:baz"}}'/> bar</p>
!! end

# Careful while editing these next 2 tests. There are \u200f characters
# before and after the <link> tags in the HTML and following some
# of the categories in wikitext
# Do not remove these characters in edits.
#
# As part of the serialization, these bidi characters will get stripped.
!! test
RTL (\u200f) and LTR (\u200e) markers around category tags should be stripped
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<p>‏<link rel="mw:PageProp/Category" href="./קטגוריה:טקסים" />‏
‏<link rel="mw:PageProp/Category" href="./קטגוריה:_שיטות_משפט" />‏</p>
!! wikitext
[[קטגוריה:טקסים]]
[[קטגוריה: שיטות משפט]]
!! end

!! test
RTL (\u200f) and LTR (\u200e) markers should not be stripped if followed by a text node
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<p>‏<link rel="mw:PageProp/Category" href="./קטגוריה:טקסים" />‏y</p>
!! wikitext
[[קטגוריה:טקסים]]
‏y
!! end

!! test
Lists: Add space after bullets
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>foo</li>
<li> bar</li>
<li><span> baz</span></li>
</ul>
!! wikitext
* foo
* bar
* <span> baz</span>
!! end

!! test
1. Headings: Add space before/after == (T53744)
!! options
parsoid=html2wt
!! html/parsoid
<h2>foo</h2>
<h2> bar</h2>
<h2>baz </h2>
<h2><span> baz</span></h2>
!! wikitext
== foo ==

== bar ==

== baz ==

== <span> baz</span> ==
!! end

!! test
2. Headings: Add space before/after == even after hoisted content
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2> <link href="./Category:A2" rel="mw:PageProp/Category" />ok</h2>
!! wikitext
[[Category:A2]]

== ok ==
!! end

!! test
1. Headings: suppress newly created empty headings
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2></h2>
!! wikitext
!! end

!! test
2. Headings: don't suppress empty headings if scrubWikitext is false
!! options
parsoid=html2wt
!! html/parsoid
<h2></h2>
!! wikitext
==<nowiki/>==
!! end

!! test
3. Headings: suppress empty headings on edits
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
==<span id="x">foo</span>==
!! wikitext/edited
!! end

!! test
Headings: Replace <br/> with a single whitespace char (when scrubWikitext = true)
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2>foo<br/>bar</h2>
<h2>foo <span><br/>bar</span> baz</h2>
!! wikitext
== foo bar ==

== foo <span> bar</span> baz ==
!! end

!! test
Headings: Replace <br/> with a single whitespace char (when scrubWikitext = false)
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! html/parsoid
<h2>foo<br/>bar</h2>
!! wikitext
== foo<br />bar ==
!! end

!! test
1. WT Quote Tags: suppress newly created empty style tags
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<i></i><b></b>
!! wikitext
!! end

!! test
2. WT Quote Tags: don't suppress empty style tags if scrubWikitext is false
!! options
parsoid=html2wt
!! html/parsoid
<i></i><b></b>
!! wikitext
''<nowiki/>'''''<nowiki/>'''
!! end

!! test
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/parsoid
<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> bar<b></b></p>"]
  ]
}
!! wikitext
<div id="x">foo</div>
!! wikitext/edited
<div id="x">foo</div>
bar
!! 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
hi

hello
!! end

!! test
2. Indent Pre Nowiki: don't suppress whitespace at the start of new paragraph if scrubWikitext is false
!! options
parsoid=html2wt
!! html/parsoid
<p> hi</p>
<p>    hello</p>
!! wikitext
<nowiki> </nowiki>hi

<nowiki> </nowiki>   hello
!! end

!! test
3. Indent Pre Nowiki: suppress whitespace after newlines in new paragraph or table cell
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<p>Foo
 bar
baz</p>

<table><tr><td>Foo
 bar
 baz bang</td></tr></table>

<p><!--boo--> foo
 bar</p>

<p> foo
 bar<span>boo</span></p>
!! wikitext
Foo
bar
baz

{|
|Foo
bar
baz bang
|}

<!--boo-->foo
bar

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
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! 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
2. New links that end in spaces
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! 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/parsoid
<table>
<tr><td>a</td></tr>
<tr><td>-</td></tr>
<tr><td>+</td></tr>
<tr><td>}</td></tr>
</table>
!! wikitext
{|
|a
|-
|<nowiki>-</nowiki>
|-
|<nowiki>+</nowiki>
|-
|<nowiki>}</nowiki>
|}
!! end

!! test
2. Table cells with escapable prefixes
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<table>
<tr><td>a</td></tr>
<tr><td>-</td></tr>
<tr><td>+</td></tr>
<tr><td>}</td></tr>
</table>
!! wikitext
{|
|a
|-
| -
|-
| +
|-
| }
|}
!! end

!! 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
{|
|a||-
|}
!! wikitext/edited
{|
| -
|}
!! end

!! 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

## T111151 Remove font elements without attributes
!! test
5a. font tags without attributes should be dropped in scrubWikitext mode
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<font>foo</font>
<font><font>bar</font></font>
<font class="x">boo</font>
!! wikitext
foo
bar
<font class="x">boo</font>
!! end

!! test
5b. font tags should not be dropped without scrubWikitext being enabled
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! html/parsoid
<font>foo</font>
!! wikitext
<font>foo</font>
!! end

!! test
Ignore empty <p></p> when scrubWikitext is false
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! html/parsoid
<div>1</div>
<p>a</p><p></p><p>b</p>
<div>2</div>
<p>a</p>
<p></p>
<p>b</p>
<div>3</div>
<p>a</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p>b</p>
!! wikitext
<div>1</div>
a

b
<div>2</div>
a

b
<div>3</div>
a

b
!! html/php+tidy
<div>1</div>
<p>a
</p><p>b
</p>
<div>2</div>
<p>a
</p><p>b
</p>
<div>3</div>
<p>a
</p><p>b
</p>
!! end

!! test
Normalize empty paragraphs to HTML form that html2wt expects
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<div>1</div>
<p>a</p><p></p><p>b</p>
<div>2</div>
<p>a</p>
<p></p>
<p>b</p>
<div>3</div>
<p>a</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p>b</p>
<div>4</div>
<p>a</p>
<p></p>
<div>foo</div>
!! wikitext
<div>1</div>
a


b
<div>2</div>
a


b
<div>3</div>
a





b
<div>4</div>
a

<div>foo</div>
!! html/php+tidy
<div>1</div>
<p>a
</p><p><br />
b
</p>
<div>2</div>
<p>a
</p><p><br />
b
</p>
<div>3</div>
<p>a
</p><p><br />
</p><p><br />
</p><p>b
</p>
<div>4</div>
<p>a
</p>
<div>foo</div>
!! end

!! test
Templated content should be skipped over by normalization
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SomeTemplate1","href":"./Template:SomeTemplate1"},"params":{"1":{"wt":"boo"}},"i":0}}]}'>foobar</p><p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SomeTemplate2","href":"./Template:SomeTemplate2"},"params":{"1":{"wt":"booboo"}},"i":0}}]}'>foobar</p><span about="#mwt2">
</span><p about="#mwt2"></p><span about="#mwt2">
</span>
!! wikitext
{{SomeTemplate1|boo}}{{SomeTemplate2|booboo}}
!! 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

# This is meant to be an interim fix while we go about figuring out
# how to not introduce these trailing <nowiki/>s in the first place.
!! test
T115717: Strip trailing <nowiki/>s (without affecting valid uses)
!! options
parsoid=html2wt
!! html/parsoid
<p>x<meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/>
y</p>
<p><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":"&lt;nowiki/>"}},"i":0}}]}'></span></p>
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n"," "," ","\n"]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;nowiki/>"}},"i":0}}]}'></span></p>
!! wikitext
x
y

{{1x|
1 = <nowiki/>}}

{{1x|
1 = <nowiki/>
}}
!! end

!! test
New list is serialized on newlines
!! options
parsoid=html2wt
!! html/parsoid
<p>The quick brown fox jumps over the lazy dog.</p><ul>
<li>Yesterday</li>
<li>Today</li>
<li>Tomorrow</li>
</ul><p>The quick onyx goblin jumps over the lazy dwarf.</p>
!! wikitext
The quick brown fox jumps over the lazy dog.

* Yesterday
* Today
* Tomorrow

The quick onyx goblin jumps over the lazy dwarf.
!! end

!! test
New lists in formatting elements serialized w/o newlines
!! options
parsoid=html2wt
!! html/parsoid
<small>

<ul>
<li>123</li>
</ul>

</small>

<small><ul><li>hi</li></ul></small>
!! wikitext
<small>
* 123
</small>

<small>
* hi
</small>
!! end

!! test
New list in table doesn't need newlines
!! options
parsoid=html2wt
!! html/parsoid
<table><tr><td><ul><li>test</li><li>123</li></td></tr></table>
!! wikitext
{|
|
* test
* 123
|}
!! end

!! test
Newly inserted noinclude tags do not need newlines before/after
!! html/parsoid
<p>a<meta typeof="mw:Includes/NoInclude">b<meta typeof="mw:Includes/NoInclude/End">c</p>
!! wikitext
a<noinclude>b</noinclude>c
!! end

# ---------------------------------------------------
# End of tests spec'ing wikitext serialization norms |
# ---------------------------------------------------

# T104032
!! test
Bare inline nodes not wrapped inside p-tags should be treated as p-wrapped
!! options
parsoid=html2wt
!! html/parsoid
a<p>b</p>
<b>c</b><p>d</p>
<table><tr>
<td>a<p>b</p></td>
<td><b>c</b><p>d</p></td>
</tr></table>
!! wikitext
a

b

'''c'''

d
{|
|a
b
|'''c'''
d
|}
!! end

!! test
Anchor without href scenarios
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a class="bc"></a>
<a class="no">dice</a>
<a name="foo"></a>
!! wikitext

dice
<span name="foo"></span>
!! end

!! test
New transclusion added after a list should be serialized after the list
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>a</li></ul><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>
!! wikitext
* a
{{1x|foo}}
!! end

!! test
Only html p-tag is strong indent pre suppressing
!! options
parsoid=html2wt
!! html/parsoid
<p>test2<span>
 test3
</span></p>
!! wikitext
test2<span>
<nowiki> </nowiki>test3
</span>
!! end

# Clients like VE don't know about this property (T238721)
!! test
T238721: New transclusion without the "i" property for a template part should be handled properly
!! options
parsoid=html2wt
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}}}}]}'>foo</span>
!! wikitext
{{1x|foo}}
!! end

# -----------------------------------------------------------------
# End of section for Parsoid-only html2wt tests for serialization
# of new content
# -----------------------------------------------------------------

# -----------------------------------------------------------------
# The following section of tests are primarily to spec behavior of
# the selective serializer. All these tests have manual selser
# changes. The automated selser changes for all tests handle the
# wide variation of changes, but these tests here capture specs
# deterministically.
# ----------------------------------------------------------------

## T90517
!! test
Selser: New comments should not be lost
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#a", "after", "<!--c1-->" ],
    [ "#b", "before", "<!--c2-->" ]
  ]
}
!! wikitext
<span id="a">a</span>

<span id="b">b</span>
!! wikitext/edited
<span id="a">a</span><!--c1-->

<!--c2--><span id="b">b</span>
!! end

## T89383
!! test
Selser: Check for validity of DSR before using it
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#a", "before", "<meta property='mw:PageProp/displaytitle' content='foo'>" ]
  ]
}
!! wikitext
<span id="a">a</span>
!! wikitext/edited
{{DISPLAYTITLE:foo}}
<span id="a">a</span>
!! end

!! test
1. DOMDiff: Changes to <ref> content should be looked up using id
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["#X", "after", "bar"],
    ["#Y", "after", "baz"]
  ]
}
!! wikitext
X <ref><span id="X">foo</span></ref>
Y <ref name="a" />
<references>
<ref name="a"><span id="Y">foo</span></ref>
</references>
!! wikitext/edited
X <ref><span id="X">foo</span>bar</ref>
Y <ref name="a" />
<references>
<ref name="a"><span id="Y">foo</span>baz</ref>
</references>
!! end

!! test
2. DOMDiff: Changes to <ref> content should be looked up using id
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["#Z", "after", "bar"]
  ]
}
!! wikitext
A <ref>foo bar for a</ref>
B <ref group="X" name="b" />

<references />

<references group="X">
<ref name="b"><span id="Z">foo</span></ref>
</references>
!! wikitext/edited
A <ref>foo bar for a</ref>
B <ref group="X" name="b" />

<references />

<references group="X">
<ref name="b"><span id="Z">foo</span>bar</ref>
</references>
!! end

!! test
DOMDiff: Edits to content nested in elements with templated attributes should not be lost (T139388)
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "div:first-child", "text", "bar" ]
  ]
}
!! wikitext
<div style="{{1x|color:red;}}%">foo</div>
!! wikitext/edited
<div style="{{1x|color:red;}}%">bar</div>
!! end

!! test
Empty LI (T49673)
!! wikitext
*a
* 
*
*b
!! html+tidy
<ul><li>a</li>
<li class="mw-empty-elt"></li>
<li class="mw-empty-elt"></li>
<li>b</li></ul>
!! end

!! test
unclosed internal link XSS (T137264)
!! wikitext
[[#%3Cscript%3Ealert(1)%3C/script%3E|
!! html/php
<p>[[#&lt;script&gt;alert(1)&lt;/script&gt;|
</p>
!! html/parsoid
<p>[[#%3Cscript%3Ealert(1)%3C/script%3E|</p>
!! end

!! test
Validating that <style> isn't eaten by tidy (T167349)
!! options
styletag=1
!! wikitext
<div class="foo">
<style>.foo::before { content: "<foo>"; }</style>
<style data-mw-foobar="baz">.foo::after { content: "<bar>"; }</style>
</div>
!! html/php+tidy
<div class="foo">
<style>.foo::before { content: "<foo>"; }</style>
<style data-mw-foobar="baz">.foo::after { content: "<bar>"; }</style>
</div>
!! html/parsoid
<div class="foo">
<style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style>
<style data-x-data-mw-foobar="baz" typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{"data-x-data-mw-foobar":"baz"},"body":{"extsrc":".foo::after { content: \"&lt;bar>\"; }"}}'>.foo::after { content: "<bar>"; }</style>
</div>
!! end

## Right now, Parsoid doesn't de-duplicate style tags.
## So, we shouldn't see link tags that need to bypass the sanitizer.
## In a followup patch, when we de-duplicate style tags and
## introduce link tags, we'll add a hook for link tags in
## the parser test runner script.
!! test
Validating that <style> isn't wrapped in a paragraph (T186965)
!! options
styletag=1
!! wikitext
A style tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph

<style>.foo::before { content: "<foo>"; }</style>

<style>.foo::before { content: "<foo>"; }</style> <link rel="foo" href="bar"/><style>.foo::before { content: "<foo>"; }</style>

But if it's on a line with other content, let it be wrapped.

<style>.foo::before { content: "<foo>"; }</style> bar

foo <style>.foo::before { content: "<foo>"; }</style>

foo <style>.foo::before { content: "<foo>"; }</style> bar

And the same if we have non-paragraph-breaking whitespace

foo
<style>.foo::before { content: "<foo>"; }</style>
bar
!! html/php
<p>A style tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph
</p>
<style>.foo::before { content: "<foo>"; }</style>
<style>.foo::before { content: "<foo>"; }</style> <link rel="foo" href="bar" /><style>.foo::before { content: "<foo>"; }</style>
<p>But if it's on a line with other content, let it be wrapped.
</p><p><style>.foo::before { content: "<foo>"; }</style> bar
</p><p>foo <style>.foo::before { content: "<foo>"; }</style>
</p><p>foo <style>.foo::before { content: "<foo>"; }</style> bar
</p><p>And the same if we have non-paragraph-breaking whitespace
</p><p>foo
<style>.foo::before { content: "<foo>"; }</style>
bar
</p>
!! html/parsoid
<p>A style tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph</p>

<style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style>

<p><style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style> &lt;link rel="foo" href="bar"/><style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style></p>

<p>But if it's on a line with other content, let it be wrapped.</p>

<p><style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style> bar</p>

<p>foo <style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style></p>

<p>foo <style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style> bar</p>

<p>And the same if we have non-paragraph-breaking whitespace</p>

<p>foo
<style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style>
bar</p>
!! end

!! test
Validating that <link> isn't wrapped in a paragraph (T186965)
!! options
styletag=1
!! wikitext
A link tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph

<link rel="foo" href="bar"/>

<link rel="foo" href="bar"/> <style>.foo::before { content: "<foo>"; }</style><link rel="foo" href="bar"/>

But if it's on a line with other content, let it be wrapped.

<link rel="foo" href="bar"/> bar

foo <link rel="foo" href="bar"/>

foo <link rel="foo" href="bar"/> bar

And the same if we have non-paragraph-breaking whitespace

foo
<link rel="foo" href="bar"/>
bar
!! html/php
<p>A link tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph
</p>
<link rel="foo" href="bar" />
<link rel="foo" href="bar" /> <style>.foo::before { content: "<foo>"; }</style><link rel="foo" href="bar" />
<p>But if it's on a line with other content, let it be wrapped.
</p><p><link rel="foo" href="bar" /> bar
</p><p>foo <link rel="foo" href="bar" />
</p><p>foo <link rel="foo" href="bar" /> bar
</p><p>And the same if we have non-paragraph-breaking whitespace
</p><p>foo
<link rel="foo" href="bar" />
bar
</p>
!! end

!! test
Extension returning multiple nodes starting with a style tag roundtrips
!! options
wgRawHtml=1
!! wikitext
<table>
{{1x|<html><style>.hi { color: red; }</style>
</html>}}
<tr><td class="hi">ho</td></tr>
</table>
!! html/parsoid
<p about="#mwt5" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;html>&lt;style>.hi { color: red; }&lt;/style>\n&lt;/html>"}},"i":0}},"\n&lt;tr>&lt;td class=\"hi\">ho&lt;/td>&lt;/tr>\n&lt;/table>"]}'><style typeof="mw:Extension/html" about="#mwt4" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;style>.hi { color: red; }&lt;/style>\n"}}'>.hi { color: red; }</style><span about="#mwt4">
</span></p><table about="#mwt5" data-parsoid='{"stx":"html"}'>

<tbody><tr><td class="hi">ho</td></tr>
</tbody></table>
!! end

!! test
Decoding of HTML entities in headings and links for IDs and link fragments (T103714)
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
==A&B&amp;C&amp;amp;D&amp;amp;amp;E==
[[#A&B&amp;C&amp;amp;D&amp;amp;amp;E]]
!! html/php
<h2><span id="A.26B.26C.26amp.3BD.26amp.3Bamp.3BE"></span><span class="mw-headline" id="A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E">A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</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: A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p><a href="#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E">#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</a>
</p>
!! html/parsoid
<h2 id="A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E"><span id="A.26B.26C.26amp.3BD.26amp.3Bamp.3BE" typeof="mw:FallbackId" data-parsoid="{}"></span>A&amp;B<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>C<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>amp;D<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>amp;amp;E</h2>
<p><a rel="mw:WikiLink" href="./Parser_test#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E"},"sa":{"href":"#A&amp;B&amp;amp;C&amp;amp;amp;D&amp;amp;amp;amp;E"}}'>#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</a></p>
!! end

!! test
Decoding of HTML entities in headings and links for IDs and link fragments (T103714) (legacy)
!! config
wgFragmentMode=[ 'legacy' ]
!! wikitext
==A&B&amp;C&amp;amp;D&amp;amp;amp;E==
[[#A&B&amp;C&amp;amp;D&amp;amp;amp;E]]
!! html/php
<h2><span class="mw-headline" id="A.26B.26C.26amp.3BD.26amp.3Bamp.3BE">A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</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: A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p><a href="#A.26B.26C.26amp.3BD.26amp.3Bamp.3BE">#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</a>
</p>
!! end

!! test
Decoding of HTML entities in embedded HTML tags
!! wikitext
<table class="1&2&amp;3&amp;amp;4&amp;amp;amp;5"><tr><td>x</td></tr></table>
!! html/php
<table class="1&amp;2&amp;3&amp;amp;4&amp;amp;amp;5"><tbody><tr><td>x</td></tr></tbody></table>
!! html/parsoid
<table class="1&amp;2&amp;3&amp;amp;4&amp;amp;amp;5" data-parsoid='{"stx":"html","a":{"class":"1&amp;2&amp;3&amp;amp;4&amp;amp;amp;5"},"sa":{"class":"1&amp;2&amp;amp;3&amp;amp;amp;4&amp;amp;amp;amp;5"}}'><tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'>x</td></tr></tbody></table>
!! end

!! test
Decoding of HTML entities in indicator names for IDs (T104196)
!! options
parsoid=wt2html,html2html
showindicators
!! wikitext
<indicator name="1&2&amp;3&amp;amp;4&amp;amp;amp;5">Indicator</indicator>
!! html/php
1&2&3&amp;4&amp;amp;5=Indicator

!! html/parsoid
<p><span typeof="mw:Extension/indicator" about="#mwt3" data-mw='{"name":"indicator","attrs":{"name":"1&amp;2&amp;3&amp;amp;4&amp;amp;amp;5"},"body":{"extsrc":"Indicator"}}'></span></p>
!! end

# this version of the test strips out the ambiguity so Parsoid rts cleanly
!! test
Decoding of HTML entities in indicator names for IDs (unambiguous) (T104196)
!! options
showindicators
!! wikitext
<indicator name="1&2&3&amp;amp;4&amp;amp;amp;5">Indicator</indicator>
!! html/php
1&2&3&amp;4&amp;amp;5=Indicator

!! html/parsoid
<p><span typeof="mw:Extension/indicator" about="#mwt3" data-mw='{"name":"indicator","attrs":{"name":"1&amp;2&amp;3&amp;amp;4&amp;amp;amp;5"},"body":{"extsrc":"Indicator"}}'></span></p>
!! end

# This fragment mode is what Parsoid supports.
!! test
HTML5 ids: fallback to legacy
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
==Foo bar==

==foo Bar==

==Тест==

==Тест==

==тест==

==Hey < # " > % : '==
[[#Foo bar]] [[#foo Bar]] [[#Тест]] [[#тест]] [[#Hey < # " > % : ']]

{{anchorencode:💩}} <span id="{{anchorencode:💩}}"></span>

<!-- These two links should produce identical HTML -->
[[#啤酒]] [[#%E5%95%A4%E9%85%92]]

!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Тест"><span class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Тест_2"><span class="tocnumber">4</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#тест"><span class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="#Hey_&lt;_#_&quot;_&gt;_%_:_&#39;"><span class="tocnumber">6</span> <span class="toctext">Hey &lt; # " &gt;&#160;%&#160;: '</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Foo_bar">Foo bar</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: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="foo_Bar_2">foo Bar</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id=".D0.A2.D0.B5.D1.81.D1.82"></span><span class="mw-headline" id="Тест">Тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id=".D0.A2.D0.B5.D1.81.D1.82_2"></span><span class="mw-headline" id="Тест_2">Тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id=".D1.82.D0.B5.D1.81.D1.82"></span><span class="mw-headline" id="тест">тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id="Hey_.3C_.23_.22_.3E_.25_:_.27"></span><span class="mw-headline" id="Hey_&lt;_#_&quot;_&gt;_%_:_'">Hey &lt; # " &gt;&#160;%&#160;: '</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Hey &lt; # &quot; &gt; % : &#039;">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a href="#Тест">#Тест</a> <a href="#тест">#тест</a> <a href="#Hey_&lt;_#_&quot;_&gt;_%_:_&#39;">#Hey &lt; # " &gt;&#160;%&#160;: '</a>
</p><p>💩 <span id="💩"></span>
</p><p><a href="#啤酒">#啤酒</a> <a href="#啤酒">#啤酒</a>
</p>
!! html/parsoid
<h2 id="Foo_bar">Foo bar</h2>

<h2 id="foo_Bar_2">foo Bar</h2>

<h2 id="Тест"><span id=".D0.A2.D0.B5.D1.81.D1.82" typeof="mw:FallbackId"></span>Тест</h2>

<h2 id="Тест_2"><span id=".D0.A2.D0.B5.D1.81.D1.82_2" typeof="mw:FallbackId"></span>Тест</h2>

<h2 id="тест"><span id=".D1.82.D0.B5.D1.81.D1.82" typeof="mw:FallbackId"></span>тест</h2>

<h2 id="Hey_&lt;_#_&quot;_>_%_:_'"><span id="Hey_.3C_.23_.22_.3E_.25_:_.27" typeof="mw:FallbackId"></span>Hey &lt; # " ><span typeof="mw:DisplaySpace"> </span>%<span typeof="mw:DisplaySpace"> </span>: '</h2>
<p><a rel="mw:WikiLink" href="./Parser_test#Foo_bar">#Foo bar</a> <a rel="mw:WikiLink" href="./Parser_test#foo_Bar">#foo Bar</a> <a rel="mw:WikiLink" href="./Parser_test#Тест">#Тест</a> <a rel="mw:WikiLink" href="./Parser_test#тест">#тест</a> <a rel="mw:WikiLink" href="./Parser_test#Hey_&lt;_#_&quot;_>_%_:_'" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Hey_&lt;_#_\"_>_%_:_&apos;"},"sa":{"href":"#Hey &lt; # \" > % : &apos;"}}'>#Hey &lt; # " ><span typeof="mw:DisplaySpace"> </span>%<span typeof="mw:DisplaySpace"> </span>: '</a></p>

<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode:💩","function":"anchorencode"},"params":{},"i":0}}]}'>💩</span> <span id="💩" about="#mwt3" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"id"},{"html":"&lt;span about=\"#mwt2\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[178,197,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"anchorencode:💩\",\"function\":\"anchorencode\"},\"params\":{},\"i\":0}}]}&#39;>💩&lt;/span>"}]]}'></span></p>

<!-- These two links should produce identical HTML -->
<p><a rel="mw:WikiLink" href="./Parser_test#啤酒">#啤酒</a> <a rel="mw:WikiLink" href="./Parser_test#啤酒" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#啤酒"},"sa":{"href":"#%E5%95%A4%E9%85%92"}}'>#啤酒</a></p>
!! end

# Parsoid doesn't support this mode
!! test
HTML5 ids: legacy with a fallback to modern
!! config
wgFragmentMode=[ 'legacy', 'html5' ]
!! wikitext
==Foo bar==

==foo Bar==

==Тест==

==Тест==

==тест==

==Hey < # " > % : '==
[[#Foo bar]] [[#foo Bar]] [[#Тест]] [[#тест]] [[#Hey < # " > % : ']]

{{anchorencode:💩}} <span id="{{anchorencode:💩}}"></span>

<!-- These two links should produce identical HTML -->
[[#啤酒]] [[#%E5%95%A4%E9%85%92]]

!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#.D0.A2.D0.B5.D1.81.D1.82"><span class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#.D0.A2.D0.B5.D1.81.D1.82_2"><span class="tocnumber">4</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#.D1.82.D0.B5.D1.81.D1.82"><span class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="#Hey_.3C_.23_.22_.3E_.25_:_.27"><span class="tocnumber">6</span> <span class="toctext">Hey &lt; # " &gt;&#160;%&#160;: '</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Foo_bar">Foo bar</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: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="foo_Bar_2">foo Bar</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id="Тест"></span><span class="mw-headline" id=".D0.A2.D0.B5.D1.81.D1.82">Тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id="Тест_2"></span><span class="mw-headline" id=".D0.A2.D0.B5.D1.81.D1.82_2">Тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id="тест"></span><span class="mw-headline" id=".D1.82.D0.B5.D1.81.D1.82">тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span id="Hey_&lt;_#_&quot;_&gt;_%_:_'"></span><span class="mw-headline" id="Hey_.3C_.23_.22_.3E_.25_:_.27">Hey &lt; # " &gt;&#160;%&#160;: '</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Hey &lt; # &quot; &gt; % : &#039;">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a href="#.D0.A2.D0.B5.D1.81.D1.82">#Тест</a> <a href="#.D1.82.D0.B5.D1.81.D1.82">#тест</a> <a href="#Hey_.3C_.23_.22_.3E_.25_:_.27">#Hey &lt; # " &gt;&#160;%&#160;: '</a>
</p><p>.F0.9F.92.A9 <span id=".F0.9F.92.A9"></span>
</p><p><a href="#.E5.95.A4.E9.85.92">#啤酒</a> <a href="#.E5.95.A4.E9.85.92">#啤酒</a>
</p>
!! end

# Parsoid doesn't support this mode.
!! test
HTML5 ids: no legacy
!! config
wgFragmentMode=[ 'html5' ]
!! wikitext
==Foo bar==

==foo Bar==

==Тест==

==Тест==

==тест==

==Hey < # " > % : '==
[[#Foo bar]] [[#foo Bar]] [[#Тест]] [[#тест]] [[#Hey < # " > % : ']]

{{anchorencode:💩}} <span id="{{anchorencode:💩}}"></span>

<!-- These two links should produce identical HTML -->
[[#啤酒]] [[#%E5%95%A4%E9%85%92]]

!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Тест"><span class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Тест_2"><span class="tocnumber">4</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#тест"><span class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="#Hey_&lt;_#_&quot;_&gt;_%_:_&#39;"><span class="tocnumber">6</span> <span class="toctext">Hey &lt; # " &gt;&#160;%&#160;: '</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Foo_bar">Foo bar</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: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="foo_Bar_2">foo Bar</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Тест">Тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Тест_2">Тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="тест">тест</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: тест">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Hey_&lt;_#_&quot;_&gt;_%_:_'">Hey &lt; # " &gt;&#160;%&#160;: '</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Hey &lt; # &quot; &gt; % : &#039;">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a href="#Тест">#Тест</a> <a href="#тест">#тест</a> <a href="#Hey_&lt;_#_&quot;_&gt;_%_:_&#39;">#Hey &lt; # " &gt;&#160;%&#160;: '</a>
</p><p>💩 <span id="💩"></span>
</p><p><a href="#啤酒">#啤酒</a> <a href="#啤酒">#啤酒</a>
</p>
!! end

!! test
T90902: Normalize weird characters in section IDs
!! config
wgFragmentMode=[ 'html5', 'legacy' ]
!! wikitext
==Foo&nbsp;bar==
[[#Foo&nbsp;bar]]

!! html/php
<h2><span class="mw-headline" id="Foo_bar">Foo&#160;bar</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: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p><a href="#Foo_bar">#Foo&#160;bar</a>
</p>
!! html/parsoid
<h2 id="Foo_bar"> Foo<span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>bar </h2>
<p><a rel="mw:WikiLink" href="./Parser_test#Foo_bar" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Foo_bar"},"sa":{"href":"#Foo&amp;nbsp;bar"}}'>#Foo bar</a></p>
!! end

!! test
T51672: Test for brackets in attributes of elements in external link texts
!! wikitext
[http://example.com/ link <span title="title with [brackets]">span</span>]
[http://example.com/ link <span title="title with &#91;brackets&#93;">span</span>]

!! html/php
<p><a rel="nofollow" class="external text" href="http://example.com/">link <span title="title with &#91;brackets&#93;">span</span></a>
<a rel="nofollow" class="external text" href="http://example.com/">link <span title="title with &#91;brackets&#93;">span</span></a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/" class="external text">link <span title="title with [brackets]">span</span></a>
<a rel="mw:ExtLink" href="http://example.com/" class="external text">link <span title="title with [brackets]" data-parsoid='{"stx":"html","a":{"title":"title with [brackets]"},"sa":{"title":"title with &amp;#91;brackets&amp;#93;"}}'>span</span></a></p>
!! end

!! test
T72875: Test for brackets in attributes of elements in internal link texts
!! wikitext
[[Foo|link <span title="title with [[double brackets]]">span</span>]]
[[Foo|link <span title="title with &#91;&#91;double brackets&#93;&#93;">span</span>]]

!! html/php
<p><a href="/wiki/Foo" title="Foo">link <span title="title with &#91;&#91;double brackets&#93;&#93;">span</span></a>
<a href="/wiki/Foo" title="Foo">link <span title="title with &#91;&#91;double brackets&#93;&#93;">span</span></a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo" title="Foo">link <span title="title with [[double brackets]]">span</span></a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">link <span title="title with [[double brackets]]" data-parsoid='{"stx":"html","a":{"title":"title with [[double brackets]]"},"sa":{"title":"title with &amp;#91;&amp;#91;double brackets&amp;#93;&amp;#93;"}}'>span</span></a></p>
!! end

!! test
T199926: html arrow wt: Parsoid sometimes trips up on verticalbar chars in hrefs
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a href="https://stats.wikimedia.org/v2/#/fr.wikipedia.org/reading/page-views-by-country/normal|map|2-Year~2016060100~2018071100|~total">9</a>
<a href="https://stats.wikimedia.org/v2/#/fr.wikipedia.org/reading/page-views-by-country/normal%7Cmap%7C2-Year~2016060100~2018071100%7C~total">10</a>
!! wikitext
[https://stats.wikimedia.org/v2/#/fr.wikipedia.org/reading/page-views-by-country/normal|map|2-Year~2016060100~2018071100|~total 9]
[[stats:v2/#/fr.wikipedia.org/reading/page-views-by-country/normal%7Cmap%7C2-Year~2016060100~2018071100%7C~total|10]]
!! end

!! test
T199926: Hash only interwiki link
!! config
wgFragmentMode=[ 'html5' ]
!! wikitext
[[meatball:Test#1/2]]
[[gerrit:#/q/project:mediawiki/services/parsoid|Gerrit]]
!! html/php+tidy
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?Test#1.2F2" class="extiw" title="meatball:Test">meatball:Test#1/2</a>
<a href="https://gerrit.wikimedia.org/#/q/project:mediawiki/services/parsoid" class="extiw" title="gerrit:">Gerrit</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?Test#1.2F2" title="meatball:Test" data-parsoid='{"stx":"simple","a":{"href":"http://www.usemod.com/cgi-bin/mb.pl?Test#1.2F2"},"sa":{"href":"meatball:Test#1/2"},"isIW":true}'>meatball:Test#1/2</a>
<a rel="mw:WikiLink/Interwiki" href="https://gerrit.wikimedia.org/#/q/project:mediawiki/services/parsoid">Gerrit</a></p>
!! end

!! test
T179544: {{anchorencode:}} output should be always usable in links
!! config
wgFragmentMode=[ 'html5' ]
!! wikitext
<span id="{{anchorencode:[foo]}}"></span>[[#{{anchorencode:[foo]}}]]
!! html/php
<p><span id="&#91;foo&#93;"></span><a href="#[foo]">#&#91;foo&#93;</a>
</p>
!! html/parsoid
<p><span id="[foo]" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"id":"[foo]"},"sa":{"id":"{{anchorencode:[foo]}}"}}' data-mw='{"attribs":[[{"txt":"id"},{"html":"&lt;span typeof=\"mw:Transclusion mw:Entity\" about=\"#mwt1\" data-parsoid=&apos;{\"srcContent\":\"[\",\"dsr\":[10,32,null,null],\"pi\":[[]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"anchorencode:[foo]\",\"function\":\"anchorencode\"},\"params\":{},\"i\":0}}]}&apos;>[&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">foo&lt;/span>&lt;span typeof=\"mw:Entity\" about=\"#mwt1\" data-parsoid=&apos;{\"src\":\"&amp;amp;#x5D;\",\"srcContent\":\"]\"}&apos;>]&lt;/span>"}]]}'></span><a typeof="mw:ExpandedAttrs" about="#mwt4" rel="mw:WikiLink" href="./Parser_test#[foo]" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#[foo]"},"sa":{"href":"#{{anchorencode:[foo]}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"#&lt;span typeof=\"mw:Transclusion mw:Entity\" about=\"#mwt2\" data-parsoid=&apos;{\"srcContent\":\"[\",\"dsr\":[44,66,null,null],\"pi\":[[]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"anchorencode:[foo]\",\"function\":\"anchorencode\"},\"params\":{},\"i\":0}}]}&apos;>[&lt;/span>&lt;span about=\"#mwt2\" data-parsoid=\"{}\">foo&lt;/span>&lt;span typeof=\"mw:Entity\" about=\"#mwt2\" data-parsoid=&apos;{\"src\":\"&amp;amp;#x5D;\",\"srcContent\":\"]\"}&apos;>]&lt;/span>"}]]}'>#[foo]</a></p>
!! end
##########################################################################
# Tests demonstrating white-space insensitivity in input wikitext
# for wikitext headings, wikitext list items, and wikitext table captions,
# headings, and cells. HTML versions of the same should preserve whitespace.
##########################################################################
!! test
Trim whitespace in wikitext headings, list items, table captions, headings, and cells
!! options
parsoid={
	"modes": ["wt2html"],
	"preserveIEW": true
}
!! wikitext
__NOTOC__
==    <!--c1-->  <!--c2--> Spaces   <!--c3--> <!--c4-->  ==
==		<!--c1-->	<!--c2--> Tabs		<!--c3--><!--c4-->	==
== <!--Headings with fallback ids--> Личная жизнь ==
*     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->
; <!--term to define--> term : <!--term's definition--> definition
{|
|+ <!--c1--> <!--c2--> Table Caption <!--c3--> <!--c4-->
|-
!  <!--c1--> <!--c2--> Table Heading 1 <!--c3--> <!--c4--> !!   Table Heading 2 <!--c5-->
|-
| <!--c1--> <!--c2--> Table Cell 1 <!--c3--> <!--c4--> ||   Table Cell 2 <!--c5-->
|-
| class="foo" || <!--c1--> <!--c2--> Table Cell 3 <!--c3--> <!--c4-->
|-
| <!--c1--> testing [[one|two]] <!--c2--> | <!--c3--> some content
|}
: {|
  |  <!--c1--> <!--c2--> Table Cell 1 <!--c3--> <!--c4--> ||   Table Cell 2 <!--c5-->
  |} foo   <!--c1-->
!! html/php+tidy
<h2><span class="mw-headline" id="Spaces">Spaces</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Spaces">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Tabs">Tabs</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Tabs">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id=".D0.9B.D0.B8.D1.87.D0.BD.D0.B0.D1.8F_.D0.B6.D0.B8.D0.B7.D0.BD.D1.8C">Личная жизнь</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Личная жизнь">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<ul><li>List item</li></ul>
<dl><dt>term</dt>
<dd>definition</dd></dl>
<table>
<caption>Table Caption
</caption>
<tbody><tr>
<th>Table Heading 1</th>
<th>Table Heading 2
</th></tr>
<tr>
<td>Table Cell 1</td>
<td>Table Cell 2
</td></tr>
<tr>
<td>class="foo"</td>
<td>Table Cell 3
</td></tr>
<tr>
<td>testing <a href="/index.php?title=One&amp;action=edit&amp;redlink=1" class="new" title="One (page does not exist)">two</a>  |  some content
</td></tr></tbody></table>
<dl><dd><table>
<tbody><tr>
<td>Table Cell 1</td>
<td>Table Cell 2
</td></tr></tbody></table> foo</dd></dl>
!! html/parsoid
<meta property="mw:PageProp/notoc">
<h2 id="Spaces"><!--c1--><!--c2-->Spaces<!--c3--><!--c4--></h2>
<h2 id="Tabs"><!--c1--><!--c2-->Tabs<!--c3--><!--c4--></h2>
<h2 id="Личная_жизнь"><span id=".D0.9B.D0.B8.D1.87.D0.BD.D0.B0.D1.8F_.D0.B6.D0.B8.D0.B7.D0.BD.D1.8C" typeof="mw:FallbackId"></span><!--Headings with fallback ids-->Личная жизнь</h2>
<ul><li><!--c1--><!--c2-->List item<!--c3--><!--c4--></li></ul>
<dl><dt><!--term to define-->term</dt><dd><!--term's definition-->definition</dd></dl>
<table>
<caption><!--c1--><!--c2-->Table Caption<!--c3--><!--c4--></caption>
<tbody><tr>
<th><!--c1--><!--c2-->Table Heading 1<!--c3--><!--c4--></th><th>Table Heading 2<!--c5--></th></tr>
<tr>
<td><!--c1--><!--c2-->Table Cell 1<!--c3--><!--c4--></td><td>Table Cell 2<!--c5--></td></tr>
<tr>
<td>class="foo"</td><td><!--c1--><!--c2-->Table Cell 3<!--c3--><!--c4--></td></tr>
<tr>
<td><!--c1-->testing <a rel="mw:WikiLink" href="./One" title="One" class="new">two</a> <!--c2--> | <!--c3--> some content</td></tr>
</tbody></table>
<dl><dd><table>
  <tbody><tr><td><!--c1--><!--c2-->Table Cell 1<!--c3--><!--c4--></td><td>Table Cell 2<!--c5--></td></tr>
  </tbody></table> foo<!--c1--></dd></dl>
!! end

# Looks like <caption> is not accepted in HTML
!! test
Do not trim whitespace in HTML headings, list items, table captions, headings, and cells
!! options
parsoid={
	"modes": ["wt2html"],
	"preserveIEW": true
}
!! wikitext
__NOTOC__
<h2>    <!--c1-->   <!--c2--> Heading    <!--c3--> <!--c4-->  </h2>
<ul><li>     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->  </li></ul>
<table>
<tr><th> <!--c1--> <!--c2--> Table Heading <!--c3--> <!--c4--> <th></tr>
<tr><td> <!--c1--> <!--c2--> Table Cell <!--c3--> <!--c4--> <th></tr>
</table>
!! html/php+tidy
<h2><span class="mw-headline" id="Heading">        Heading       </span></h2>
<ul><li>          List item    </li></ul>
<table>
<tbody><tr><th>   Table Heading   </th><th></th></tr>
<tr><td>   Table Cell   </td><th></th></tr>
</tbody></table>
!! html/parsoid
<meta property="mw:PageProp/notoc"/>
<h2 id="Heading">    <!--c1-->   <!--c2--> Heading    <!--c3--> <!--c4-->  </h2>
<ul><li>     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->  </li></ul>
<table>
<tbody><tr><th> <!--c1--> <!--c2--> Table Heading <!--c3--> <!--c4--> </th><th></th></tr>
<tr><td> <!--c1--> <!--c2--> Table Cell <!--c3--> <!--c4--> </td><th></th></tr>
</tbody></table>
!! end

!! test
Do not trim whitespace in links and quotes
!! options
parsoid={
	"modes": ["wt2html"],
	"preserveIEW": true
}
!! wikitext
foo ''  <!--c1--> italic <!--c2-->   '' and '''  <!--c3-->  bold  <!--c4-->  '''
[[Foo|  some text  ]]
!! html/php+tidy
<p>foo <i>   italic    </i> and <b>    bold    </b>
<a href="/wiki/Foo" title="Foo">  some text  </a>
</p>
!! html/parsoid
<p>foo <i>  <!--c1--> italic <!--c2-->   </i> and <b>  <!--c3-->  bold  <!--c4-->  </b>
<a rel="mw:WikiLink" href="./Foo" title="Foo">  some text  </a></p>
!! end

!! test
Remove p tags surrounding a single element in a figcaption
!! options
parsoid=html2wt
!! wikitext
[[File:Foobar.jpg|right|200x200px|Caption]]
!! html/parsoid
<figure class="mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="23" width="200"/></a><figcaption><p>Caption</p></figcaption></figure>
!! end

!! test
Selser preserves lack of newline before list and allows newline after the list
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    [ "ul", "after", "<p>footer</p>" ]
  ]
}
!! wikitext
header
*foo
*bar
!! wikitext/edited
header
*foo
*bar
footer
!! end

!! test
Selser does not introduce newlines between unedited paragraph preceding the list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr td p:last-child", "empty" ]
  ]
}
!! wikitext
{|
|
header
*foo
*bar
footer
|}
!! wikitext/edited
{|
|
header
*foo
*bar

|}
!! end

!! test
Selser does not introduce newlines between unedited paragraph following the list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr td p:first-child", "empty" ]
  ]
}
!! wikitext
{|
|
header
*foo
*bar
footer
|}
!! wikitext/edited
{|
|
*foo
*bar
footer
|}
!! end

!! test
Remove a list item but do not insert newline above list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
     [ "ul li:last-child", "remove" ]
  ]
}
!! wikitext
header
*foo
*bar
footer
!! wikitext/edited
header
*foo
footer
!! end

!! test
Spaced heading with element
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["#x", "attr", "class", "y"]
  ]
}
!! wikitext
=== hi <span id="x">hi</span> hi ho ===
!! wikitext/edited
=== hi <span id="x" class="y">hi</span> hi ho ===
!! end

## Note that there's a leading \r here that's necessary for the test
!! test
Stray carriage return in text
!! options
parsoid=wt2html
!! wikitext

hiho
!! html/php+tidy
<p>
hiho
</p>
!! html/parsoid
<p>
hiho</p>
!! end

!! test
Allow tabindex 0
!! wikitext
<div tabindex="0">A</div>
!! html+tidy
<div tabindex="0">A</div>
!! end

!! test
Don't allow tabindex -1
!! options
parsoid=wt2html
!! wikitext
<div tabindex="-1">A</div>
!! html+tidy
<div>A</div>
!! end

!! test
Don't Allow tabindex > 0
!! options
parsoid=wt2html
!! wikitext
<div tabindex="3">A</div>
!! html+tidy
<div>A</div>
!! end

!! test
aside tag in extension HTML is not p-wrapped (T278565)
!! wikitext
<asidetag></asidetag>This is some article content.
!! html/php
<aside>Some aside content</aside><p>This is some article content.</p>
!! html/parsoid
<aside typeof="mw:Extension/asidetag" data-mw='{"name":"asidetag","attrs":{},"body":{"extsrc":""}}'>Some aside content</aside><p>This is some article content.</p>
!! end

!! test
aside tag is not allowed directly in wikitext (T278565)
!! wikitext
<aside>This aside tag in wikitext should be escaped</aside>
!! html
<p>&lt;aside&gt;This aside tag in wikitext should be escaped&lt;/aside&gt;
</p>
!! end
