# MediaWiki Parser test cases
# Some taken from http://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
# ill           add inter-language links
# subpage       enable subpages (disabled by default)
# noxml         don't check for XML well-formedness
# 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
#
# You can also set the following parser properties via test options:
#  wgEnableUploads, wgAllowExternalImages, wgMaxTocLevel,
#  wgLinkHolderBatchSize, wgRawHtml
#
# 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
Template:Foo
!!text
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:echo
!! text
{{{1}}}
!! endarticle

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

!! article
Template:echo_with_div
!! text
<div>{{{1}}}</div>
!! 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>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:PartialTable
!! text
{|
|-
!! endarticle

!! article
Template:image_attribs
!! text
<noinclude>
[[File:foobar.jpg|</noinclude>right|Caption text<noinclude>]]</noinclude>
!! endarticle

## See T48811 for details
!! article
Template:mixed_attr_content_template
!! text
style="color:red;" title="T48811"
|-
|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

###
### 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
foo

bar


baz



booz
!! html
<p>foo
</p><p>bar
</p><p><br />
baz
</p><p><br />
</p><p>booz
</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
!! wikitext
=b=



[[a]]
!! html
<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>
!! 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

# Note that the html+tidy output removes the spaces after the <li>,
# which is a bug (http://sourceforge.net/p/tidy/bugs/945/, etc).
# This is an issue for all tests with lists.  We intentionally do
# *not* add html+tidy clauses for these, as we don't want to
# document/test the broken behavior.  (Parsoid matches the non-tidy
# output in these cases.)

!! 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 (bug 47326)
!! 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]] (bug 49926)
!! 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]] (bug 49926)
!! 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

# The PHP parser strips the empty tags out for giggles; parsoid doesn't.
!! test
Italics and bold: 2-quote opening sequence: (2,5)
!! options
parsoid=wt2html
!! wikitext
''foo'''''
!! html/php
<p><i>foo</i>
</p>
!! html/parsoid
<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/php
<p><i>foo</i>
</p>
!! html/parsoid
<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
<p><b>foo</b>
</p>
!! html/parsoid
<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
<p><b>foo</b>
</p>
!! html/parsoid
<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
<p>'<b>foo</b>
</p>
!! html/parsoid
<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
<p>'<b>foo</b>
</p>
!! html/parsoid
<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/*
<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


# The PHP parser strips the empty tags out for giggles; parsoid doesn't.
!! test
Italics and bold: multiple quote sequences: (3,4,2)
!! options
parsoid=wt2html
!! wikitext
'''foo''''bar''
!! html/php
<p><b>foo'</b>bar
</p>
!! html/parsoid
<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
!! options
parsoid
!! wikitext
'''<nowiki>foo'</nowiki>'''bar''<nowiki/>''
!! html/php
<p><b>foo'</b>bar
</p>
!! html/parsoid
<p><b><span typeof="mw:Nowiki">foo'</span></b>bar<i></i>
</p>
!! end


# The PHP parser strips the empty tags out for giggles; parsoid doesn't.
!! test
Italics and bold: multiple quote sequences: (3,4,3)
!! options
parsoid=wt2html
!! wikitext
'''foo''''bar'''
!! html/php
<p><b>foo'</b>bar
</p>
!! html/parsoid
<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
'''<nowiki>foo'</nowiki>'''bar'''<nowiki/>'''
!! html/php
<p><b>foo'</b>bar
</p>
!! html/parsoid
<p><b><span typeof="mw:Nowiki">foo'</span></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
Parsoid only: Quote balancing context should be restricted to td/th cells on the same wikitext line
(Requires tidy for PHP parser output to be fixed up)
!! options
parsoid=wt2html,wt2wt
!! wikitext
{|
!''a!!''b
|''a||''b
|}
!! html/php+tidy
<table>
<tr>
<th><i>a</i></th>
<th><i>b</i></th>
<td><i>a</i></td>
<td><i>b</i></td>
</tr>
</table>
!! html/parsoid
<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

###
### 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 (bug 52468)
!! 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
# http://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 (bug 17663, 40670, 52022)
!! 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
<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>
!! end

# There is a tidy bug here: http://sourceforge.net/p/tidy/bugs/946/
# If the non-word-character tag made it through the sanitizer, tidy
# would munge it up.
!! test
Non-word characters don't terminate tag names + tidy
!! 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+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/parserTestsParserHook.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>

!! end

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

<s.foo>s</s>
!! html/php+tidy
<p>&lt;s.foo&gt;s</p>
!! html/parsoid
<p>&lt;s.foo&gt;s</p>
!! end

###
### Special characters
###

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

!! test
Bare pipe character from a template (bug 52363)
!! wikitext
{{pipe}}
!! html
<p>|
</p>
!! 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
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
<p>&lt;
</p>
!! end

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

!! 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

# This test fails because wikitext whitespace is not normalized before comparing.
!! 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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo|bar |[[&quot;}},&quot;i&quot;:0}}]}" about="#mwt2"></p>
!! wikitext
{{echo|foo{{!}}bar}}
{{echo|<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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;a }&quot;}},&quot;i&quot;:0}}]}" about="#mwt5"></span></p>
!! wikitext
{{echo|a [ b}}
{{echo|a <nowiki>}}</nowiki> b}}
{{echo|<nowiki>a [[ b</nowiki>}}
{{echo|a {{!}} <nowiki>{{ ]]</nowiki>}}
{{echo|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

###
### 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
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

###
### 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
a <div>foo</div>
<p>b
</p>
!! html+tidy
<p>a</p>
<div>foo</div>
<p>b</p>
!! end

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

b
!! html
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
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
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
<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>
!! end

# Tidy strips out the empty <div> tags. Parsoid doesn't.
# So, we have a separate section for Parsoid. We don't want
# to mimic this stripping behavior in Parsoid. It affects
# editing experience and also requires us to maintain additional
# info for RT-ing.
!! 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
<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
<p><br /></p>
<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

## PHP parser emits output which is broken
!! 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

###
### 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
Bug 52763: Preformatted in <blockquote>
!! wikitext
<blockquote>
 Blah
{|
|
 indented cell (no pre-wrapping!)
|}
</blockquote>
!! html
<blockquote>
<p> Blah
</p>
<table>
<tr>
<td>
<p> indented cell (no pre-wrapping!)
</p>
</td></tr></table>
</blockquote>

!! end

!! test
Bug 51086: 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
Bug 15491: <ins>/<del> in blockquote
!! wikitext
<blockquote>
Foo <del>bar</del> <ins>baz</ins> quux
</blockquote>
!! html
<blockquote>
<p>Foo <del>bar</del> <ins>baz</ins> quux
</p>
</blockquote>

!! end

# Note that the p-wrapping is newline sensitive, which could be
# considered a bug: tidy will wrap only the 'Foo' in the example
# below in a <p> tag. (see comment 23-25 of bug #6200)
!! test
Bug 15491: <ins>/<del> in blockquote (2)
!! wikitext
<blockquote>Foo <del>bar</del> <ins>baz</ins> quux
</blockquote>
!! html
<blockquote>Foo <del>bar</del> <ins>baz</ins> quux
</blockquote>

!! html+tidy
<blockquote>
<p>Foo</p>
<del>bar</del> <ins>baz</ins> quux</blockquote>
!! end

!! test
<pre> with attributes (bug 3202)
!! 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 (bug 3202)
!! wikitext
<pre width="8">Narrow screen goodies</pre>
!! html
<pre width="8">Narrow screen goodies</pre>

!! end

!! test
<pre> with forbidden attribute (bug 3202)
!! 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 (bug 3202)
!! 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> (bug 13238)
!! 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> and <pre> preference (first one wins)
!! wikitext
<pre>
<nowiki>
</pre>
</nowiki>
</pre>

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

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

&lt;/pre&gt;
</p>
!! html/parsoid
<pre data-parsoid='{"stx":"html","strippedNL":true}'>&lt;nowiki>
</pre>
<p><span typeof="mw:Placeholder" data-parsoid='{"src":"&lt;/nowiki>"}'>&lt;/nowiki></span>
&lt;/pre></p>

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

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

# Parsoid doesn't strip empty tags, like Tidy does.
!! test
Empty pre; pre inside other HTML tags (bug 54946)
!! options
parsoid=wt2html,wt2wt
!! wikitext
a

<div><pre>
foo
</pre></div>
<pre></pre>
!! html/php
<p>a
</p>
<div><pre>
foo
</pre></div>
<pre></pre>

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

<div><pre>foo
</pre></div>
<pre></pre>
!! end

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

# Note that tidy removes the empty <p> tags from the start and end.
# Parsoid does not, by design.
!!test
Block tag pre
!! wikitext
<p><pre>foo</pre></p>
!! html/php+tidy
<pre>
foo
</pre>
!! html/parsoid
<p data-parsoid='{"stx":"html","autoInsertedEnd":true}'></p><pre data-parsoid='{"stx":"html"}'>foo</pre><p data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p>
!!end

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

!!end

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

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

!! test
Templates: Indent-Pre: 1d: Wrapping should be based on expanded content
!! wikitext
 {{echo|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
{{echo| foo}}

{{echo| foo}}{{echo| bar}}

{{echo| foo}}
{{echo| bar}}

{{echo|<!--cmt--> foo}}

<!--cmt-->{{echo| foo}}

{{echo|{{echo| }}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
{{echo| }}a

{{echo|
 }}a

{{echo|
 b}}

{{echo|a
 }}b

{{echo|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

!! test
Pres with newline attributes
!! wikitext
<pre class="one
two">hi</pre>
!! html/php
<pre class="one two">hi</pre>

!! html/parsoid
<pre class="one
two" data-parsoid='{"stx":"html"}'>hi</pre>
!! end

!! test
Things that look like <pre> tags aren't treated as such
!! wikitext
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

## PHP parser discards the "<pre " string
!! test
Handle broken pre-like tags (bug 64025)
!! options
parsoid=wt2html
!! wikitext
{{echo|<pre <pre>x</pre>}}

<table><pre </table>
!! html/php
<pre>x</pre>
<table><pre></pre></table>

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


<p>&lt;pre </p>

<table></table>
!! end

!! test
Parsoid: handle pre with space after attribute
!! options
parsoid=wt2html
!! wikitext
<pre style="width:50%;" >{{echo|foo}}</pre>
!! html/php
<pre style="width:50%;">{{echo|foo}}</pre>

!! html/parsoid
<pre style="width:50%;">{{echo|foo}}</pre>
!! end

# TODO / maybe: fix wt2wt for this
!! test
Parsoid: Don't paragraph-wrap fosterable content
!! options
parsoid=wt2html
!! wikitext
{|
<td></td>
<td></td>



|}
!! html
<table>

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

<td></td></tr>



</tbody></table>
!! end

!! test
Parsoid: Don't paragraph-wrap fosterable content even if table syntax is unbalanced
!! options
parsoid=wt2html
!! wikitext
{|
<td>
<td>
</td>



|}
!! html
<table>

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

<td>
</td></tr>



</tbody></table>
!! 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
{{echo|1= a }}

{{echo|1= {{echo|b}} }}

{{echo| 1 =
 c }}

{{echo| 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
{{echo|a }}

{{echo|{{echo|b}} }}

{{echo| c 
}}

{{echo| {{echo|d}}
}}

{{echo|
 e}}

{{echo|
* f}}

{{echo|
 }}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: Handle empty comment-and-ws-only lines correctly
!! wikitext
{{echo|foo
<!--should be ignored-->
 <!--should be ignored as well-->
bar}}
!! html
<p>foo
bar
</p>
!! end

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

{{echo<!-- should be ignored -->
|foo}}

{{echo<!-- should be ignored -->|foo}}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

!! test
Parsoid: Pipe in external link target and content in template parameter
!! options
parsoid=html2wt,wt2wt
!! wikitext
{{echo|[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|b</a></p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://foo.com/a|b" about="#mwt1"
typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},
"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)
!! options
parsoid
!! wikitext
{{echo|[{{fullurl:{{FULLPAGENAME}}|action=edit}} bar]}}
!! html
<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[{{fullurl:{{FULLPAGENAME}}|action=edit}} bar]"}},"i":0}}]}'>[Main Page bar]</p>
!! end

!! test
Templates: Don't escape already nowiki-escaped text in template parameters
!! options
parsoid=html2wt,wt2wt
!! wikitext
{{echo|foo<nowiki>|</nowiki>bar}}
{{echo|<nowiki>&lt;div&gt;</nowiki>}}
{{echo|<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":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo<nowiki>|</nowiki>bar"}},"i":0}}]}'}'>foo</span><span typeof="mw:Nowiki" about="#mwt1">|</span><span about="#mwt1">bar</span>
<span typeof="mw:Transclusion mw:Nowiki" about="#mwt2" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<nowiki>&amp;lt;div&amp;gt;</nowiki>"}},"i":0}}]}'><span typeof="mw:Entity">&lt;</span>div<span typeof="mw:Entity">&gt;</span></span>
<span typeof="mw:Transclusion mw:Nowiki" about="#mwt3" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<nowiki></nowiki>"}},"i":0}}]}'></span>
</p>
!! end

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

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

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

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

<tr>
<th>h1</th>
<th>h2
</th>
<td>foo</td>
<td>bar
</td></tr></table>

!!end

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

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

!!end

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

!!end

!!test
2d. Indent-Pre and tables
!! wikitext
 a
 {|
 | b
 |}
!! html/php
<pre>a
</pre>
<table>
<tr>
<td> b
</td></tr></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
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
 a <p> foo </p>
 b <div> foo </div>
 c <blockquote> foo </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"}'> foo </blockquote>
<pre><span> foo </span>
</pre>
!! html+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>
!! end

!!test
3b. Indent-Pre and block tags (multi-line html)
!! wikitext
 a <span>foo</span>
 b <div> foo </div>
!! html
<pre>a <span>foo</span>
</pre>
 b <div> foo </div>

!! html/parsoid
<pre>a <span data-parsoid='{"stx":"html"}'>foo</span></pre>
 b <div data-parsoid='{"stx":"html"}'> foo </div>
!! html+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
<p>
 foo
</p>
<div>
<pre>foo
</pre>
</div>
<center>
<pre>foo
</pre>
</center>
<blockquote>
<p> foo
</p>
</blockquote>
<blockquote>
<pre>
foo
</pre>
</blockquote>
<table><tr><td>
<pre>foo
</pre>
</td></tr></table>
<ul><li>
  foo
</li></ul>

!!end

!!test
4. Indent-Pre and extension tags
!! wikitext
 a <gallery>
File:foobar.jpg
</gallery>
!! html
 a <ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
			</div>
		</div></li>
</ul>

!! html+tidy
<p>a</p>
<ul class="gallery mw-gallery-traditional">
<li class="gallerybox" style="width: 155px">
<div style="width: 155px">
<div class="thumb" style="width: 150px;">
<div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div>
</div>
<div class="gallerytext"></div>
</div>
</li>
</ul>
!!end

!! test
Table wikitext syntax outside wiki-tables
!! wikitext
a
! not a table heading
|- not a table row
| not a table cell
| class="foo bar" | baz
b
|}
|-
c
!! html
<p>a
! not a table heading
|- not a table row
| not a table cell
| class="foo bar" | baz
b
|}
|-
c
</p>
!! 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>
<tr>
<td>foo
</td></tr></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 -->
{{echo| [[Category:foo]]}} <!-- No pre-wrapping -->
!! html/php+tidy
!! html/parsoid
 <link rel="mw:PageProp/Category" href="./Category:Foo"> <!-- No pre&#x2D;wrapping -->
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":" [[Category:foo]]"}},"i":0}}]}'> </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1"> <!-- No pre&#x2D;wrapping -->
!! end

!! test
7b. Indent-pre and category links
!! options
parsoid=wt2html,wt2wt
!! wikitext
 [[Category:foo]] a
 [[Category:foo]] {{echo|b}}
!! html
<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":"echo","href":"./Template:Echo"},"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

###
### 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 data-parsoid='{"stx":"html"}'>foo</pre>

<pre data-parsoid='{"stx":"html","strippedNL":"\n"}'>
foo
</pre>

<pre data-parsoid='{"stx":"html"}'>

foo
</pre>

<pre data-parsoid='{"stx":"html"}'>


foo
</pre>
!!end

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




haha




haha




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




haha




haha




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




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 data-parsoid='{"stx":"html","strippedNL":true}'>* foo
# bar
= no-h =
'' no-italic ''
[[ NoLink ]]
</pre>
!!end

###
### Definition lists
###
!! test
Simple definition
!! wikitext
; name : Definition
!! html
<dl><dt> name&#160;</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
!! wikitext
; http://example.com/ : definition
!! html
<dl><dt> <a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a>&#160;</dt>
<dd> 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
!! 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" 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
!! wikitext
; [http://www.wikipedia2.org/ Wikipedia : The Next Generation]: OK, I made that up
!! html
<dl><dt> <a rel="nofollow" class="external text" href="http://www.wikipedia2.org/">Wikipedia&#160;: The Next Generation</a></dt>
<dd> 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
!! wikitext
;one<br/>two : two-line fun
!! html
<dl><dt>one<br />two&#160;</dt>
<dd> two-line fun</dd></dl>

!! end

!! test
Bug 11748: 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.
!! wikitext
<ul><li>
; term : description
* unordered
</li></ul>
!! html
<ul><li>
<dl><dt> term&#160;</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>

!! 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>
<tr>
<td>foo
</td>
<td>bar
</td></tr></table></dd></dl></dd></dl>
<p>this text
should be left alone
</p>
!! end

!! test
Definition Lists: Hacky use to indent tables, with comments (bug 63979)
!! 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
!! wikitext
::<!-- foo -->{|
|foo
|}
!! html/parsoid
<dl><dd><dl><dd><!-- foo --><table><tr>
<td>foo</td>
</tr></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>
<tr>
<td>a
</td></tr></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 http://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>

<tr>
<td> a
<ul><li> b</li></ul>
</td></tr>
<tr>
<td> c
<ul><li> d</li></ul>
</td></tr></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>
<tr>
<td>
<dl><dd>a</dd>
<dd>b</dd></dl>
</td>
<td>
<ul><li>c</li>
<li>d</li></ul>
</td></tr></table></dd></dl>
<ul><li>e</li>
<li>f</li></ul>

!!end

!! test
Definition Lists: Nesting: Multi-level (Parsoid only)
!! options
parsoid
!! wikitext
;t1 :d1
;;t2 ::d2
;;;t3 :::d3
!! html
<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 (Parsoid only)
!! wikitext
;t1
::d2
!! html/php+tidy
<dl>
<dt>t1</dt>
<dd>
<dl>
<dd>d2</dd>
</dl>
</dd>
</dl>
!! html/parsoid
<dl>
  <dt>t1</dt>
  <dd>
    <dl>
      <dd>d2</dd>
    </dl>
  </dd>
</dl>

!! end


!! test
Definition Lists: Nesting: Test 3 (Parsoid only)
!! wikitext
:;t1
::::d2
!! html/php+tidy
<dl>
<dd>
<dl>
<dt>t1</dt>
<dd>
<dl>
<dd>
<dl>
<dd>d2</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
</dd>
</dl>
!! html/parsoid
<dl>
  <dd>
    <dl>
      <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
<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>
<dd>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
</dd>
</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
!! wikitext
*;d1 :d2
*;d3 :d4
!! html
<ul><li><dl><dt>d1&#160;</dt>
<dd>d2</dd>
<dt>d3&#160;</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
!! wikitext
*;foo :bar
!! html
<ul><li><dl><dt>foo&#160;</dt>
<dd>bar</dd></dl></li></ul>

!! end


!! test
Definition Lists: Mixed Lists: Test 10
!! wikitext
*#;foo :bar
!! html
<ul><li><ol><li><dl><dt>foo&#160;</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 two tests.  Parsoid is more
# consistent, and recognizes the shared nesting and keeps the
# still-open tags around until the nesting is complete.
# (And tidy again converts <dt> to <dd> before 'bar'.)

!! test
Definition Lists: Mixed Lists: Test 11
!! wikitext
*#*#;*;;foo :bar
*#*#;boo :baz
!! html/php
<ul><li><ol><li><ul><li><ol><li><dl><dt>foo&#160;</dt>
<dd><ul><li><dl><dt><dl><dt>bar</dt></dl></dd></dl></li></ul></dd></dl>
<dl><dt>boo&#160;</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&#160;</dt>
<dd>
<ul>
<li>
<dl>
<dd>
<dl>
<dt>bar</dt>
</dl>
</dd>
</dl>
</li>
</ul>
</dd>
</dl>
<dl>
<dt>boo&#160;</dt>
<dd>baz</dd>
</dl>
</li>
</ol>
</li>
</ul>
</li>
</ol>
</li>
</ul>
!! html/parsoid
<ul>
<li>
<ol>
<li>
<ul>
<li>
<ol>
<li>
<dl>
<dt>
<ul>
<li>
<dl>
<dt>
<dl>
<dt>foo<span typeof="mw:Placeholder" data-parsoid='{"src":" "}'>&nbsp;</span></dt>
<dd data-parsoid='{"stx":"row"}'>bar</dd>
</dl></dt>
</dl></li>
</ul></dt>
<dt>boo<span typeof="mw:Placeholder" data-parsoid='{"src":" "}'>&nbsp;</span></dt>
<dd data-parsoid='{"stx":"row"}'>baz</dd>
</dl></li>
</ol></li>
</ul></li>
</ol></li>
</ul>
!! end


# Another case where tidy converts a <dt> to a <dd> (but Parsoid doesn't).
# From whitelist:
# * 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
!! wikitext
*#;*::;; foo : bar (who uses this?)
!! html/php
<ul><li><ol><li><dl><dt> foo&#160;</dt>
<dd><ul><li><dl><dd><dl><dd><dl><dt><dl><dt> bar (who uses this?)</dt></dl></dd></dl></dd></dl></dd></dl></li></ul></dd></dl></li></ol></li></ul>

!! html/php+tidy
<ul>
<li>
<ol>
<li>
<dl>
<dt>foo&#160;</dt>
<dd>
<ul>
<li>
<dl>
<dd>
<dl>
<dd>
<dl>
<dd>
<dl>
<dt>bar (who uses this?)</dt>
</dl>
</dd>
</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<span typeof="mw:DisplaySpace mw:Placeholder" data-parsoid='{"src":" ","isDisplayHack":true}'> </span></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>
;{{echo|a:b}}
;{{echo|''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>
<dd>
<div>a:b</div>
</dd>
<dd>
<div>a
<dl>
<dd>b</dd>
</dl>
</div>
</dd>
<dt>a</dt>
<dd>b</dd>
<dt><i>a:b</i></dt>
</dl>
<dl>
<dd>
<dl>
<dd>
<dl>
<dt><i>a:b</i></dt>
</dl>
</dd>
</dl>
</dd>
</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</dd>
<dt><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a:b"}},"i":0}}]}'>a:b</span></dt>
<dt><i about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"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

!! test
Definition Lists: colons and tables 1
!! wikitext
:{|
| x
|}
:{|
| y
|}
!! html
<dl><dd><table>
<tr>
<td> x
</td></tr></table></dd></dl>
<dl><dd><table>
<tr>
<td> y
</td></tr></table></dd></dl>

!! end

# Parsoid's output (as documented below) differs from php's in this case.
# This is probably a bug. If we fixup parsoid to match php's output, the
# above test should pass and the below test case can be removed. It is
# unclear which output is more desirable.

!! test
Definition Lists: colons and tables 2
!! wikitext
:{|
| x
|}
:{|
| y
|}
!! html/parsoid
<dl><dd><table>
<tr>
<td> x
</td></tr></table></dd>
<dd><table>
<tr>
<td> y
</td></tr></table></dd></dl>
!! end

!! 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 bug 53505
!! 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"></a>
Numbered: <a rel="mw:ExtLink" href="http://example.net"></a>
Numbered: <a rel="mw:ExtLink" href="http://example.com"></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 bug 53505
!! 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"></a></p>
!!end

!! test
External links: open square bracket forbidden in URL (bug 4377)
!! 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">http://example.com/1</a>[2345</p>
!! end

!! test
External links: open square bracket forbidden in URL (named) (bug 4377)
!! 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">[2345</a></p>
!!end

# parsoid adds a space before the link name
!! test
External links: open square bracket forbidden in URL (named) (bug 4377)
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 (bug 6230)
!! 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 (bug 6230 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 bug 53505
!! 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"></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 (bug 30269)
!! wikitext
foo//example.com/Foo
!! html
<p>foo//example.com/Foo
</p>
!! end

!! test
External links: with no contents
!! 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"></a></p>
<p><a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/Foo" title="wikipedia:Foo">Bar</a></p>
<p><a rel="mw:ExtLink" 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&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 ">http://example.com/url_with_entity </a>
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity ">http://example.com/url_with_entity </a>
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity ">http://example.com/url_with_entity </a>
<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%3C">http://example.com/url_with_entity%3C</a>
<a rel="nofollow" class="external free" href="http://example.com/url_with_entity%3C">http://example.com/url_with_entity%3C</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a>,
<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>;
<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>\
<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>.
<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>:
<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>!
<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>?
<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>)
<a rel="mw:ExtLink" href="http://example.com/url_with_(brackets)">http://example.com/url_with_(brackets)</a>
(<a rel="mw:ExtLink" href="http://example.com/url_without_brackets">http://example.com/url_without_brackets</a>)
<a rel="mw:ExtLink" href="http://example.com/url_with_entity ">http://example.com/url_with_entity </a>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity ">http://example.com/url_with_entity </a>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity ">http://example.com/url_with_entity </a>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity">http://example.com/url_with_entity</a><span typeof="mw:Entity">&lt;</span>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity&lt;">http://example.com/url_with_entity&lt;</a>
<a rel="mw:ExtLink" href="http://example.com/url_with_entity&lt;">http://example.com/url_with_entity&lt;</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 (bug 65278)
!! 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 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

!! test
External links: URL in text
!! wikitext
URL in text: [http://example.com http://example.com]
!! html
<p>URL in text: <a rel="nofollow" class="external free" href="http://example.com">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"><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">http://x&amp;y</a></p>
!! end

!! test
External links: encoded equals (bug 6102)
!! 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">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 bug 53505, 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"></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"></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"></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] (bug 6102)
!! 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"></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/"></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/">http://example.com/</a></p>
!! end

!! test
External links: www.jpeg.org (bug 554)
!! 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 bug 53505
!! test
External links: URL within URL (original bug 2)
!! 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"></a></p>
!! end

!! test
BUG 361: 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
BUG 361: 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
BUG 289: ">"-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
BUG 289: 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/" data-parsoid='{"stx":"url"}'>http://www.example.com/</a><b data-parsoid='{"stx":"html"}'>html</b></p>
!! end

!! test
BUG 289: ">"-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
BUG 289: 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
BUG 289: 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
BUG 289: 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. (bug 5081)
!! 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

!! test
External links: wiki links within external link (Bug 3695)
!! wikitext
[http://example.com [[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><a rel="nofollow" class="external text" href="http://example.com"> embedded in ext link</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com"></a><a rel="mw:WikiLink" href="./Wikilink" title="Wikilink">wikilink</a><span> embedded in ext link</span></p>
!! end

!! test
BUG 787: 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
[{{echo|http:/example.com}} title]
!! html
<p>[http:/example.com title]
</p>
!! end

!! test
Bug 2702: 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
<p><a rel="nofollow" class="external text" href="http://example.com"><i>text</i></a>
<a rel="nofollow" class="external text" href="http://example.com"><b>text</b></a>
<i>Something </i><a rel="nofollow" class="external text" href="http://example.com"><i>in italic</i></a>
<i>Something </i><a rel="nofollow" class="external text" href="http://example.com"><i>mixed</i><b>, even bold</b></a>
<i><b>Now </b></i><a rel="nofollow" class="external text" href="http://example.com"><i><b>both</b></i></a>
</p>
!! end


!! test
Bug 4781: %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">http://www.example.com/?title=AT%26T</a></p>
!! end

# According to http://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
Bug 4781, 5267: %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">http://www.example.com/?title=100%25_Bran</a></p>
!! end

!! test
Bug 4781, 5267: %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">http://www.example.com/?title=Ben-Hur_%281959_film%29</a></p>
!! end


!! test
Bug 4781: %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"></a></p>
!! end

!! test
Bug 4781, 5267: %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"></a></p>
!! end

!! test
Bug 4781, 5267: %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"></a></p>
!! end


!! test
Bug 4781: %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">link</a></p>
!! end

!! test
Bug 4781, 5267: %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
Bug 4781, 5267: %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">link</a></p>
!! end

!! test
External link containing a period in the anchor. (bug 63947)
!! wikitext
[//foo.org/bar#baz. bang]

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

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

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

!! test
External link containing double-single-quotes in text '' (bug 4598 sanity check)
!! wikitext
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

!! test
External link containing double-single-quotes in text embedded in italics (bug 4598 sanity check)
!! wikitext
''Some [http://example.com/ pretty ''italics'' and stuff]!''
!! html
<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>
!! end

!! 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
<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 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>.</a>
</p>
!! 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"><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)">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">Google <!-- comment --></a></p>
!! end

!! test
External link to bare IPv4 address
!! wikitext
[http://192.168.0.1 Link]
!! html/php
<p><a rel="nofollow" class="external text" href="http://192.168.0.1">Link</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://192.168.0.1">Link</a></p>
!! end

!! test
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">http://example.com/index.php?foozoid%5B%5D=bar</a></p>

<p><a rel="mw:ExtLink" href="http://example.com/index.php?foozoid[]=bar">http://example.com/index.php?foozoid[]=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="//tools.ietf.org/html/rfc2373">RFC 2373</a>, section 2.2:
</p>
<ul><li> <a rel="nofollow" class="external free" href="http://[1080::8:800:200C:417A]/unicast">http://[1080::8:800:200C:417A]/unicast</a></li>
<li> <a rel="nofollow" class="external free" href="http://[FF01::101]/multicast">http://[FF01::101]/multicast</a></li>
<li> <a rel="nofollow" class="external free" href="http://[::1]/loopback">http://[::1]/loopback</a></li>
<li> <a rel="nofollow" class="external free" href="http://[::]/unspecified">http://[::]/unspecified</a></li>
<li> <a rel="nofollow" class="external free" href="http://[::13.1.68.3]/ipv4compat">http://[::13.1.68.3]/ipv4compat</a></li>
<li> <a rel="nofollow" class="external free" href="http://[::FFFF:129.144.52.38]/ipv4compat">http://[::FFFF:129.144.52.38]/ipv4compat</a></li></ul>
<p>Examples from <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc2732">RFC 2732</a>, section 2:
</p>
<ul><li> <a rel="nofollow" class="external free" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html">http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html</a></li>
<li> <a rel="nofollow" class="external free" href="http://[1080:0:0:0:8:800:200C:417A]/index.html">http://[1080:0:0:0:8:800:200C:417A]/index.html</a></li>
<li> <a rel="nofollow" class="external free" href="http://[3ffe:2a00:100:7031::1]">http://[3ffe:2a00:100:7031::1]</a></li>
<li> <a rel="nofollow" class="external free" href="http://[1080::8:800:200C:417A]/foo">http://[1080::8:800:200C:417A]/foo</a></li>
<li> <a rel="nofollow" class="external free" href="http://[::192.9.5.5]/ipng">http://[::192.9.5.5]/ipng</a></li>
<li> <a rel="nofollow" class="external free" href="http://[::FFFF:129.144.52.38]:80/index.html">http://[::FFFF:129.144.52.38]:80/index.html</a></li>
<li> <a rel="nofollow" class="external free" href="http://[2010:836B:4179::836B:4179]">http://[2010:836B:4179::836B:4179]</a></li></ul>

!! html/parsoid
<p><a rel="mw:ExtLink" href="http://[2404:130:0:1000::187:2]/index.php">http://[2404:130:0:1000::187:2]/index.php</a></p>

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

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

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

Examples from RFC 2373, section 2.2:
* [http://[1080::8:800:200C:417A] unicast]
* [http://[FF01::101] multicast]
* [http://[::1]/ loopback]
* [http://[::] unspecified]
* [http://[::13.1.68.3] ipv4compat]
* [http://[::FFFF:129.144.52.38] ipv4compat]

Examples from RFC 2732, section 2:
* [http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html 1]
* [http://[1080:0:0:0:8:800:200C:417A]/index.html 2]
* [http://[3ffe:2a00:100:7031::1] 3]
* [http://[1080::8:800:200C:417A]/foo 4]
* [http://[::192.9.5.5]/ipng 5]
* [http://[::FFFF:129.144.52.38]:80/index.html 6]
* [http://[2010:836B:4179::836B:4179] 7]

!! html/php
<p><a rel="nofollow" class="external text" href="http://[2404:130:0:1000::187:2]/index.php">test</a>
</p><p>Examples from <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc2373">RFC 2373</a>, section 2.2:
</p>
<ul><li> <a rel="nofollow" class="external text" href="http://[1080::8:800:200C:417A]">unicast</a></li>
<li> <a rel="nofollow" class="external text" href="http://[FF01::101]">multicast</a></li>
<li> <a rel="nofollow" class="external text" href="http://[::1]/">loopback</a></li>
<li> <a rel="nofollow" class="external text" href="http://[::]">unspecified</a></li>
<li> <a rel="nofollow" class="external text" href="http://[::13.1.68.3]">ipv4compat</a></li>
<li> <a rel="nofollow" class="external text" href="http://[::FFFF:129.144.52.38]">ipv4compat</a></li></ul>
<p>Examples from <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc2732">RFC 2732</a>, section 2:
</p>
<ul><li> <a rel="nofollow" class="external text" href="http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html">1</a></li>
<li> <a rel="nofollow" class="external text" href="http://[1080:0:0:0:8:800:200C:417A]/index.html">2</a></li>
<li> <a rel="nofollow" class="external text" href="http://[3ffe:2a00:100:7031::1]">3</a></li>
<li> <a rel="nofollow" class="external text" href="http://[1080::8:800:200C:417A]/foo">4</a></li>
<li> <a rel="nofollow" class="external text" href="http://[::192.9.5.5]/ipng">5</a></li>
<li> <a rel="nofollow" class="external text" href="http://[::FFFF:129.144.52.38]:80/index.html">6</a></li>
<li> <a rel="nofollow" class="external text" href="http://[2010:836B:4179::836B:4179]">7</a></li></ul>

!! html/parsoid
<p><a rel="mw:ExtLink" href="http://[2404:130:0:1000::187:2]/index.php">test</a></p>

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

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

!! test
Non-extlinks in brackets
!! wikitext
[foo]
[foo bar]
[foo ''bar'']
[fool's] errand
[fool's errand]
[{{echo|foo}}]
[{{echo|foo}} bar]
[{{echo|foo}} ''bar'']
[{{echo|foo}}l's] errand
[{{echo|foo}}l's errand]
[url={{echo|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 typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}"}'>foo</span>]
[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}"}'>foo</span> bar]
[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}"}'>foo</span> <i>bar</i>]
[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}l&#39;s"}'>fool's</span>] errand
[<span typeof="mw:Placeholder" data-parsoid='{"src":"{{echo|foo}}l&#39;s"}'>fool's</span> errand]
[<span typeof="mw:Placeholder" data-parsoid='{"src":"url={{echo|foo}}"}'>url=foo</span>]
[url=<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>]
[http:// bare protocols don't count]</p>
!! end

!! test
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">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">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">http://example.com</a>)</p>
<p><a rel="mw:ExtLink" href="http://example.com/test">http://example.com/test</a>)</p>
<p><a rel="mw:ExtLink" href="http://example.com/(test)">http://example.com/(test)</a></p>
<p><a rel="mw:ExtLink" href="http://example.com/((test)">http://example.com/((test)</a></p>
<p>(<a rel="mw:ExtLink" href="http://example.com/(test))">http://example.com/(test))</a></p>
<p>(<a rel="mw:ExtLink" href="http://example.com/(test)))))">http://example.com/(test)))))</a></p>
<p><a rel="mw:ExtLink" href="http://example.com/a)b">http://example.com/a)b</a></p>
<p><a rel="mw:ExtLink" href="http://example.com)">foo</a></p>
!! end

!! test
Parenthesis in external links, w/ transclusion or comment
!! wikitext
(http://example.com/{{echo|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" data-parsoid='{"stx":"url","a":{"href":"http://example.com/hi"},"sa":{"href":"http://example.com/{{echo|hi}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"http://example.com/&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;dsr&amp;quot;:[20,31,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;hi&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">hi&lt;/span>"}]]}'>http://example.com/hi</a>)</p>

<p>(<a rel="mw:ExtLink" href="http://example.com" 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=html2wt
!! 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>*a [[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"},"dsr":[0,11,6,2]}'>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]]
[[wikipedia:Foo|Bar]]
[[wikipedia:Foo|Bar]]

[[wikipedia:European_Robin|European Robin]]
[[wikipedia: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


# Parsoid inserts an empty bold tag pair at the end of the line, that the PHP
# parser strips. 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).
</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:
# http://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
<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><tr><td></td></tr></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>
<tr>
<td> foo
</td></tr></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>
<tr>
<td> foo
</td></tr></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>
<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></table>

!! end

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

!! end

!! test
Simple table but with multiple dashes for row wikitext
!! wikitext
{|
| foo
|-----
| bar
|}
!! html
<table>
<tr>
<td> foo
</td></tr>
<tr>
<td> bar
</td></tr></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>
<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></table>

!! end

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

!! end

!! test
Accept "!!" in table data
!! wikitext
{|
| Foo!! ||
|}
!! html
<table>
<tr>
<td> Foo!! </td>
<td>
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"autoInsertedEnd":true}'> Foo!! </td><td data-parsoid='{"stx_v":"row","autoInsertedEnd":true}'></td></tr>
</tbody></table>
!! end

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

!! end

!! test
Accept "!!" in templates
!! wikitext
{|
!a {{echo|b!!c}}
|}
!! html/php
<table>
<tr>
<th>a b</th>
<th>c
</th></tr></table>

!! html/parsoid
<table>
<tbody><tr><th typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"autoInsertedEnd":true,"pi":[[{"k":"1","spc":["","","",""]}]]}' data-mw='{"parts":["!a ",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"b!!c"}},"i":0}}]}'>a b</th><th about="#mwt1">c</th></tr>
!! end

!! test
Accept "!!" in table headings after newline
!! wikitext
{|
!a
b!!c
|}
!! html/php
<table>
<tr>
<th>a
<p>b!!c
</p>
</th></tr></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+tidy
<table>
<tr>
<th>a</th>
</tr>
<tr>
<td>b!!c</td>
</tr>
</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>
<tr>
<th> h1
</th>
<td> a
</td></tr></table>

!! end

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

<tr>
<td> bar
</td></tr></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>

<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></table>

!!end

!! 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
<table border="1">
<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></table>

!! end

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

!! end

!! test
Invalid attributes in table cell (bug 1830)
!! wikitext
{|
|Cell:|broken
|}
!! html
<table>
<tr>
<td>broken
</td></tr></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>
<tr>
<td title="foo">bar
</td>
<td title="foo&#124;">bar
</td>
<td> title="foo|" bar
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr><td title="foo">bar</td>
<td title="foo|" data-parsoid='{"a":{"title":"foo|"},"sa":{"title":"foo&lt;nowiki>|&lt;/nowiki>"},"autoInsertedEnd":true}'>bar</td>
<td> title="foo<span typeof="mw:Nowiki">|</span>" bar</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>
<tr>
<td>[<a rel="nofollow" class="external free" href="ftp://%7Cx">ftp://%7Cx</a></td>
<td>]" onmouseover="alert(document.cookie)"&gt;test
</td>
</tr>
</table>

!! html/parsoid
<table><tbody>
<tr>
<td data-parsoid='{"startTagSrc":"| ","attrSepSrc":"|","autoInsertedEnd":true}'><a rel="mw:ExtLink" href="ftp://|x||"></a>" onmouseover="alert(document.cookie)">test</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>
<tr>
<td> style="color: red !important;" data-contrived="put this here </td>
<td> foo
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr><td> style="color: red !important;" data-contrived="put this here </td><td data-parsoid='{"stx_v":"row","a":{"\"":null},"sa":{"\"":""},"autoInsertedEnd":true}'> foo</td></tr>
</tbody></table>
!! end

!! test
Indented table markup mixed with indented pre content (proposed in bug 6200)
!! wikitext
 <table>
 <tr>
 <td>
 Text that should be rendered preformatted
 </td>
 </tr>
 </table>
!! html
 <table>
 <tr>
 <td>
<pre>Text that should be rendered preformatted
</pre>
 </td>
 </tr>
 </table>

!! 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>
<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></table>

!! end

!! test
2. Template-generated table cell attributes and cell content
!! wikitext
{|
|{{table_attribs_2}}
|}
!! html/php
<table>
<tr>
<td style="color:red;">Foo
</td>
<td>Bar</td>
<td>Baz
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr><td about="#mwt1" typeof="mw:Transclusion" 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>
<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></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>
<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></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<span class="mw-ref" id="cite_ref-1" rel="dc:references" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></span></td></tr>
</tbody></table>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">foo</span></li></ol>
!! end

!! test
Table with row followed by newlines and table heading
!! wikitext
{|
|-

! foo
|}
!! html
<table>


<tr>
<th> foo
</th></tr></table>

!! end

!! test
Table with empty line following the start tag
!! wikitext
{|

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


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

!! end

# FIXME: Preserve the attribute properly (with an empty string as value) in
# the PHP parser. Parsoid implements the behavior below.
!! test
Table attributes with empty value
!! wikitext
{|
| style=| hello
|}
!! 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>
<tr>
<td> foo
</td></tr>
<tr>
<td>
</td></tr></table>

!! end

!! test
Wikitext table comments represented in parsoid dom
!! wikitext
{|<!--c1--><!--c2-->
|-<!--c3-->
| x
|}
!! html/php+tidy
<table>
<tr>
<td>x</td>
</tr>
</table>
!! html/parsoid
<table><!--c1--><!--c2-->
<tbody><tr data-parsoid='{"startTagSrc":"|-","autoInsertedEnd":true}'><!--c3-->
<td data-parsoid='{"autoInsertedEnd":true}'> x</td></tr>
</tbody></table>
!! end

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

!! end

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

!! end

!! test
Table-cell after a comment-only-empty-line
!! wikitext
{|
|a
<!--c1-->
<!--c2-->| b
|}
!! html
<table>
<tr>
<td>a
</td>
<td> b
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"autoInsertedEnd":true}'>a</td>
<!--c1-->
<!--c2--><td data-parsoid='{"autoInsertedEnd":true}'> 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">
<tr>
<th> header
</th>
<th> second header
</th></tr>
<tr style="color:red;">
<td> data </td>
<td style="color:red;"> second data
</td></tr></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">
<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></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">
<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></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

## Note that Parsoid output differs from PHP and PHP+tidy here.
## The lack of <tr> tags in the PHP output is arguably a bug in the
## PHP parser, which tidy then compounds by fostering the content
## entirely out of the table.  Parsoid recognizes the table context
## and generates <tr> and <td> wrappers as needed.  Hopefully nobody
## depends on PHP's treatment of broken table markup!
!! test
Implicit <td> after a |-
!! options
parsoid=wt2html,html2html
!! wikitext
{|
|-
a
|}
!! html/php
<table>

a
</table>

!! html/php+tidy
<p>a</p>
!! html/parsoid
<table>
<tr><td>a</td></tr>
</table>
!! end

# Again, Parsoid adds implicit <td>s here, PHP and Tidy strip the b out.
!! test
<pre> tags should be recognized in an explicit <td> context, but not in an implicit <td> context
!! options
parsoid=wt2html,html2html
!! wikitext
{|
|-
|
 a
|-
 b
|}
!! html/php
<table>

<tr>
<td>
<pre>a
</pre>
</td></tr>
 b
</table>

!! html/php+tidy
<p>b</p>
<table>
<tr>
<td>
<pre>
a
</pre></td>
</tr>
</table>
!! html/parsoid
<table>
<tbody>
<tr><td><pre>a</pre></td></tr>
<tr><td> b</td></tr>
</tbody>
</table>
!! end

# PHP + Tidy strips the list out of the table; Parsoid wraps it.
# Parsoid generates the missing <td>, so wt2wt won't succeed.
!! test
Lists should be recognized in an implicit <td> context
!! options
parsoid=wt2html,html2html
!! wikitext
{|
|-
*a
|}
!! html/php
<table>

<ul><li>a</li></ul>
</table>

!! html/php+tidy
<ul>
<li>a</li>
</ul>
!! html/parsoid
<table>
<tr>
<td><ul>
<li>a</li>
</ul></td>
</tr>
</table>
!! end

!! test
Table cells not properly parsed in an implicit-td context
!! wikitext
{|
|-
{{table_attribs_4}} || a || b
|}
!! html/php+tidy
<table>
<tr>
<td style="background-color:#DC241f;" width="10px"></td>
<td>a</td>
<td>b</td>
</tr>
</table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"startTagSrc":"|-","autoInsertedEnd":true}'>
<td style="background-color:#DC241f;" width="10px" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"autoInsertedEnd":true,"pi":[[]]}' data-mw='{"parts":["",{"template":{"target":{"wt":"table_attribs_4","href":"./Template:Table_attribs_4"},"params":{},"i":0}}," "]}'> </td><td data-parsoid='{"stx_v":"row","autoInsertedEnd":true}'> a </td><td data-parsoid='{"stx_v":"row","autoInsertedEnd":true}'> b</td></tr>
</tbody></table>
!! end

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

{|
|baz
|}<b>quux</b>
!! html+tidy
<table>
<tr>
<td>foo</td>
</tr>
</table>
<p>bar</p>
<table>
<tr>
<td>baz</td>
</tr>
</table>
<p><b>quux</b></p>
!! end

!! test
Parsoid: Default to a newline after tables in new content (bug 51219)
!! 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: newline inducing block nodes don't suppress <nowiki>
!! options
parsoid=html2wt
!! html/parsoid
 a<h1>foo</h1>
!! wikitext
<nowiki> </nowiki>a

= foo =
!! end

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

!! test
Tables: Digest broken attributes on table and tr tag
!! options
parsoid=wt2html
!! wikitext
{| || |} ++
|- || || ++ --
|- > [
|}
!! html
<table>
<tbody>
<tr></tr>
<tr></tr>
</tbody></table>
!! end

!! test
Strip unsupported table tags
!! options
parsoid=html2wt
!! html/parsoid
<table>
<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
{|

!Month
!Savings

|January
|$100

|-
|February
|$80

|Sum
|$180

|}
!! 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

###
### 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
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

!! test
Broken link with fragment
!! wikitext
[[Zigzagzogzagzig#zug]]
!! html
<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>
!! 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

!! test
Nonexistent special page link with fragment
!! wikitext
[[Special:ThisNameWillHopefullyNeverBeUsed#anchor]]
!! html
<p><a href="/wiki/Special:ThisNameWillHopefullyNeverBeUsed" class="new" title="Special:ThisNameWillHopefullyNeverBeUsed (page does not exist)">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
Bug 43661: 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]]]
!! 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>
</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></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

# Note that parsoid does not munge anchor text; all non-space
# characters are valid in HTML5 ids.
!! test
Anchor containing a #. (bug 63430)
!! wikitext
[[Main Page#And#Link]]
!! html/php
<p><a href="/wiki/Main_Page#And.23Link" title="Main Page">Main Page#And#Link</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page#And%23Link" title="Main Page">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 (bug 51680)
!! 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]]
!! html/php
<p><a href="/wiki/7%25_Solution" title="7% Solution">7% Solution</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./7%25_Solution" title="7% Solution">7% 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]]
!! html/php
<p><a href="/wiki/7%25_Solution" title="7% Solution">7% Solution</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./7%25_Solution" title="7% Solution">7% 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

# note that parsoid does not munge anchor text; all non-space
# characters are valid in HTML5 anchors.
!! test
Link containing "#<" and "#>" % as a hex sequences- these are valid section anchors
Example for such a section: == < ==
!! wikitext
[[%23%3c]][[%23%3e]]
!! html/php
<p><a href="#.3C">#&lt;</a><a href="#.3E">#&gt;</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main%20Page#%3C" title="Main Page">#&lt;</a><a rel="mw:WikiLink" href="./Main%20Page#%3E" title="Main Page">#></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 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 '' (bug 4598)
!! wikitext
[[Lista d''e paise d''o munno]]
!! html/php
<p><a href="/index.php?title=Lista_d%27%27e_paise_d%27%27o_munno&amp;action=edit&amp;redlink=1" class="new" title="Lista d''e paise d''o munno (page does not exist)">Lista d''e paise d''o munno</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Lista_d''e_paise_d''o_munno" title="Lista d''e paise d''o munno">Lista d''e paise d''o munno</a></p>
!! end

!! test
Link containing double-single-quotes '' in text (bug 4598 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">pretty <i>italics</i> and stuff</a>!</p>
!! end

!! test
Link containing double-single-quotes '' in text embedded in italics (bug 4598 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

!! test
Link with double quotes in title part (literal) and alternate part (interpreted)
!! wikitext
[[File:Denys_Savchenko_''Pentecoste''.jpg]]

[[''Pentecoste'']]

[[''Pentecoste''|Pentecoste]]

[[''Pentecoste''|''Pentecoste'']]
!! html/php
<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Denys_Savchenko_%27%27Pentecoste%27%27.jpg" class="new" title="File:Denys Savchenko &#39;&#39;Pentecoste&#39;&#39;.jpg">File:Denys Savchenko <i>Pentecoste</i>.jpg</a>
</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">''Pentecoste''</a>
</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)">Pentecoste</a>
</p><p><a href="/index.php?title=%27%27Pentecoste%27%27&amp;action=edit&amp;redlink=1" class="new" title="''Pentecoste'' (page does not exist)"><i>Pentecoste</i></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:Denys_Savchenko_''Pentecoste''.jpg"><img resource="./File:Denys_Savchenko_''Pentecoste''.jpg" src="./Special:FilePath/Denys_Savchenko_''Pentecoste''.jpg" height="220" width="220"/></a></span></p>
<p><a rel="mw:WikiLink" href="''Pentecoste''" title="''Pentecoste''">''Pentecoste''</a></p>
<p><a rel="mw:WikiLink" href="''Pentecoste''" title="''Pentecoste''">Pentecoste</a></p>
<p><a rel="mw:WikiLink" href="''Pentecoste''" title="''Pentecoste''"><i>Pentecoste</i></a></p>
!! end

!! test
Broken image links with HTML captions (bug 39700)
!! wikitext
[[File:Nonexistent|<script></script>]]
[[File:Nonexistent|100x100px|<script></script>]]
[[File:Nonexistent|&lt;]]
[[File:Nonexistent|a<i>b</i>c]]
!! html/php
<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">&lt;script&gt;&lt;/script&gt;</a>
<a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">&lt;script&gt;&lt;/script&gt;</a>
<a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">&lt;</a>
<a href="/index.php?title=Special:Upload&amp;wpDestFile=Nonexistent" class="new" title="File:Nonexistent">abc</a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span>
<span typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="100" width="100"/></a></span>
<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&lt;span typeof=\"mw:Entity\" data-parsoid=\"{&amp;quot;src&amp;quot;:&amp;quot;&amp;amp;lt;&amp;quot;,&amp;quot;srcContent&amp;quot;:&amp;quot;&lt;&amp;quot;,&amp;quot;dsr&amp;quot;:[107,111,null,null]}\">&amp;lt;&lt;/span>"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span>
<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"a&lt;i data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[134,142,3,4]}\">b&lt;/i>c"}'><a href="./File:Nonexistent"><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220"/></a></span></p>
!! end

!! test
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"></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 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"></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|an">example URL</a>]</p>
!! end

!! test
BUG 2: [[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
BUG 337: Escaped self-links should be bold
!! options
title=[[Bug462]]
!! wikitext
[[Bu&#103;462]] [[Bug462]]
!! html/php
<p><strong class="selflink">Bu&#103;462</strong> <strong class="selflink">Bug462</strong>
</p>
!! html/php+tidy
<p><strong class="selflink">Bug462</strong> <strong class="selflink">Bug462</strong></p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Bug462" title="Bug462">Bug462</a> <a rel="mw:WikiLink" href="./Bug462" title="Bug462">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
<p><strong class="selflink">0</strong>
</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
<p>[[Main Page]] <a href="/wiki/Main_Page" title="Main Page">the main page [it's not very good]</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

!! test
Internal link with ca linktrail, surrounded by bold apostrophes (bug 27473 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 (bug 27473 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 (bug 27473)
!! 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 (bug 27473)
!! 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 (bug 27473)
!! 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'an)">Something'nice</a>
</p>
!! end

!! test
Link with multiple ":" in a subpage-supporting namespace (bug 63636)
!! 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">Test</a></p>
!! end

!! test
Purely hash wikilink
!! options
title=[[User:test/123]]
!! 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
1. Interaction of linktrail and template encapsulation
!! options
parsoid
!! wikitext
{{echo|[[Foo]]}}l
!! html
<p><a rel="mw:WikiLink" href="Foo" title="Foo" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Foo]]"}},"i":0}},"l"]}'>Fool</a></p>
!! end

!! test
2. Interaction of linktrail and template encapsulation
!! options
parsoid
!! wikitext
{{echo|Some [[Fool]]}}s
!! html
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"Some [[Fool]]"}},"i":0}},"s"]}' data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}'>Some </span><a rel="mw:WikiLink" href="./Fool" title="Fool" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Fool"},"sa":{"href":"Fool"},"tail":"s"}'>Fools</a></p>
!! end

!! test
3. Interaction of linktrail and template encapsulation
!! options
parsoid
!! wikitext
{{echo|Some [[Fool]]s are '''bold and foolish'''}}
!! html
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"Some [[Fool]]s are &#39;&#39;&#39;bold and foolish&#39;&#39;&#39;"}},"i":0}}]}' data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}'>Some <a rel="mw:WikiLink" href="./Fool" title="Fool" data-parsoid='{"stx":"simple","a":{"href":"./Fool"},"sa":{"href":"Fool"},"tail":"s"}'>Fools</a> are <b>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
!! html
<p>Aðrir <a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">mótmælendasöfnuðir</a> og
</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-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
!! options
parsoid
!! wikitext
[[Foo|{{echo|a}} b {{echo|c}}]]
!! html
<p><a rel="mw:WikiLink" href="Foo" title="Foo"><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span> b <span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"c"}},"i":0}}]}'>c</span></a></p>
!! end

!! test
Link with angle bracket after anchor
!! wikitext
[[Foo#<bar>]]
!! html/php
<p><a href="/wiki/Foo#.3Cbar.3E" title="Foo">Foo#&lt;bar&gt;</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo#%3Cbar%3E" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo#%3Cbar%3E"},"sa":{"href":"Foo#&lt;bar>"}}'>Foo#&lt;bar></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:ExtLink" 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 (bug 2372)
!! 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:ExtLink" href="http://www.usemod.com/cgi-bin/mb.pl?" title="meatball:">MeatBall:</a></p>
!! end

!! test
Interwiki link encoding conversion (bug 1636)
!! wikitext
*[[Wikipedia:ro:Olteni&#0355;a]]
*[[Wikipedia:ro:Olteni&#355;a]]
!! html
<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+tidy
<ul>
<li><a href="http://en.wikipedia.org/wiki/ro:Olteni%C5%A3a" class="extiw" title="wikipedia:ro:Olteniţa">Wikipedia:ro:Olteniţ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ţa</a></li>
</ul>
!! end

!! test
Interwiki link with fragment (bug 2130)
!! 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

# 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:ExtLink" 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:ExtLink" 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:ExtLink" 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:ExtLink" 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:ExtLink" 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:ExtLink" 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:ExtLink" 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 ? 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:ExtLink" href="http://www.usemod.com/cgi-bin/mb.pl?ok" title="meatball:ok">meatball:ok</a>
<a rel="mw:ExtLink" href="http://www.usemod.com/cgi-bin/mb.pl?ok#foo" title="meatball:ok">ok with fragment</a>
<a rel="mw:ExtLink" href="http://www.usemod.com/cgi-bin/mb.pl?ok_as_well?" title="meatball:ok as well?">ok ending with ? mark</a>
<a rel="mw:ExtLink" href="http://de.wikipedia.org/wiki/Foo?action=history">has query</a>
<a rel="mw:ExtLink" href="http://de.wikipedia.org/wiki/#foo">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:ExtLink" 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><strong class="selflink">local:Main Page</strong>
</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 (bug 64167)
!! 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 (bug 61357)
!! 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:ExtLink" 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

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

!! test
Interlanguage link
!! 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
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
!! options
parsoid=wt2html,wt2wt,html2html
!! 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
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
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 (bug 8897)
!! 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 (bug 32189 / 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

!! 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 bug 53221: Wikilinks should be properly entity-escaped
!! options
parsoid=html2wt
!! 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]]
!! end

!! test
Parsoid: handle constructor well
!! 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="{&quot;stx&quot;:&quot;simple&quot;,&quot;a&quot;:{&quot;href&quot;:&quot;./Constructor&quot;},&quot;sa&quot;:{&quot;href&quot;:&quot;constructor&quot;}}">constructor</a></p>

<p><a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid="{&quot;stx&quot;:&quot;simple&quot;,&quot;a&quot;:{&quot;href&quot;:&quot;./Foo&quot;},&quot;sa&quot;:{&quot;href&quot;:&quot;constructor:foo&quot;}}">constructor:foo</a></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:ExtLink" 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 (bug 45209)
!! 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 (bug 68085)
!! 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:ExtLink" 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
!! wikitext
#REDIRECT [[<nowiki>[[Bar]]</nowiki>]]
!! html/parsoid
<ol><li data-parsoid>REDIRECT [[[[Bar]]]]</li></ol>
!! end

!! test
4. Redirect to a templated destination
!! wikitext
#REDIRECT [[{{echo|Foo}}bar]]
!! html/parsoid
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/redirect" href="./Foobar" data-mw='{"attribs":[[{"txt":"href"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;dsr&amp;quot;:[12,24,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;Foo&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">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

# FIXME: Should hoist the redirect to the top of the page and ensure there
# is only one.
!! test
New redirect
!! options
parsoid=html2wt
!! html/parsoid
<p>Foo<link rel="mw:PageProp/redirect" href="./Foo"/></p>
!! wikitext
Foo
#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
!! wikitext
</br>
!! html/php
<p>&lt;/br&gt;
</p>
!! end

# TODO: Fix html2html mode (bug 51055)!
!! 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

## FIXME: Is Parsoid's acceptance of self-closing html-tags
## a feature or a bug? See https://phabricator.wikimedia.org/T76962
!! 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/php
<p>&lt;div title /&gt;
&lt;div title/&gt;
</p>
<div>
<p>&lt;div title=bar /&gt;
&lt;div title=bar/&gt;
</p>
<div title="bar/"></div>
</div>

!! html/parsoid
<div title="" data-parsoid='{"stx":"html","selfClose":true}'></div>
<div title="" data-parsoid='{"stx":"html","selfClose":true}'></div>
<div title="" data-parsoid='{"stx":"html","selfClose":true,"brokenHTMLTag":true}'></div>
<div title="bar" data-parsoid='{"stx":"html","selfClose":true}'></div>
<div title="bar" data-parsoid='{"stx":"html","selfClose":true}'></div>
<div title="bar/" data-parsoid='{"stx":"html","autoInsertedEnd":true}'></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
<p><br title="" />
<br title="" />
<br />
<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
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>
!! 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
<hr /> Foo

!! html+tidy
<hr />
<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

!! 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
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></li></ul></li>
<li>bar</li></ul>

!! end

!! test
Nested lists 5 (both elements empty)
!! wikitext
**
*
!! html
<ul><li><ul><li></li></ul></li>
<li></li></ul>

!! end

!! test
Nested lists 6 (both elements empty)
!! wikitext
*
**
!! html
<ul><li>
<ul><li></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

!! test
Nested lists 9 (extension interaction)
!! options
parsoid
!! wikitext
*<references />
!! html/parsoid
<ul><li data-parsoid='{}'><ol class="mw-references" typeof="mw:Extension/references" about="#mwt2" data-parsoid='{}' data-mw='{"name":"references","attrs":{}}'></ol></li></ul>
!! 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>

!! end

!! test
2. Lists with start-of-line-transparent tokens before bullets: Template close
!! wikitext
*foo {{echo|bar
}}*baz
!! html
<ul><li>foo bar</li>
<li>baz</li></ul>

!! end

!! test
List items are not parsed correctly following a <pre> block (bug 785)
!! 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 data-parsoid='{"stx":"html"}'>foo</pre></li>
<li> <pre data-parsoid='{"stx":"html"}'>bar</pre></li>
<li> zar</li></ul>
!! end

!! 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
{{echo|<li>}}a
{{echo|<li>}}b
{{echo|<li>}}c
!! html
<li>a
<li>b
<li>c</li>
</li>
</li>

!! html+tidy
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
!!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

!!test
Test the li-hack
(The PHP parser relies on Tidy for the hack)
!!options
parsoid=wt2html,wt2wt
!! wikitext
* foo
* <li>li-hack
* {{echo|<li>templated li-hack}}
* <!--foo--> <li> unsupported li-hack with preceding comments

<ul>
<li><li>not a li-hack
</li>
</ul>
!! html+tidy
<ul>
<li>foo</li>
<li>li-hack</li>
<li>templated li-hack</li>
<li>unsupported li-hack with preceding comments</li>
</ul>
<ul>
<li>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
!! options
parsoid
!! wikitext
# foo
## bar
* foo
** bar
: foo
:: bar
!! html
<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
!! wikitext
* {{bullet}}
!! html
<ul>
<li> </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
(php parser relies on Tidy to fix up)
!! wikitext
<div>
*a</div><div>
*b</div>
!! html+tidy
<div>
<ul>
<li>a</li>
</ul>
</div>
<div>
<ul>
<li>b</li>
</ul>
</div>
!! end

# Parsoid fails this test, but it might be tricky to support properly.
# See bug 68395.
!! test
Unbalanced closing non-block tags don't break a list
(php parser relies on Tidy to fix up)
!! wikitext
<span>
*a</span><span>
*b</span>
!! html/php+tidy
<ul>
<li><span>a</span></li>
<li><span>b</span></li>
</ul>
!! html/parsoid
<span>
<ul>
<li>a<span></span>
</li>
<li>b
</li>
</ul>
</span>
!! end

!! test
Unclosed formatting tags that straddle lists are closed and reopened
(php parser relies on Tidy to fix up)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
# <s> a
# b </s>
!! html/php+tidy
<ol>
<li><s>a</s></li>
<li><s>b</s></li>
</ol>
!! html/parsoid
<ol><li> <s> a</s></li>
<li><s> b </s></li></ol>
!! end

# See bug 68395.
!!test
1. List embedded in a formatting tag
!! wikitext
<small>
* foo
</small>
!! html/php+tidy
<ul>
<li><small>foo</small></li>
</ul>
!! html/parsoid
<small>
<ul>
<li> foo</li>
</ul>
</small>
!!end

## Ugly Parsoid output here
## Not sure what the right output is.
!!test
2. List embedded in a formatting tag
!! wikitext
<small>
*a
*b</small>
!! html/php+tidy
<ul>
<li><small>a</small></li>
<li><small>b</small></li>
</ul>
!! html/parsoid
<small></small>
<ul><small>
<li>a</li>
</small>
<li><small>b</small></li>
</ul>
!!end

# Ugly Parsoid and PHP parser output here
# Not sure if we want to make this a test!
#
## !!test
## 3. Unclosed formatting tags in list elements
## !! wikitext
## *<small>a
## *<small>b
## !! html/php+tidy
## <ul>
## <li><small>a</small></li>
## <li><small><small>b</small></small></li>
## </ul>
## !! html/parsoid
## <ul>
## <li><small>a</small></li>
## <small>
## <li><small>b</small></li>
## </small></ul>
## !!end

# This is a bug in the PHP parser + tidy combination.
# (The </tr> tag gets parsed as text and html-escaped by PHP,
# and then fostered out of the table by tidy.)
# We believe the Parsoid output to be correct.
!! test
Table with missing opening <tr> tag
!! options
parsoid=wt2html,wt2wt
!! wikitext
<table>
<td>foo</td>
</tr>
</table>
!! html+tidy
<table>
<tr>
<td>foo</td>
</tr>
</table>
!! 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}} (@bug 4594)
!! 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]]
!! wikitext
{{FULLPAGENAME}}
!! html
<p>User:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{FULLPAGENAMEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! 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]]
!! wikitext
{{TALKSPACE}}
!! html
<p>User talk
</p>
!! end

!! test
Magic Word: {{TALKSPACE}}, same namespace
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{TALKSPACE}}
!! html
<p>User talk
</p>
!! end

!! test
Magic Word: {{TALKSPACE}}, main namespace
!! options
title=[[Parser Test]]
!! wikitext
{{TALKSPACE}}
!! html
<p>Talk
</p>
!! end

!! test
Magic Word: {{TALKSPACEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{TALKSPACEE}}
!! html
<p>User_talk
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{SUBJECTSPACE}}
!! html
<p>User
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}, same namespace
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{SUBJECTSPACE}}
!! html
<p>User
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}, main namespace
!! options
title=[[Parser Test]]
!! wikitext
{{SUBJECTSPACE}}
!! html

!! end

!! test
Magic Word: {{SUBJECTSPACEE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{SUBJECTSPACEE}}
!! html
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{NAMESPACE}}
!! html
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{NAMESPACEE}}
!! html
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACENUMBER}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{NAMESPACENUMBER}}
!! html
<p>2
</p>
!! end

!! test
Magic Word: {{SUBPAGENAME}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub ö]] subpage
!! wikitext
{{SUBPAGENAME}}
!! html
<p>sub ö
</p>
!! end

!! test
Magic Word: {{SUBPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub ö]] subpage
!! wikitext
{{SUBPAGENAMEE}}
!! html
<p>sub_%C3%B6
</p>
!! end

!! test
Magic Word: {{ROOTPAGENAME}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub/sub2]] subpage
!! wikitext
{{ROOTPAGENAME}}
!! html
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{ROOTPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub/sub2]] subpage
!! 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
!! wikitext
{{BASEPAGENAME}}
!! html
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{BASEPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub]] subpage
!! 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]]
!! wikitext
{{TALKPAGENAME}}
!! html
<p>User talk:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{TALKPAGENAMEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! 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]]
!! wikitext
{{SUBJECTPAGENAME}}
!! html
<p>User:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{SUBJECTPAGENAMEE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{SUBJECTPAGENAMEE}}
!! html
<p>User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{NUMBEROFFILES}}
!! wikitext
{{NUMBEROFFILES}}
!! html
<p>5
</p>
!! end

!! test
Magic Word: {{PAGENAME}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{PAGENAME}}
!! html
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{PAGENAME}} with metacharacters
!! options
title=[['foo & bar = baz']]
!! wikitext
''{{PAGENAME}}''
!! html/php
<p><i>&#39;foo &#38; bar &#61; baz&#39;</i>
</p>
!! html+tidy
<p><i>'foo &amp; bar = baz'</i></p>
!! end

!! test
Magic Word: {{PAGENAME}} with metacharacters (bug 26781)
!! options
title=[[*RFC 1234 http://example.com/]]
!! wikitext
{{PAGENAME}}
!! html/php
<p>&#42;RFC&#32;1234 http&#58;//example.com/
</p>
!! html+tidy
<p>*RFC 1234 http://example.com/</p>
!! end

!! test
Magic Word: {{PAGENAMEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
!! wikitext
{{PAGENAMEE}}
!! html
<p>%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{PAGENAMEE}} with metacharacters (bug 26781)
!! options
title=[[*RFC 1234 http://example.com/]]
!! wikitext
{{PAGENAMEE}}
!! html/php
<p>&#42;RFC_1234_http&#58;//example.com/
</p>
!! html+tidy
<p>*RFC_1234_http://example.com/</p>
!! end

!! test
Magic Word: {{REVISIONID}}
!! wikitext
{{REVISIONID}}
!! html
<p>1337
</p>
!! end

!! test
Magic Word: {{SCRIPTPATH}}
!! wikitext
{{SCRIPTPATH}}
!! html
<p>/
</p>
!! end

!! test
Magic Word: {{STYLEPATH}}
!! wikitext
{{STYLEPATH}}
!! html
<p>/skins
</p>
!! end

!! test
Magic Word: {{SERVER}}
!! wikitext
{{SERVER}}
!! html
<p><a rel="nofollow" class="external free" href="http://example.org">http://example.org</a>
</p>
!! end

!! test
Magic Word: {{SERVERNAME}}
!! wikitext
{{SERVERNAME}}
!! html
<p>example.org
</p>
!! end

!! test
Magic Word: {{SITENAME}}
!! wikitext
{{SITENAME}}
!! html
<p>MediaWiki
</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
!! wikitext
{{DISPLAYTITLE:''{{PAGENAME}}''}}
!! html/parsoid
<meta property="mw:PageProp/displaytitle" content="Main Page" about="#mwt2" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"content"},{"html":"&lt;i data-parsoid=\"{&amp;quot;dsr&amp;quot;:[15,31,2,2]}\">&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;pi&amp;quot;:[[]],&amp;quot;dsr&amp;quot;:[17,29,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;PAGENAME&amp;quot;,&amp;quot;function&amp;quot;:&amp;quot;pagename&amp;quot;},&amp;quot;params&amp;quot;:{},&amp;quot;i&amp;quot;:0}}]}\">Main Page&lt;/span>&lt;/i>"}]]}'/>
!! end

!! test
Parsoid: Template-generated DISPLAYTITLE
!! wikitext
{{{{echo|DISPLAYTITLE}}:Foo}}
!! html/parsoid
<meta property="mw:PageProp/displaytitle" content="Foo" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,29,null,null],"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"{{echo|DISPLAYTITLE}}:Foo"},"params":{},"i":0}}]}'/>
!! 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}} (bug 4783)
!! wikitext
{{ns:0}}
!! html

!! end

!! test
Namespace 0 {{ns:00}} (bug 4783)
!! 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
<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: 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 (bug 479)
!! 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">RFC 123</a></p>
!! end

!! test
Magic links: RFC (bug 479)
!! wikitext
RFC 822
!! html/php
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc822">RFC 822</a>
</p>
!! html/parsoid
<p><a href="//tools.ietf.org/html/rfc822" rel="mw:ExtLink">RFC 822</a></p>
!! end

!! test
Magic links: RFC (bug 65278)
!! wikitext
This is RFC 822 but thisRFC 822 is not RFC 822linked.
!! html/php
<p>This is <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc822">RFC 822</a> but thisRFC 822 is not RFC 822linked.
</p>
!! html/parsoid
<p>This is <a href="//tools.ietf.org/html/rfc822" rel="mw:ExtLink">RFC 822</a> but thisRFC 822 is not RFC 822linked.</p>
!! end

!! test
Magic links: RFC (w/ non-newline whitespace, bug 28950/29025)
!! wikitext
RFC &nbsp;&#160;&#0160;&#xA0;&#Xa0; 822
RFC
822
!! html/php
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc822">RFC 822</a>
RFC
822
</p>
!! html/parsoid
<p><a href="//tools.ietf.org/html/rfc822" rel="mw:ExtLink">RFC <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 822</a>
RFC
822</p>
!! end

!! test
Magic links: ISBN (bug 1937)
!! wikitext
ISBN 0-306-40615-2
!! html/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 (bug 65278)
!! 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, bug 28950/29025)
!! 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">PMID 1234</a></p>
!! end

!! test
Magic links: PMID (bug 65278)
!! 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">PMID 1234</a> but thisPMID 1234 is not PMID 1234linked.</p>
!! end

!! test
Magic links: PMID (w/ non-newline whitespace, bug 28950/29025)
!! 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">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

###
### 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>|{{echo|foo}}|{{echo|a}}={{echo|b}}|a = b}}
!! html
<p>{{a<b>b</b>|foo|a=b|a = b}}
</p>
!! end

!! test
Template with invalid target containing unclosed tag
!! wikitext
{{a<b>|{{echo|foo}}|{{echo|a}}={{echo|b}}|a = b}}
!! html
<p>{{a<b>|foo|a=b|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

!! test
Template with just whitespace in it, bug #68421
!! wikitext
{{echo|{{ }}}}
!! html/parsoid
<p><span typeof="mw:Transclusion mw:Nowiki" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{ }}"}},"i":0}}]}'>{{ }}</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
Template with thumb image (with link in description)
!! wikitext
{{paramtest|param =[[Image:noimage.png|thumb|[[no link|link]] [[no link|caption]]]]}}
!! html/php
This is a test template with parameter <div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/index.php?title=Special:Upload&amp;wpDestFile=Noimage.png" class="new" title="File:Noimage.png">File:Noimage.png</a>  <div class="thumbcaption"><a href="/index.php?title=No_link&amp;action=edit&amp;redlink=1" class="new" title="No link (page does not exist)">link</a> <a href="/index.php?title=No_link&amp;action=edit&amp;redlink=1" class="new" title="No link (page does not exist)">caption</a></div></div></div>

!! html+tidy
<p>This is a test template with parameter</p>
<div class="thumb tright">
<div class="thumbinner" style="width:182px;"><a href="/index.php?title=Special:Upload&amp;wpDestFile=Noimage.png" class="new" title="File:Noimage.png">File:Noimage.png</a>
<div class="thumbcaption"><a href="/index.php?title=No_link&amp;action=edit&amp;redlink=1" class="new" title="No link (page does not exist)">link</a> <a href="/index.php?title=No_link&amp;action=edit&amp;redlink=1" class="new" title="No link (page does not exist)">caption</a></div>
</div>
</div>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"paramtest","href":"./Template:Paramtest"},"params":{"param":{"wt":"[[Image:noimage.png|thumb|[[no link|link]] [[no link|caption]]]]"}},"i":0}}]}'>This is a test template with parameter </p><figure class="mw-default-size" typeof="mw:Error mw:Image/Thumb" about="#mwt1" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:Noimage.png" ><img resource="./File:Noimage.png" src="./Special:FilePath/Noimage.png" height="220" width="220"/></a><figcaption><a rel="mw:WikiLink" href="./No_link" title="No link">link</a> <a rel="mw:WikiLink" href="./No_link" title="No link">caption</a></figcaption></figure>
!! 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
BUG 553: link with two variables in a piped link
!! wikitext
{|
|[[{{{1}}}|{{{2}}}]]
|}
!! html
<table>
<tr>
<td>[[{{{1}}}|{{{2}}}]]
</td></tr></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
<p><span class="error">Template loop detected: <a href="/wiki/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

!! article
Template:table
!! text
{|
| 1 || 2
|-
| 3 || 4
|}
!! endarticle

!! test
BUG 529: Template with table, not included at beginning of line
!! wikitext
foo {{table}}
!! html
<p>foo 
</p>
<table>
<tr>
<td> 1 </td>
<td> 2
</td></tr>
<tr>
<td> 3 </td>
<td> 4
</td></tr></table>

!! end

!! test
BUG 523: Template shouldn't eat newline (or add an extra one before table)
!! wikitext
foo
{{table}}
!! html
<p>foo
</p>
<table>
<tr>
<td> 1 </td>
<td> 2
</td></tr>
<tr>
<td> 3 </td>
<td> 4
</td></tr></table>

!! end

!! test
BUG 41: Template parameters shown as broken links
!! wikitext
{{{parameter}}}
!! html
<p>{{{parameter}}}
</p>
!! end

!! test
Template with targets containing wikilinks
!! wikitext
{{[[foo]]}}

{{[[{{echo|foo}}]]}}

{{{{echo|[[foo}}]]}}
!! html
<p>{{<a href="/wiki/Foo" title="Foo">foo</a>}}
</p><p>{{<a href="/wiki/Foo" title="Foo">foo</a>}}
</p><p>{{[[foo}}]]
</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;"},"params":{},"i":0}}]}'>bar</span> baz
</p>
!! 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>&lt;var&gt;
</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
<p>Foo
</p>
!! end


!! article
Template:Includes3
!! text
<onlyinclude>Foo</onlyinclude>bar<includeonly>zar</includeonly>
!! endarticle

!! test
<onlyinclude> and <includeonly> being included
!! wikitext
{{Includes3}}
!! html
<p>Foo
</p>
!! end

!! test
<includeonly> and <noinclude> on a page
!! wikitext
Foo<noinclude>zar</noinclude><includeonly>bar</includeonly>
!! html
<p>Foozar
</p>
!! end

!! test
Un-closed <noinclude>
!! wikitext
<noinclude>
!! html
!! 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
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>
<tr>
<td>a
</td>
<td>b
</td>
<td>c&lt;/includeonly&gt;
</td>
<td>d&lt;/includeonly&gt;&lt;/includeonly&gt;
</td></tr></table>

!!end

!! article
Template:Includeonly section
!! text
<includeonly>
==Includeonly section==
</includeonly>
==Section T-1==
!!endarticle

!! test
Bug 6563: Edit link generation for section shown by <includeonly>
!! wikitext
{{includeonly section}}
!! html
<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>

!! end

# Uses same input as the contents of [[Template:Includeonly section]]
!! test
Bug 6563: 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
Bug 6563: 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
Bug 6563: 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
!! end

!! test
Includes and comments at SOL
!! wikitext
<!-- comment --><noinclude><!-- comment --></noinclude><!-- comment -->== hu ==

<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>
<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> 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/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>can have stuff&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><h3> here </h3>

!! end

# TODO: test with DOM fragment reuse!
!! test
Parsoid: DOM fragment reuse
!! options
parsoid=wt2wt,wt2html
!! wikitext
a{{echo|b<table></table>c}}d

a{{echo|b
<table></table>
c}}d

{{echo|a

<table></table>

b}}
!! html
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["a",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"b&lt;table>&lt;/table>c"}},"i":0}},"d"]}' data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}'>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":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"b\n&lt;table>&lt;/table>\nc"}},"i":0}},"d"]}' data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}'>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":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n\n&lt;table>&lt;/table>\n\nb"}},"i":0}}]}' data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}'>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)
!! options
parsoid
!! wikitext
{|
|{{echo|{{!}} foo}}
|}
!! html
<table><tbody>
<tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{!}} foo"}},"i":0}}]}'> foo</td></tr>
</tbody></table>
!! end

!! test
Parsoid: Merge double tds in nested transclusion content (T52603)
!! options
parsoid
!! wikitext
{{echo|<div>}}
{|
|{{echo|{{!}} foo}}
|}
{{echo|</div>}}
!! html
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<div>"}},"i":0}},"\n{|\n|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{!}} foo"}},"i":1}},"\n|}\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"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>


<tr>
<td>a
</td></tr>
</table>

!!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 blacklisting 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
{{echo|}}{| width = '100%'
|foo
|}
!!html/parsoid
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":""}},"i":0}}]}'></span><table width="100%">
<tbody><tr><td>foo</td></tr>
</tbody></table>
!!end

!!test
2. Table tag in SOL posn. should get reparsed correctly with valid TSR
!!options
parsoid=wt2html,wt2wt
!!wikitext
<includeonly>a</includeonly>{| {{{b}}}
|c
|}
!!html/parsoid
<meta typeof="mw:Includes/IncludeOnly"/><meta typeof="mw:Includes/IncludeOnly/End"/><table about="#mwt2" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"{{{b}}}","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Param\" data-parsoid=\"{&amp;quot;dsr&amp;quot;:[31,38,null,null],&amp;quot;src&amp;quot;:&amp;quot;{{{b}}}&amp;quot;}\">{{{b}}}&lt;/span>"},{"html":""}]]}' data-parsoid='{"a":{"{{{b}}}":null},"sa":{"{{{b}}}":""}}'>
<tbody><tr><td>c</td></tr>
</tbody></table>

!!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
<p>foo
</p>
!!end

!!test
Templates: Template Name/Arg clash: 2. Use of named param
!! wikitext
{{quote|quote=foo}}
!! html
<p>foo
</p>
!!end

!!test
Templates: Template Name/Arg clash: 3. Use of named param with empty input
!! wikitext
{{quote|quote}}
!! html
<p>quote
</p>
!!end

###
### Parsoid-centric tests to stress Parsoid's ability to RT them unchanged
###

!!test
Templates: 1. Simple use
!! wikitext
{{echo|Foo}}
!! html
<p>Foo
</p>
!!end

!!test
Templates: 2. Inside a block tag
!! wikitext
<div>{{echo|Foo}}</div>
<blockquote>{{echo|Foo}}</blockquote>
!! html
<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
{{echo|Foo}}
{{echo|bar}}
!! html
<p>Foo
bar
</p>
!!end

!!test
Templates: P-wrapping: 1b. Templates on consecutive lines
!! wikitext
Foo

{{echo|bar}}
{{echo|baz}}
!! html
<p>Foo
</p><p>bar
baz
</p>
!!end

!!test
Templates: P-wrapping: 1c. Templates on consecutive lines
!! wikitext
{{echo|Foo}}
{{echo|bar}} <div>baz</div>
!! html
<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
!!options
parsoid
!! wikitext
<!-- foo -->
{{echo|Bar}}
!! html
<!-- foo -->

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

!!test
Templates: Inline Text: 1. Multiple template uses
!! wikitext
{{echo|Foo}}bar{{echo|baz}}
!! html
<p>Foobarbaz
</p>
!!end

!!test
Templates: Inline Text: 2. Back-to-back template uses
!! wikitext
{{echo|Foo}}{{echo|bar}}
!! html
<p>Foobar
</p>
!!end

!!test
Templates: Block Tags: 1. Multiple template uses
!! wikitext
{{echo|<div>Foo</div>}}<div>bar</div>{{echo|<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
{{echo|<div>Foo</div>}}{{echo|<div>bar</div>}}
!! html
<div>Foo</div><div>bar</div>

!!end

# This is an edge case relating to paragraph wrapping.
!!test
Templates: Correctly encapsulate templates producing </p> tag without a corresponding <p> tag
!! wikitext
{{echo|a
b</p>}}
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\nb&lt;/p>"}},"i":0}}]}'>a
b</p>
!!end

!!test
Templates: Links: 1. Simple example
!! wikitext
{{echo|[[Foo|bar]]}}
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

!!test
Templates: Links: 2. Generation of link href
!! wikitext
[[{{echo|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{{echo|o}}|bar]]

[[Foo{{echo|bar}}]]

[[Foo{{echo|bar}}baz]]

[[Foo{{echo|bar}}|bar]]

[[:Foo{{echo|bar}}]]

[[:Foo{{echo|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
[[{{echo|F}}{{echo|o}}ob{{echo|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|{{echo|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
{{echo|[[{{echo|Foo}}|bar]]}}
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

!!test
Templates: HTML Tag: 1. Generation of HTML attr. key
!! wikitext
<div {{echo|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={{echo|'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 {{echo|style}}={{echo|'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="{{echo|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 {{echo|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 {{echo|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{{echo|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 {{echo|1=id="v1"}}>bar</div>
!! html
<div id="v1">bar</div>

!!end

!! test
Templates: HTML Tag: 9. Multiple template-generated attributes
!! wikitext
<div {{echo|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">

<tr>
<td>foo
</td></tr>
<tr>
<td>bar
</td></tr></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
1. Entities and nowikis inside templated attributes should be handled correctly
!! wikitext
<div {{echo|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=\"{&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;dsr&amp;quot;:[5,49,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;style{{=}}\\&amp;quot;background:&amp;amp;#35;f9f9f9;\\&amp;quot;&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">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=\"{&amp;quot;src&amp;quot;:&amp;quot;&amp;amp;#35;&amp;quot;,&amp;quot;srcContent&amp;quot;:&amp;quot;#&amp;quot;}\">#&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>
<tr>
<td style="background:#f9f9f9;">Foo
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td style="background:#f9f9f9;" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"autoInsertedEnd":true,"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>
<tr>
<td style="background:#f9f9f9;">Foo
</td></tr></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>
<tr>
<td style="background: red;"> hi
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr><td style="background:  red;" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"autoInsertedEnd":true,"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
Templates: HTML Tables: 1. Generating start of a HTML table
!! wikitext
{{echo|<table><tr><td>foo</td>}}</tr></table>
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 2a. Generating middle of a HTML table
!! wikitext
<table><tr>{{echo|<td>foo</td>}}</tr></table>
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 2b. Generating middle of a HTML table
!! wikitext
<table>{{echo|<tr><td>foo</td></tr>}}</table>
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 3. Generating end of a HTML table
!! wikitext
<table><tr>{{echo|<td>foo</td></tr></table>}}
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 4a. Generating a single tag of a HTML table
!! wikitext
{{echo|<table>}}<tr><td>foo</td></tr></table>
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 4b. Generating a single tag of a HTML table
!! wikitext
<table>{{echo|<tr>}}<td>foo</td></tr></table>
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 4c. Generating a single tag of a HTML table
!! wikitext
<table><tr>{{echo|<td>}}foo</td></tr></table>
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 4d. Generating a single tag of a HTML table
!! wikitext
<table><tr><td>foo{{echo|</td>}}</tr></table>
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 4e. Generating a single tag of a HTML table
!! wikitext
<table><tr><td>foo</td>{{echo|</tr>}}</table>
!! html
<table><tr><td>foo</td></tr></table>

!!end

!!test
Templates: HTML Tables: 4f. Generating a single tag of a HTML table
!! wikitext
<table><tr><td>foo</td></tr>{{echo|</table>}}
!! html
<table><tr><td>foo</td></tr></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 (Bug 50330)-->
<table>[[Category:bar1]][[Category:bar2]]<tr><td>foo</td></tr></table>
!! html
<link rel="mw:PageProp/Category" href="./Category:Foo1"><table><tbody><tr><td>foo</td></tr></tbody></table>
<!--Two categories (Bug 50330)-->
<link rel="mw:PageProp/Category" href="./Category:Bar1"><link rel="mw:PageProp/Category" href="./Category:Bar2"><table><tbody><tr><td>foo</td></tr></tbody></table>
!!end

!!test
Templates: Wiki Tables: 1a. Fostering of entire template content
!! wikitext
{|
{{echo|a}}
|}
!! html
<table>
a
<tr><td></td></tr></table>

!! html+tidy
<p>a</p>
<table>
<tr>
<td></td>
</tr>
</table>
!! end

!!test
Templates: Wiki Tables: 1b. Fostering of entire template content
!! wikitext
{|
{{echo|<div>}}
foo
{{echo|</div>}}
|}
!! html
<table>
<div>
<p>foo
</p>
</div>
<tr><td></td></tr></table>

!! html+tidy
<div>
<p>foo</p>
</div>
<table>
<tr>
<td></td>
</tr>
</table>
!! end

!!test
Templates: Wiki Tables: 2. Fostering of partial template content
!! wikitext
{|
{{echo|a
<div>b</div>}}
|}
!! html
<table>
a
<div>b</div>
<tr><td></td></tr></table>

!! html+tidy
<p>a</p>
<div>b</div>
<table>
<tr>
<td></td>
</tr>
</table>
!! end

!!test
Templates: Wiki Tables: 3. td-content via multiple templates
!! wikitext
{|
{{echo|{{pipe}}a}}{{echo|b}}
|}
!! html
<table>
<tr>
<td>ab
</td></tr></table>

!!end

!!test
Templates: Wiki Tables: 4. Templated tags, no content
!! wikitext
{{tbl-start}}
{{tbl-end}}
!! html
<table>
<tr><td></td></tr></table>

!!end

!!test
Templates: Wiki Tables: 5. Templated tags, regular td-tags
!! wikitext
{{tbl-start}}
|foo
{{tbl-end}}
!! html
<table>
<tr>
<td>foo
</td></tr></table>

!!end

!!test
Templates: Wiki Tables: 6. Templated tags, templated td-tags
!! wikitext
{{tbl-start}}
{{!}}foo
{{tbl-end}}
!! html
<table>
<tr>
<td>foo
</td></tr></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
<span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Transclusion  mw:Extension/ref" data-mw='{"parts":[{"template":{"target":{"wt":"PartialTable","href":"./Template:PartialTable"},"params":{},"i":0}},"&lt;ref>foo&lt;/ref>\n|}"]}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span><table about="#mwt2">
<tbody>
</tbody></table>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li></ol>
!!end

!! test
Templates: Wiki Tables: 8. Fosterable meta-tags should get fostered
!! wikitext
{{echo|
{{{!}}
{{!}}-}}
<onlyinclude>
|foo
</onlyinclude>
{{!}}}
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n{{{!}}\n{{!}}-"}},"i":0}},"\n&lt;onlyinclude>\n|foo\n&lt;/onlyinclude>\n{{!}}}"]}'>
</span><meta typeof="mw:Includes/OnlyInclude" about="#mwt1"/><table about="#mwt1">
<tbody><tr>

<td>foo
<meta typeof="mw:Includes/OnlyInclude/End"/></td></tr>
</tbody></table>
!! end

!!test
Templates: Lists: Multi-line list-items via templates
!! wikitext
*{{echo|a {{nonexistent|
unused}}}}
*{{echo|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 (echo)
!! wikitext
{{echo|''a}}{{echo|b''c''d}}{{echo|''e}}
!! html
<p><i>ab</i>c<i>d</i>e
</p>
!!end

!!test
Templates: Ugly nesting: 2. Quotes opened/closed across templates (echo_with_span)
(PHP parser generates misnested html)
!! wikitext
{{echo_with_span|''a}}{{echo_with_span|b''c''d}}{{echo_with_span|''e}}
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo_with_span&quot;,&quot;href&quot;:&quot;./Template:Echo_with_span&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;''a&quot;}},&quot;i&quot;:0}}]}"><i>a</i></span><i about="#mwt2" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo_with_span&quot;,&quot;href&quot;:&quot;./Template:Echo_with_span&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;b''c''d&quot;}},&quot;i&quot;:0}},{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo_with_span&quot;,&quot;href&quot;:&quot;./Template:Echo_with_span&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;''e&quot;}},&quot;i&quot;:1}}]}"><span>b</span></i><span about="#mwt2">c</span><i about="#mwt2">d<span></span></i><span about="#mwt2">e</span></p>
!!end

!!test
Templates: Ugly nesting: 3. Quotes opened/closed across templates (echo_with_div)
(PHP parser generates misnested html; Parsoid html2wt mode adds newlines between {{echo}}s)
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{echo_with_div|''a}}{{echo_with_div|b''c''d}}{{echo_with_div|''e}}
!! html
<div about="#mwt1" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo_with_div&quot;,&quot;href&quot;:&quot;./Template:Echo_with_div&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;''a&quot;}},&quot;i&quot;:0}}]}"><i>a</i></div>
<div about="#mwt2" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo_with_div&quot;,&quot;href&quot;:&quot;./Template:Echo_with_div&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;b''c''d&quot;}},&quot;i&quot;:0}}]}"><i>b</i>c<i>d</i></div>
<div about="#mwt3" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo_with_div&quot;,&quot;href&quot;:&quot;./Template:Echo_with_div&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;''e&quot;}},&quot;i&quot;:0}}]}">e</div>
!!end

!!test
Templates: Ugly nesting: 4. Divs opened/closed across templates
!! wikitext
a<div>b{{echo|c</div>d}}e
!! html
a<div>bc</div>de

!! html+tidy
<p>a</p>
<div>bc</div>
<p>de</p>
!! end

!!test
Templates: Ugly templates: 1. Navbox template parses badly leading to table misnesting
(Parsoid-centric)
!! options
parsoid
!! wikitext
{|
|{{echo|foo</table>}}
|bar
|}
!! html
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["{|\n|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo</table>"}},"i":0}},"\n|bar\n|}"]}'>

<tbody>
<tr>
<td>foo</td></tr></tbody></table><span about="#mwt1">
</span><span about="#mwt1">|bar</span><span about="#mwt1">
|}</span>
!!end

!!test
Templates: Ugly templates: 2. Navbox template parses badly leading to table misnesting
(Parsoid-centric)
!! options
parsoid
!! wikitext
<table>
  <tr>
    <td>
    <table>
      <tr>
        <td>1. {{echo|foo </table>}}</td>
        <td> bar </td>
        <td>2. {{echo|baz </table>}}</td>
      </tr>
      <tr>
        <td>abc</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td>xyz</td>
  </tr>
</table>
!! html
<table about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":["<table>\n  <tr>\n    <td>\n    <table>\n      <tr>\n        <td>1. ",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo </table>"}},"i":0}},"</td>\n        <td> bar </td>\n        <td>2. ",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"baz </table>"}},"i":1}},"</td>\n      </tr>\n      <tr>\n        <td>abc</td>\n      </tr>\n    </table>\n    </td>\n  </tr>\n  <tr>\n    <td>xyz</td>\n  </tr>\n</table>"]}'>
  <tbody><tr>
    <td>
    <table>
      <tbody><tr>
        <td>1. foo </td></tr></tbody></table></td>
        <td> bar </td>
        <td>2. baz </td></tr></tbody></table><span about="#mwt2">
      </span><span about="#mwt2">
      </span><span about="#mwt2">
        </span><span about="#mwt2">abc</span><span about="#mwt2">
      </span><span about="#mwt2">
    </span><span about="#mwt2">
    </span><span about="#mwt2">
  </span><span about="#mwt2">
  </span><span about="#mwt2">
    </span><span about="#mwt2">xyz</span><span about="#mwt2">
  </span><span about="#mwt2">
</span>
!!end

!! test
Templates: Ugly templates: 3. newline-only template parameter
!! wikitext
foo {{echo|
}}
!! 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
{{echo|
}}
!! html
<p><br />
</p>
!! end

# Bug 64017 -- 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
{{echo|<table>}}
{{echo|<div>foo}}
{{echo|</table>}}
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;table>"}},"i":0}},"\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;div>foo"}},"i":1}},"\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;/table>"}},"i":2}}]}' data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1","spc":["","","",""]}],[{"k":"1","spc":["","","",""]}],[{"k":"1","spc":["","","",""]}]]}'>foo
</div><table about="#mwt1" data-parsoid='{"stx":"html"}'>
</table>
!! end

# Bug 64017 -- 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
{{echo|<table><tr><td><table>}}
{{echo|<div>}}
{{echo|</div>}}
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;table>&lt;tr>&lt;td>&lt;table>"}},"i":0}},"\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;div>"}},"i":1}},"\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;/div>"}},"i":2}}]}' data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1","spc":["","","",""]}],[{"k":"1","spc":["","","",""]}],[{"k":"1","spc":["","","",""]}]]}'><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
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

###
### 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 bug 89, 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 (bug 1188)
!! 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 (bug 1936)
!! options
pst
!! wikitext
{{subst:commenttest}}
!! html/php
This template has <!-- a comment --> in it.
!! end

!! test
pre-save transform: unclosed tag
!! options
pst noxml
!! wikitext
<nowiki>'''not wiki'''
!! html/php
<nowiki>'''not wiki'''
!! end

!! test
pre-save transform: mixed tag case
!! options
pst noxml
!! wikitext
<NOwiki>'''not wiki'''</noWIKI>
!! html/php
<NOwiki>'''not wiki'''</noWIKI>
!! end

!! test
pre-save transform: unclosed comment in <nowiki>
!! options
pst noxml
!! 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 bug 1936)
!! wikitext
{{Template:dangerous}}
!! html
<p>@<span>Oh no</span>
</p>
!! end

!! test
pre-save transform: comment containing gallery (bug 5024)
!! 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 (bug 3298)
!! options
pst
!! wikitext
{{subst:Includes}}
!! html/php
Foobar
!! end

!! test
pre-save transform: <onlyinclude> in subst (bug 3298)
!! 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

!! test
bug 22297: safesubst: works during PST
!! options
pst
!! wikitext
{{subst:SafeSubstTest}}{{safesubst:SubstTest}}
!! html/php
FoobarFoobar
!! end

!! test
bug 22297: 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
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 comma in title
!! options
pst title=[[Someplace, Somewhere]]
!! wikitext
[[|Otherplace]]
[[Otherplace, Elsewhere|]]
[[Otherplace, Elsewhere, Anywhere|]]
!! html/php
[[Otherplace, Somewhere|Otherplace]]
[[Otherplace, Elsewhere|Otherplace]]
[[Otherplace, Elsewhere, Anywhere|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, bug 30149)
!! 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, bug 30149)
!! 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, bug 30149)
!! 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 (bug 21660)
!! 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
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]]
* <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
pre-save transform: Signature expansion in nowiki tags (bug 93)
!! 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
<p><span typeof="mw:Nowiki">&lt;div&gt;[[foo]]</span></p>
<p>ab</p>
<p>cd</p>
<p>ef</p>
!! end

!! test
Parsoid: Recognize nowiki with odd capitalization
!! options
parsoid=wt2html
!! wikitext
<noWikI ><div>[[foo]]</Nowiki >
!! html
<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 (bug 4926)
!! options
msg
!! wikitext
{{Includes}}
!! html
Foobar
!! end

!! test
message transform: <onlyinclude> in transcluded template (bug 4926)
!! 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

###
### Images
###
### For Parsoid-specific tests, see
#### https://www.mediawiki.org/wiki/Parsoid/MediaWiki_DOM_spec#Images

!! test
Simple image
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[Image:foobar.jpg]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Simple image (using File: namespace, now canonical)
!! wikitext
[[File:Foobar.jpg]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Right-aligned image
!! wikitext
[[File:Foobar.jpg|right]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure>
!! end

!! test
Image with caption
!! wikitext
[[File:Foobar.jpg|right|Caption text]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption text"><img alt="Caption text" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>Caption text</figcaption></figure>
!! end

!! test
Image with caption, bug 53312 #1
!! wikitext
[[File:Foobar.jpg|right|Caption page stuff]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption page stuff"><img alt="Caption page stuff" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>Caption page stuff</figcaption></figure>
!! end

!! test
Image with caption, bug 53312 #2
!! wikitext
[[File:Foobar.jpg|right|Caption page=]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption page="><img alt="Caption page=" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>Caption page=</figcaption></figure>
!! end

!! test
Image with caption, bug 53312 #3
!! wikitext
[[File:Foobar.jpg|right|Caption page=stuff]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption page=stuff"><img alt="Caption page=stuff" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>Caption page=stuff</figcaption></figure>
!! end

!! test
Allow empty links in image captions (Bug 60753)
!! options
thumbsize=220
!! wikitext
[[File:Foobar.jpg|thumb|Caption [[Link1]]
[[]]
[[Link2]]
]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Caption <a href="/index.php?title=Link1&amp;action=edit&amp;redlink=1" class="new" title="Link1 (page does not exist)">Link1</a> [[]] <a href="/index.php?title=Link2&amp;action=edit&amp;redlink=1" class="new" title="Link2 (page does not exist)">Link2</a></div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"caption","ak":"Caption [[Link1]]\n[[]]\n[[Link2]]\n"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>Caption <a rel="mw:WikiLink" href="./Link1" title="Link1" data-parsoid='{"stx":"simple","a":{"href":"./Link1"},"sa":{"href":"Link1"}}'>Link1</a>
[[]]
<a rel="mw:WikiLink" href="./Link2" title="Link2" data-parsoid='{"stx":"simple","a":{"href":"./Link2"},"sa":{"href":"Link2"}}'>Link2</a>
</figcaption></figure>
!! end

!! test
Titles in unlinked images (T23454)
!! wikitext
[[File:Foobar.jpg|link=|stuff]]
!! html/php
<p><img alt="stuff" src="http://example.com/images/3/3a/Foobar.jpg" title="stuff" width="1941" height="220" />
</p>
!! end

!! test
Link with empty target
!! wikitext
[[]]
!! html
<p>[[]]
</p>
!! end

!! test
Image with link trail
!! wikitext
Linktrails should not work for images: [[File:Foobar.jpg]]s
!! html/php
<p>Linktrails should not work for images: <a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>s
</p>
!! html/parsoid
<p>Linktrails should not work for images: <span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span>s</p>
!! end

!! test
Image with empty attribute
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|right||Caption text]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption text"><img alt="Caption text" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>Caption text</figcaption></figure>
!! end

!! test
1. Block image with individual attributes from templates
!! wikitext
[[File:Foobar.jpg|thumb|{{echo|137px}}|This is a caption]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:139px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/137px-Foobar.jpg" width="137" height="16" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/206px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/274px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This is a caption</div></div></div>

!! html/parsoid
<figure typeof="mw:Image/Thumb mw:ExpandedAttrs" about="#mwt2" data-mw='{"attribs":[["thumbnail",{"html":"thumb"}],["width",{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;dsr&amp;quot;:[24,38,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;137px&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">137px&lt;/span>"}]]}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/137px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="16" width="137"/></a><figcaption>This is a caption</figcaption></figure>
!! end

!! test
2. Block Image with individual attributes from templates
!! wikitext
[[File:Foobar.jpg|{{echo|thumb}}|{{echo|137px}}|This is a caption]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:139px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/137px-Foobar.jpg" width="137" height="16" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/206px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/274px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This is a caption</div></div></div>

!! html/parsoid
<figure typeof="mw:Image/Thumb mw:ExpandedAttrs" about="#mwt3" data-mw='{"attribs":[["thumbnail",{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;dsr&amp;quot;:[18,32,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;thumb&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">thumb&lt;/span>"}],["width",{"html":"&lt;span about=\"#mwt2\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;dsr&amp;quot;:[33,47,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;137px&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">137px&lt;/span>"}]]}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/137px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="16" width="137"/></a><figcaption>This is a caption</figcaption></figure>
!! end

!! test
3. Inline image with individual attributes from templates
!! wikitext
[[File:Foobar.jpg|{{echo|50px}}]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" width="50" height="6" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/75px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/100px-Foobar.jpg 2x" /></a>
</p>
!! html/parsoid
<p><span typeof="mw:Image mw:ExpandedAttrs" about="#mwt2" data-parsoid='{"optList":[{"ck":"width","ak":"{{echo|50px}}"}]}' data-mw='{"attribs":[["width",{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;dsr&amp;quot;:[18,31,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;50px&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">50px&lt;/span>"}]]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a></span></p>
!! end

## Parsoid does not provide editing support for images where templates produce multiple image attributes.
## To signal this, we add a 'mw:Placeholder' type to such images. This could change in the future.
!! test
Image with multiple attributes from the same template
!! wikitext
[[File:Foobar.jpg|{{image_attribs}}]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption text"><img alt="Caption text" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image mw:Placeholder"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>Caption text</figcaption></figure>
!! end

!! test
Image with link tails
!! options
thumbsize=220
!! wikitext
123[[File:Foobar.jpg]]456
123[[File:Foobar.jpg|right]]456
123[[File:Foobar.jpg|thumb]]456
!! html/php
<p>123<a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>456
</p>
123<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>456
123<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div></div></div></div>456

!! html/php+tidy
<p>123<a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>456</p>
<p>123</p>
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>
<p>456 123</p>
<div class="thumb tright">
<div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>
<div class="thumbcaption">
<div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>
</div>
</div>
</div>
<p>456</p>
!! html/parsoid
<p>123<span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span>456</p>
<p>123</p><figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure><p>456</p>
<p>123</p><figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a></figure><p>456</p>
!! end

!! test
Image with multiple captions -- only last one is accepted
!! wikitext
[[File:Foobar.jpg|right|Caption1 - ignored|[[Caption2]] - ignored|Caption3 - accepted]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption3 - accepted"><img alt="Caption3 - accepted" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>Caption3 - accepted</figcaption></figure>
!! end

!! test
Image with multiple widths -- use last
!! wikitext
[[File:Foobar.jpg|200px|300px|caption]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="caption"><img alt="caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" width="300" height="34" 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>
</p>
!! html/parsoid
<p><span typeof="mw:Image" data-mw='{"caption":"caption"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300"/></a></span></p>
!! end

!! test
Image with multiple alignments -- use first (bug 48664)
!! options
thumbsize=220
!! wikitext
[[File:Foobar.jpg|thumb|left|right|center|caption]]

[[File:Foobar.jpg|middle|text-top|caption]]
!! html/php
<div class="thumb tleft"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>caption</div></div></div>
<p><a href="/wiki/File:Foobar.jpg" class="image" title="caption"><img alt="caption" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" style="vertical-align: middle" /></a>
</p>
!! html/parsoid
<figure class="mw-default-size mw-halign-left" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
<p><span class="mw-default-size mw-valign-middle" typeof="mw:Image" data-mw='{"caption":"caption"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Image with width attribute at different positions
!! wikitext
[[File:Foobar.jpg|200px|right|Caption]]
[[File:Foobar.jpg|right|200px|Caption]]
[[File:Foobar.jpg|right|Caption|200px]]
!! html/php
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption"><img alt="Caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a></div>
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption"><img alt="Caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a></div>
<div class="floatright"><a href="/wiki/File:Foobar.jpg" class="image" title="Caption"><img alt="Caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a></div>

!! html/parsoid
<figure class="mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="23" width="200"/></a><figcaption>Caption</figcaption></figure>
<figure class="mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="23" width="200"/></a><figcaption>Caption</figcaption></figure>
<figure class="mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="23" width="200"/></a><figcaption>Caption</figcaption></figure>
!! end

# a sad bit of backward-compatibility
!! test
Image with size specified with pxpx (bug 13500, 51628)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|20pxpx]]
[[File:Foobar.jpg|200x20pxpx]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/20px-Foobar.jpg" width="20" height="2" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/30px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/40px-Foobar.jpg 2x" /></a>
<a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/177px-Foobar.jpg" width="177" height="20" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/265px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/353px-Foobar.jpg 2x" /></a>
</p>
!! html/parsoid
<p><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/20px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="2" width="20"/></a></span> <span typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/177px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="177"/></a></span></p>
!! end

!! test
Image with link parameter, wiki target
!! wikitext
[[File:Foobar.jpg|link=Main Page]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image"><a href="Main_Page"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

# parsoid bug 49293 (part 1)
!! test
Image with link parameter, URL target
!! wikitext
[[File:Foobar.jpg|link=http://example.com/]]
!! html/php
<p><a href="http://example.com/" rel="nofollow"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image"><a href="http://example.com/"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

# parsoid bug 49293 (part 2)
!! test
Image with link parameter, protocol-less URL target
!! wikitext
[[File:Foobar.jpg|link=//example.com/]]
!! html/php
<p><a href="//example.com/" rel="nofollow"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image"><a href="//example.com/"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Escaping non-block captions (T107435)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["[typeof~='mw:Image']", "attr", "data-mw", "{\"caption\": \"|\"}"]
  ]
}
!! wikitext
[[Image:Foobar.jpg|caption]]
!! wikitext/edited
[[Image:Foobar.jpg|<nowiki>|</nowiki>]]
!! end

!! test
Image with link parameter, wgExternalLinkTarget
!! wikitext
[[Image:foobar.jpg|link=http://example.com/]]
!! config
wgExternalLinkTarget='foobar'
!! html
<p><a href="http://example.com/" target="foobar" rel="nofollow"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end

!! test
Image with link parameter, wgNoFollowLinks set to false
!! wikitext
[[Image:foobar.jpg|link=http://example.com/]]
!! config
wgNoFollowLinks=false
!! html
<p><a href="http://example.com/"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end

!! test
Image with link parameter, wgNoFollowDomainExceptions
!! wikitext
[[Image:foobar.jpg|link=http://example.com/]]
!! config
wgNoFollowDomainExceptions='example.com'
!! html
<p><a href="http://example.com/"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end

!! test
Image with link parameter, wgExternalLinkTarget, unnamed parameter
!! wikitext
[[Image:foobar.jpg|link=http://example.com/|Title]]
!! config
wgExternalLinkTarget='foobar'
!! html
<p><a href="http://example.com/" title="Title" target="foobar" rel="nofollow"><img alt="Title" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end

!! test
Image with empty link parameter
!! wikitext
[[File:Foobar.jpg|link=]]
!! html/php
<p><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" />
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image"><span><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></span></span></p>
!! end

!! test
Image with link parameter (wiki target) and unnamed parameter
!! wikitext
[[File:Foobar.jpg|link=Main_Page|Title]]
!! html/php
<p><a href="/wiki/Main_Page" title="Title"><img alt="Title" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"Title"}'><a href="Main_Page"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Image with link parameter (URL target) and unnamed parameter
!! wikitext
[[File:Foobar.jpg|link=http://example.com/|Title]]
!! html/php
<p><a href="http://example.com/" title="Title" rel="nofollow"><img alt="Title" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"Title"}'><a href="http://example.com/"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Thumbnail image with link parameter
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb|link=http://example.com/|Title]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="http://example.com/"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Title</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="http://example.com/"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>Title</figcaption></figure>
!! end

!! test
Manually-specified thumbnail image
!! options
thumbsize=220
!! wikitext
[[File:Foobar.jpg|thumb=Thumb.png|Title]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:137px;"><a href="/wiki/File:Foobar.jpg"><img alt="" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" class="thumbimage" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Title</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb" data-mw='{"thumb":"Thumb.png"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/e/ea/Thumb.png" data-file-width="135" data-file-height="135" data-file-type="bitmap" height="135" width="135"/></a><figcaption>Title</figcaption></figure>
!! end

!! test
Manually-specified thumbnail image with explicit link to wiki page
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb=Thumb.png|link=Main_Page|Title]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:137px;"><a href="/wiki/Main_Page" title="Main Page"><img alt="" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" class="thumbimage" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Title</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb" data-mw='{"thumb":"Thumb.png"}'><a href="Main_Page"><img resource="./File:Foobar.jpg" src="//example.com/images/e/ea/Thumb.png" data-file-width="135" data-file-height="135" data-file-type="bitmap" height="135" width="135"/></a><figcaption>Title</figcaption></figure>
!! end

!! test
Manually-specified thumbnail image with explicit link to url
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb=Thumb.png|link=http://example.com|Title]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:137px;"><a href="http://example.com"><img alt="" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" class="thumbimage" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Title</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb" data-mw='{"thumb":"Thumb.png"}'><a href="http://example.com"><img resource="./File:Foobar.jpg" src="//example.com/images/e/ea/Thumb.png" data-file-width="135" data-file-height="135" data-file-type="bitmap" height="135" width="135"/></a><figcaption>Title</figcaption></figure>
!! end

!! test
Manually-specified thumbnail image with explicit no link
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb=Thumb.png|link=|Title]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:137px;"><img alt="" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" class="thumbimage" />  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Title</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb" data-mw='{"thumb":"Thumb.png"}'><span><img resource="./File:Foobar.jpg" src="//example.com/images/e/ea/Thumb.png" data-file-width="135" data-file-height="135" data-file-type="bitmap" height="135" width="135"/></span><figcaption>Title</figcaption></figure>
!! end

!! test
Manually-specified thumbnail image with explicit link and alt text
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb=Thumb.png|link=Main_Page|alt=alttext|Title]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:137px;"><a href="/wiki/Main_Page" title="Main Page"><img alt="alttext" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" class="thumbimage" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Title</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb" data-mw='{"thumb":"Thumb.png"}'><a href="Main_Page"><img alt="alttext" resource="./File:Foobar.jpg" src="//example.com/images/e/ea/Thumb.png" data-file-width="135" data-file-height="135" data-file-type="bitmap" height="135" width="135"/></a><figcaption>Title</figcaption></figure>
!! end

!! test
Image with frame and link
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|frame|left|This is a test image [[Main Page]]]]
!! html/php
<div class="thumb tleft"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption">This is a test image <a href="/wiki/Main_Page" title="Main Page">Main Page</a></div></div></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-left" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>This is a test image <a rel="mw:WikiLink" href="Main_Page" title="Main Page">Main Page</a></figcaption></figure>
!! end

!! test
Image with frame and link and explicit alt
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[Image:Foobar.jpg|frame|left|This is a test image [[Main Page]]|alt=Altitude]]
!! html/php
<div class="thumb tleft"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Altitude" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption">This is a test image <a href="/wiki/Main_Page" title="Main Page">Main Page</a></div></div></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-left" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img alt="Altitude" resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>This is a test image <a rel="mw:WikiLink" href="Main_Page" title="Main Page">Main Page</a></figcaption></figure>
!! end

!! test
Image with wiki markup in implicit alt
!! wikitext
[[Image:Foobar.jpg|testing '''bold''' in alt]]

[[Image:Foobar.jpg|alt=testing '''bold''' in alt]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="testing bold in alt"><img alt="testing bold in alt" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p><p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="testing bold in alt" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"testing &lt;b data-parsoid=\"{&amp;quot;dsr&amp;quot;:[27,37,3,3]}\">bold&lt;/b> in alt"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"Image:Foobar.jpg"}}'/></a></span></p>
<p><span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img alt="testing bold in alt" resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"alt":"testing bold in alt","resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"alt":"alt=testing &#39;&#39;&#39;bold&#39;&#39;&#39; in alt","resource":"Image:Foobar.jpg"}}'/></a></span></p>
!! end

!! test
Alt image option should handle most kinds of wikitext without barfing
!! wikitext
[[Image:Foobar.jpg|thumb|This is the image caption|alt=This is a [[link]] and a {{echo|''bold template''}}.]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="This is a link and a bold template." src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This is the image caption</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb mw:ExpandedAttrs" about="#mwt2" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"caption","ak":"This is the image caption"},{"ck":"alt","ak":"alt=This is a [[link]] and a {{echo|&#39;&#39;bold template&#39;&#39;}}."}]}' data-mw='{"attribs":[["thumbnail",{"html":"thumb"}],["alt",{"html":"alt=This is a &lt;a rel=\"mw:WikiLink\" href=\"./Link\" title=\"Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;./Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;link&amp;quot;},&amp;quot;dsr&amp;quot;:[65,73,2,2]}\">link&lt;/a> and a &lt;i about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=\"{&amp;quot;dsr&amp;quot;:[80,106,null,null],&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;&#39;&#39;bold template&#39;&#39;&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">bold template&lt;/i>."}]]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img alt="This is a link and a bold template." resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"alt":"This is a link and a bold template.","resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"alt":"alt=This is a [[link]] and a {{echo|&#39;&#39;bold template&#39;&#39;}}.","resource":"Image:Foobar.jpg"}}'/></a><figcaption>This is the image caption</figcaption></figure>
!! end

###################
# Conflicting image format options.
# First option specified should 'win'.
# All three cases in each test should be identical.

!! test
Image with 'frameless' first.
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|frameless|caption]]

[[File:Foobar.jpg|frameless|frame|caption]]

[[File:Foobar.jpg|frameless|thumb|caption]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="caption"><img alt="caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>
</p><p><a href="/wiki/File:Foobar.jpg" class="image" title="caption"><img alt="caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>
</p><p><a href="/wiki/File:Foobar.jpg" class="image" title="caption"><img alt="caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image/Frameless" data-mw='{"caption":"caption"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a></span></p>
<p><span class="mw-default-size" typeof="mw:Image/Frameless" data-mw='{"caption":"caption"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a></span></p>
<p><span class="mw-default-size" typeof="mw:Image/Frameless" data-mw='{"caption":"caption"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a></span></p>
!! end

!! test
Image with 'frame' first.
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|frame|caption]]
[[File:Foobar.jpg|frame|frameless|caption]]
[[File:Foobar.jpg|frame|thumb|caption]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption">caption</div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption">caption</div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption">caption</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>caption</figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>caption</figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>caption</figcaption></figure>
!! end

!! test
Image with 'thumb' first.
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb|caption]]
[[File:Foobar.jpg|thumb|frameless|caption]]
[[File:Foobar.jpg|thumb|frame|caption]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>caption</div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>caption</div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>caption</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
!! end

###################
# Image sizing.
# See https://www.mediawiki.org/wiki/Help:Images#Size_and_frame
# and https://phabricator.wikimedia.org/T64258
# Foobar has actual size of 1941x220
# 1. Thumbs & frameless always reduce, can't be enlarged unless it's
#    a scalable format.
# 2. Framed images always ignore size options; always render at default size.
# 3. "Unspecified format" and border are the only types which can be
#    enlarged.

!! test
Image: "unspecified format" and border enlarge
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|2000px]]

[[File:Foobar.jpg|border|2000px]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="2000" height="227" /></a>
</p><p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="2000" height="227" class="thumbborder" /></a>
</p>
!! html/parsoid
<p><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1941px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="227" width="2000"/></a></span></p>
<p><span class="mw-image-border" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1941px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="227" width="2000"/></a></span></p>
!! end

!! test
Image: "unspecified format" and border reduce
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|1000px]]

[[File:Foobar.jpg|border|1000px]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/1000px-Foobar.jpg" width="1000" height="113" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/1500px-Foobar.jpg 1.5x, http://example.com/images/3/3a/Foobar.jpg 2x" /></a>
</p><p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/1000px-Foobar.jpg" width="1000" height="113" class="thumbborder" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/1500px-Foobar.jpg 1.5x, http://example.com/images/3/3a/Foobar.jpg 2x" /></a>
</p>
!! html/parsoid
<p><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1000px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="113" width="1000"/></a></span></p>
<p><span class="mw-image-border" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1000px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="113" width="1000"/></a></span></p>
!! end

!! test
Image: thumbs reduce
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb|50px]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:52px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" width="50" height="6" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/75px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/100px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div></div></div></div>

!! html/parsoid
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a></figure>
!! end

!! test
Image: bitmap thumbs can't be enlarged past original size, but vector can.
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb|2000px]]

[[File:Foobar.svg|thumb|2000px]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div></div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:2002px;"><a href="/wiki/File:Foobar.svg" class="image"><img alt="Foobar.svg" src="http://example.com/images/thumb/f/ff/Foobar.svg/2000px-Foobar.svg.png" width="2000" height="1500" class="thumbimage" srcset="http://example.com/images/thumb/f/ff/Foobar.svg/3000px-Foobar.svg.png 1.5x, http://example.com/images/thumb/f/ff/Foobar.svg/4000px-Foobar.svg.png 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.svg" class="internal" title="Enlarge"></a></div></div></div></div>

!! html/parsoid
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1941px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure>
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.svg"><img resource="./File:Foobar.svg" src="//example.com/images/thumb/f/ff/Foobar.svg/240px-Foobar.svg" data-file-width="240" data-file-height="180" data-file-type="drawing" height="1500" width="2000"/></a></figure>
!! end

!! test
Image: frameless can reduce in size
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|frameless|50px]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" width="50" height="6" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/75px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/100px-Foobar.jpg 2x" /></a>
</p>
!! html/parsoid
<p><span typeof="mw:Image/Frameless"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a></span></p>
!! end

!! test
Image: bitmap frameless can't be enlarged past original size, but vector can
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|frameless|2000px]]

[[File:Foobar.svg|frameless|2000px]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p><p><a href="/wiki/File:Foobar.svg" class="image"><img alt="Foobar.svg" src="http://example.com/images/thumb/f/ff/Foobar.svg/2000px-Foobar.svg.png" width="2000" height="1500" srcset="http://example.com/images/thumb/f/ff/Foobar.svg/3000px-Foobar.svg.png 1.5x, http://example.com/images/thumb/f/ff/Foobar.svg/4000px-Foobar.svg.png 2x" /></a>
</p>
!! html/parsoid
<p><span typeof="mw:Image/Frameless"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/1941px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
<p><span typeof="mw:Image/Frameless"><a href="./File:Foobar.svg"><img resource="./File:Foobar.svg" src="//example.com/images/thumb/f/ff/Foobar.svg/240px-Foobar.svg" data-file-width="240" data-file-height="180" data-file-type="drawing" height="1500" width="2000"/></a></span></p>
!! end

!! test
Image: framed images are always unscaled.
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|frame]]

[[File:Foobar.jpg|frame|50px]]

[[File:Foobar.jpg|frame|50x50px]]

[[File:Foobar.jpg|frame|2000px]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption"></div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption"></div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption"></div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:1943px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="thumbimage" /></a>  <div class="thumbcaption"></div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure>
<figure typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure>
<figure typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure>
<figure typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></figure>
!! end

###################

!! test
Link to image page- image page normally doesn't exists, hence edit link
Add test with existing image page
#<p><a href="/wiki/File:Test" title="Image:Test">Image:test</a>
!! wikitext
[[:Image:test]]
!! html
<p><a href="/index.php?title=File:Test&amp;action=edit&amp;redlink=1" class="new" title="File:Test (page does not exist)">Image:test</a>
</p>
!! end

!! test
bug 18784  Link to non-existent image page with caption should use caption as link text
!! wikitext
[[:Image:test|caption]]
!! html
<p><a href="/index.php?title=File:Test&amp;action=edit&amp;redlink=1" class="new" title="File:Test (page does not exist)">caption</a>
</p>
!! end

!! test
Frameless image caption with a free URL
!! wikitext
[[File:Foobar.jpg|http://example.com]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="http://example.com"><img alt="http://example.com" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;a rel=\"mw:ExtLink\" href=\"http://example.com\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;url&amp;quot;,&amp;quot;dsr&amp;quot;:[18,36,0,0]}\">http://example.com&lt;/a>"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Thumbnail image caption with a free URL
!! options
thumbsize=220
!! wikitext
[[File:Foobar.jpg|thumb|http://example.com]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" href="http://example.com">http://example.com</a></figcaption></figure>
!! end

!! test
Thumbnail image caption with a free URL and explicit alt
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb|http://example.com|alt=Alteration]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Alteration" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img alt="Alteration" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" href="http://example.com">http://example.com</a></figcaption></figure>
!! end

!! test
SVG thumbnails with no language set
!! options
!! wikitext
[[File:Foobar.svg|thumb|caption]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.svg" class="image"><img alt="" src="http://example.com/images/thumb/f/ff/Foobar.svg/180px-Foobar.svg.png" width="180" height="135" class="thumbimage" srcset="http://example.com/images/thumb/f/ff/Foobar.svg/270px-Foobar.svg.png 1.5x, http://example.com/images/thumb/f/ff/Foobar.svg/360px-Foobar.svg.png 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.svg" class="internal" title="Enlarge"></a></div>caption</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.svg"><img resource="./File:Foobar.svg" src="//example.com/images/thumb/f/ff/Foobar.svg/220px-Foobar.svg" data-file-width="240" data-file-height="180" data-file-type="drawing" height="165" width="220"/></a><figcaption>caption</figcaption></figure>
!! end

!! test
SVG thumbnails with language de
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.svg|thumb|caption|lang=de]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/index.php?title=File:Foobar.svg&amp;lang=de" class="image"><img alt="" src="http://example.com/images/thumb/f/ff/Foobar.svg/langde-180px-Foobar.svg.png" width="180" height="135" class="thumbimage" srcset="http://example.com/images/thumb/f/ff/Foobar.svg/langde-270px-Foobar.svg.png 1.5x, http://example.com/images/thumb/f/ff/Foobar.svg/langde-360px-Foobar.svg.png 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.svg" class="internal" title="Enlarge"></a></div>caption</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.svg"><img resource="./File:Foobar.svg" src="//example.com/images/thumb/f/ff/Foobar.svg/220px-Foobar.svg" lang="de" data-file-width="240" data-file-height="180" data-file-type="drawing" height="165" width="220"/></a><figcaption>caption</figcaption></figure>
!! end

!! test
SVG thumbnails with invalid language code
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.svg|thumb|caption|lang=invalid.language.code]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.svg" class="image"><img alt="" src="http://example.com/images/thumb/f/ff/Foobar.svg/180px-Foobar.svg.png" width="180" height="135" class="thumbimage" srcset="http://example.com/images/thumb/f/ff/Foobar.svg/270px-Foobar.svg.png 1.5x, http://example.com/images/thumb/f/ff/Foobar.svg/360px-Foobar.svg.png 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.svg" class="internal" title="Enlarge"></a></div>lang=invalid.language.code</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.svg"><img resource="./File:Foobar.svg" src="//example.com/images/f/ff/Foobar.svg" data-file-width="240" data-file-height="180" data-file-type="drawing" height="165" width="220"/></a><figcaption>lang=invalid.language.code</figcaption></figure>
!! end

!! test
BUG 1887: A ISBN with a thumbnail
!! wikitext
[[File:Foobar.jpg|thumb|ISBN 1235467890]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div><a href="/wiki/Special:BookSources/1235467890" class="internal mw-magiclink-isbn">ISBN 1235467890</a></div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="./Special:BookSources/1235467890" rel="mw:WikiLink">ISBN 1235467890</a></figcaption></figure>
!! end

!! test
BUG 1887: A RFC with a thumbnail
!! wikitext
[[File:Foobar.jpg|thumb|This is RFC 12354]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This is <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc12354">RFC 12354</a></div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>This is <a href="//tools.ietf.org/html/rfc12354" rel="mw:ExtLink">RFC 12354</a></figcaption></figure>
!! end

!! test
BUG 1887: A mailto link with a thumbnail
!! wikitext
[[File:Foobar.jpg|thumb|Please mailto:nobody@example.com]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>Please <a rel="nofollow" class="external free" href="mailto:nobody@example.com">mailto:nobody@example.com</a></div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>Please <a rel="mw:ExtLink" href="mailto:nobody@example.com">mailto:nobody@example.com</a></figcaption></figure>
!! end

# Pending resolution to bug 368
!! test
BUG 648: Frameless image caption with a link
!! wikitext
[[File:Foobar.jpg|text with a [[link]] in it]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a link in it"><img alt="text with a link in it" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a &lt;a rel=\"mw:WikiLink\" href=\"./Link\" title=\"Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;./Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;link&amp;quot;},&amp;quot;dsr&amp;quot;:[30,38,2,2]}\">link&lt;/a> in it"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
BUG 648: Frameless image caption with a link (suffix)
!! wikitext
[[File:Foobar.jpg|text with a [[link]]foo in it]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a linkfoo in it"><img alt="text with a linkfoo in it" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a &lt;a rel=\"mw:WikiLink\" href=\"./Link\" title=\"Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;./Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;link&amp;quot;},&amp;quot;dsr&amp;quot;:[30,41,2,5],&amp;quot;tail&amp;quot;:&amp;quot;foo&amp;quot;}\">linkfoo&lt;/a> in it"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
BUG 648: Frameless image caption with an interwiki link
!! wikitext
[[File:Foobar.jpg|text with a [[MeatBall:Link]] in it]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a MeatBall:Link in it"><img alt="text with a MeatBall:Link in it" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a &lt;a rel=\"mw:ExtLink\" href=\"http://www.usemod.com/cgi-bin/mb.pl?Link\" title=\"meatball:Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;http://www.usemod.com/cgi-bin/mb.pl?Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;MeatBall:Link&amp;quot;},&amp;quot;isIW&amp;quot;:true,&amp;quot;dsr&amp;quot;:[30,47,2,2]}\">MeatBall:Link&lt;/a> in it"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
BUG 648: Frameless image caption with a piped interwiki link
!! wikitext
[[File:Foobar.jpg|text with a [[MeatBall:Link|link]] in it]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="text with a link in it"><img alt="text with a link in it" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"text with a &lt;a rel=\"mw:ExtLink\" href=\"http://www.usemod.com/cgi-bin/mb.pl?Link\" title=\"meatball:Link\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;piped&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;http://www.usemod.com/cgi-bin/mb.pl?Link&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;MeatBall:Link&amp;quot;},&amp;quot;isIW&amp;quot;:true,&amp;quot;dsr&amp;quot;:[30,52,16,2]}\">link&lt;/a> in it"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
T107474: Frameless image caption with <nowiki>
!! wikitext
[[File:Foobar.jpg|<nowiki>text with a [[MeatBall:Link|link]] in it</nowiki>]]
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;span typeof=\"mw:Nowiki\" data-parsoid=\"{&amp;quot;dsr&amp;quot;:[18,75,8,9]}\">text with a [[MeatBall:Link|link]] in it&lt;/span>"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Escape HTML special chars in image alt text
!! wikitext
[[File:Foobar.jpg|& < > "]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="&amp; &lt; &gt; &quot;"><img alt="&amp; &lt; &gt; &quot;" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&amp;amp; &amp;lt; &amp;gt; \""}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
BUG 499: Alt text should have &#1234;, not &amp;1234;
!! wikitext
[[File:Foobar.jpg|&#9792;]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="♀"><img alt="♀" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;span typeof=\"mw:Entity\" data-parsoid=\"{&amp;quot;src&amp;quot;:&amp;quot;&amp;amp;#9792;&amp;quot;,&amp;quot;srcContent&amp;quot;:&amp;quot;♀&amp;quot;,&amp;quot;dsr&amp;quot;:[18,25,null,null]}\">♀&lt;/span>"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Broken image caption with link
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[Image:Foobar.jpg|thumb|This is a broken caption. But [[Main Page|this]] is just an ordinary link.
!! html/php
<p>[[Image:Foobar.jpg|thumb|This is a broken caption. But <a href="/wiki/Main_Page" title="Main Page">this</a> is just an ordinary link.
</p>
!! html/parsoid
<p>[[Image:Foobar.jpg|thumb|This is a broken caption. But <a rel="mw:WikiLink" href="Main_Page" title="Main Page">this</a> is just an ordinary link.</p>
!! end

!! test
Image caption containing another image
!! wikitext
[[File:Foobar.jpg|thumb|This is a caption with another [[File:Thumb.png|image]] inside it!]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This is a caption with another <a href="/wiki/File:Thumb.png" class="image" title="image"><img alt="image" src="http://example.com/images/e/ea/Thumb.png" width="135" height="135" /></a> inside it!</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>This is a caption with another <span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"image"}'><a href="./File:Thumb.png"><img resource="./File:Thumb.png" src="//example.com/images/e/ea/Thumb.png" data-file-width="135" data-file-height="135" data-file-type="bitmap" height="135" width="135"/></a></span> inside it!</figcaption></figure>
!! end

!! test
Image: caption containing a newline
!! wikitext
[[File:Foobar.jpg|This
*is some text]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="This *is some text"><img alt="This *is some text" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"This\n*is some text"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!!end

!!test
Image: caption containing leading space
(The leading space should not trigger nowiki escaping in wt2wt mode)
!! wikitext
[[File:Foobar.jpg|thumb| bar]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>bar</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption> bar</figcaption></figure>
!!end

!! test
Image: caption containing a table
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[Image:Foobar.jpg|thumb|200px|This is an example image thumbnail caption with a table
{|
! Foo !! Bar
|-
| Foo1 || Bar1
|}
and some more text.]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:202px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This is an example image thumbnail caption with a table <table> <tr> <th> Foo </th> <th> Bar </th></tr> <tr> <td> Foo1 </td> <td> Bar1 </td></tr></table> and some more text.</div></div></div>

!! html/parsoid
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//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>This is an example image thumbnail caption with a table
<table>
<tbody>
<tr><th>Foo </th><th>Bar</th></tr>
<tr>
<td>Foo1 </td>
<td>Bar1</td></tr></tbody></table>and some more text.</figcaption></figure>
!! end

!! test
Bug 3090: External links other than http: in image captions
!! wikitext
[[File:Foobar.jpg|thumb|200x200px|This caption has [irc://example.net irc] and [https://example.com Secure] ext links in it.]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:202px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" width="200" height="23" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/400px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>This caption has <a rel="nofollow" class="external text" href="irc://example.net">irc</a> and <a rel="nofollow" class="external text" href="https://example.com">Secure</a> ext links in it.</div></div></div>

!! html/parsoid
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//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>This caption has <a rel="mw:ExtLink" href="irc://example.net">irc</a> and <a rel="mw:ExtLink" href="https://example.com">Secure</a> ext links in it.</figcaption></figure>
!! end

!! test
Custom class
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[Image:foobar.jpg|a|class=b]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="a"><img alt="a" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" class="b" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size b" typeof="mw:Image" data-mw='{"caption":"a"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Localized image handling (1).
!! options
parsoid=wt2html,wt2wt,html2html
language=es
!! wikitext
[[Archivo:Foobar.jpg|izquierda|enlace=foo|caption]]
!! html/php
<div class="floatleft"><a href="/wiki/Foo" title="caption"><img alt="caption" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-left" typeof="mw:Image"><a href="./Foo"><img resource="./Archivo:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>caption</figcaption></figure>
!! end

!! test
Localized image handling (2).
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
language=es
!! wikitext
[[Archivo:Foobar.jpg|miniatura|izquierda|enlace=foo|caption]]
!! html/php
<div class="thumb tleft"><div class="thumbinner" style="width:222px;"><a href="/wiki/Foo" title="Foo"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/Archivo:Foobar.jpg" class="internal" title="Aumentar"></a></div>caption</div></div></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-left" typeof="mw:Image/Thumb"><a href="Foo"><img resource="./Archivo:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
!! end

!! test
"border", "frameless" and "class" attributes on an image.
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|frameless|border|class=extra|caption]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="caption"><img alt="caption" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="extra thumbborder" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size mw-image-border extra" typeof="mw:Image/Frameless" data-mw='{"caption":"caption"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a></span></p>
!! end

# Note that 'right' is the default alignment, despite the misspelled 'righ' below
!! test
Invalid image attributes (bug 62500)
!! options
thumbsize=220
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|thumb|float|left|caption]]

[[File:Foobar.jpg|thumb|righ|caption]]

[[File:Foobar.jpg|bogus1|thumb|bogus2|left|bogus3|caption]]
!! html/php
<div class="thumb tleft"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>caption</div></div></div>
<div class="thumb tright"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>caption</div></div></div>
<div class="thumb tleft"><div class="thumbinner" style="width:222px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" width="220" height="25" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/330px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/440px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>caption</div></div></div>

!! html/parsoid
<figure class="mw-default-size mw-halign-left" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
<figure class="mw-default-size mw-halign-left" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
!! end

!! article
File:Barfoo.jpg
!! text
#REDIRECT [[File:Barfoo.jpg]]
!! endarticle

# FIXME: Parsoid should run this test -- but we'd need to teach the
# mockAPI about the redirected Barfoo.jpg image.
!! test
Redirected image
!! wikitext
[[Image:Barfoo.jpg]]
!! html/php
<p><a href="/wiki/File:Barfoo.jpg" title="File:Barfoo.jpg">File:Barfoo.jpg</a>
</p>
!! end

!! test
Missing image with uploads disabled
!! options
wgEnableUploads=0
!! wikitext
[[File:Foobaz.jpg]]
!! html/php
<p><a href="/wiki/File:Foobaz.jpg" title="File:Foobaz.jpg">File:Foobaz.jpg</a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:Foobaz.jpg"><img resource="./File:Foobaz.jpg" src="./Special:FilePath/Foobaz.jpg" height="220" width="220"/></a></span></p>
!! end

# Parsoid-specific testing for images
# https://www.mediawiki.org/wiki/Parsoid/MediaWiki_DOM_spec#Images
# Currently imperfect due to a flaw in the Parsoid testrunner
# Work in progress
# THESE TESTS SHOULD BE MOVED UP and merged with the php-specific
# image tests.

!! test
Parsoid-specific image handling - simple image with size and middle alignment
!! wikitext
[[File:Foobar.jpg|middle|50px]]
!! html/parsoid
<p><span class="mw-valign-middle" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a></span></p>
!! end

!! test
Parsoid-specific image handling - simple image with size, middle alignment,
non-standard namespace alias
!! options
parsoid=wt2wt,wt2html,html2html
!! wikitext
[[Image:Foobar.jpg|middle|50px]]
!! html/parsoid
<p><span class="mw-valign-middle" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a></span></p>
!! end

!! test
Parsoid-specific image handling - simple image with size and middle alignment
(existing content)
!! wikitext
[[File:Foobar.jpg|50px|middle]]
!! html/parsoid
<p><span class="mw-valign-middle" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"width","ak":"50px"},{"ck":"middle","ak":"middle"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"6","width":"50"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
!! end

!! test
Parsoid-specific image handling - simple image with size and middle alignment
and non-standard namespace name
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[Image:Foobar.jpg|50px|middle]]
!! html/parsoid
<p><span class="mw-valign-middle" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a></span></p>
!! end

!! test
Parsoid-specific image handling - simple image with both sizes, a baseline alignment, and a caption
!! wikitext
[[File:Foobar.jpg|500x10px|baseline|caption]]
!! html/parsoid
<p><span class="mw-valign-baseline" typeof="mw:Image" data-mw='{"caption":"caption"}' data-parsoid='{"optList":[{"ck":"width","ak":"500x10px"},{"ck":"baseline","ak":"baseline"},{"ck":"caption","ak":"caption"}],"size":"500x10"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/89px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="10" width="89" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"10","width":"89"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
!! end

!! test
Parsoid-specific image handling - simple image with border and size spec
!! wikitext
[[File:Foobar.jpg|50px|border|caption]]
!! html/parsoid
<p><span class="mw-image-border" typeof="mw:Image" data-mw='{"caption":"caption"}' data-parsoid='{"optList":[{"ck":"width","ak":"50px"},{"ck":"border","ak":"border"},{"ck":"caption","ak":"caption"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"6","width":"50"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
!! end

!! test
Parsoid-specific image handling - thumbnail with halign, valign, and caption
!! wikitext
[[File:Foobar.jpg|left|baseline|thumb|caption content]]
!! html/parsoid
<figure class="mw-default-size mw-halign-left mw-valign-baseline" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption content</figcaption></figure>
!! end

!! test
Parsoid-specific image handling - thumbnail with halign, valign, and caption
(existing content)
!! wikitext
[[File:Foobar.jpg|thumb|left|baseline|caption content]]
!! html/parsoid
<figure class="mw-default-size mw-halign-left mw-valign-baseline" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"left","ak":"left"},{"ck":"baseline","ak":"baseline"},{"ck":"caption","ak":"caption content"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>caption content</figcaption></figure>
!! end

!! test
Parsoid-specific image handling - thumbnail with specific size, halign, valign, and caption
!! wikitext
[[Image:Foobar.jpg|right|middle|thumb|50x50px|caption]]
!! html/parsoid
<figure class="mw-halign-right mw-valign-middle" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50"/></a><figcaption>caption</figcaption></figure>
!! end

!! test
Parsoid-specific image handling - thumbnail with specific size, halign,
valign, and caption (existing content)
!! wikitext
[[File:Foobar.jpg|thumb|50x50px|right|middle|caption]]
!! html/parsoid
<figure class="mw-halign-right mw-valign-middle" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"width","ak":"50x50px"},{"ck":"right","ak":"right"},{"ck":"middle","ak":"middle"},{"ck":"caption","ak":"caption"}],"size":"50x50"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"6","width":"50"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>caption</figcaption></figure>
!! end

!! test
Parsoid-specific image handling - framed image with specific size and caption
(size is ignored)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|frame|500x50px|caption]]
!! html/parsoid
<figure typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>caption</figcaption></figure>
!! end

!! test
Parsoid-specific image handling - framed image with specific size, halign, valign, and caption
(size is ignored)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[File:Foobar.jpg|left|baseline|frame|500x50px|caption]]
!! html/parsoid
<figure class="mw-halign-left mw-valign-baseline" typeof="mw:Image/Frame"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>caption</figcaption></figure>
!! end

!! test
Parsoid-specific image handling - frameless image with specific size, border, and caption
!! wikitext
[[File:Foobar.jpg|frameless|442x50px|border|caption]]
!! html/parsoid
<p><span class="mw-image-border" typeof="mw:Image/Frameless" data-mw='{"caption":"caption"}' data-parsoid='{"optList":[{"ck":"frameless","ak":"frameless"},{"ck":"width","ak":"442x50px"},{"ck":"border","ak":"border"},{"ck":"caption","ak":"caption"}],"size":"442x50"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/442px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="50" width="442" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"50","width":"442"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
!! end

!! test
Parsoid-specific image handling - simple image with a formatted caption
!! wikitext
[[File:Foobar.jpg|<table><tr><td>a</td><td>b</td></tr><tr><td>c</td></tr></table>]]
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"&lt;table data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[18,81,7,8]}\">&lt;tbody data-parsoid=\"{&amp;quot;dsr&amp;quot;:[25,73,0,0]}\">&lt;tr data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[25,54,4,5]}\">&lt;td data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[29,39,4,5]}\">a&lt;/td>&lt;td data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[39,49,4,5]}\">b&lt;/td>&lt;/tr>&lt;tr data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[54,73,4,5]}\">&lt;td data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;html&amp;quot;,&amp;quot;dsr&amp;quot;:[58,68,4,5]}\">c&lt;/td>&lt;/tr>&lt;/tbody>&lt;/table>"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!! end

!! test
Parsoid-specific image handling - caption with a template in it
!! wikitext
[[File:Foobar.jpg|thumb|200x23px|This caption has a {{echo|transclusion}} in it.]]
!! html/parsoid
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//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>This caption has a <span about="#mwt1" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;transclusion&quot;}},&quot;i&quot;:0}}]}">transclusion</span> in it.</figcaption></figure>
!! end

!! test
Parsoid-specific image handling - caption with unbalanced tags in it
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
foo
[[File:Foobar.jpg|thumb|200x200px|This caption has a <center>unbalanced tag in it.]]
bar
!! html/parsoid
<p>foo</p>
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//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>This caption has a <center>unbalanced tag in it.</center></figcaption></figure>
<p>bar</p>
!! end

!! test
Parsoid-specific image handling - empty caption (1)
!! options
parsoid=wt2html,wt2wt
!! wikitext
[[File:Foobar.jpg|thumb|]]
!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption></figcaption></figure>
!! end

# empty captions don't get serialized unless we're in the "round trip" case
!! test
Parsoid-specific image handling - empty caption (2)
!! 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="//example.com/images/3/3a/Foobar.jpg"
         data-file-width="1941" data-file-height="220" data-file-type="bitmap"
         height="25" width="220"/>
  </a>
  <figcaption></figcaption>
</figure>
!! wikitext
[[File:Foobar.jpg|thumb]]
!! end

!! test
Parsoid-specific image handling - whitespace caption
!! wikitext
[[File:Foobar.jpg|thumb| ]]
!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption> </figcaption></figure>
!! end

!! test
Parsoid-specific image handling - lang option
!! wikitext
foo
[[File:Foobar.svg|lang=de|caption]]
bar
!! html/parsoid
<p>foo
<span class="mw-default-size" typeof="mw:Image" data-mw='{"caption":"caption"}'><a href="./File:Foobar.svg"><img resource="./File:Foobar.svg" src="//example.com/images/f/ff/Foobar.svg" lang="de" data-file-width="240" data-file-height="180" data-file-type="drawing" height="180" width="240"/></a></span>
bar</p>
!! end

## Edge case bugs in Parsoid from T93580
!! test
T93580: 1. Templated <ref> inside block images
!! wikitext
[[File:Foobar.jpg|thumb|Caption with templated ref: {{echo|<ref>foo</ref>}}]]

<references />
!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"caption","ak":"Caption with templated ref: {{echo|&lt;ref>foo&lt;/ref>}}"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>Caption with templated ref: <span about="#mwt5" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Transclusion  mw:Extension/ref" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;ref>foo&lt;/ref>"}},"i":0}}]}'><a href="#cite_note-1" style="counter-reset: mw-Ref 1;"><span class="mw-reflink-text">[1]</span></a></span></figcaption></figure>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">foo</span></li></ol>
!! end

!! test
T93580: 2. <ref> inside inline images
!! wikitext
[[File:Foobar.jpg|Undisplayed caption in inline image with ref: <ref>foo</ref>]]

<references />
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"caption","ak":"Undisplayed caption in inline image with ref: &lt;ref>foo&lt;/ref>"}]}' data-mw='{"caption":"Undisplayed caption in inline image with ref: &lt;span about=\"#mwt2\" class=\"mw-ref\" id=\"cite_ref-1\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid=\"{&amp;quot;dsr&amp;quot;:[64,78,5,6]}\" data-mw=\"{&amp;quot;name&amp;quot;:&amp;quot;ref&amp;quot;,&amp;quot;body&amp;quot;:{&amp;quot;id&amp;quot;:&amp;quot;mw-reference-text-cite_note-1&amp;quot;},&amp;quot;attrs&amp;quot;:{}}\">&lt;a href=\"#cite_note-1\" style=\"counter-reset: mw-Ref 1;\">&lt;span class=\"mw-reflink-text\">[1]&lt;/span>&lt;/a>&lt;/span>&lt;meta typeof=\"mw:Extension/ref/Marker\" about=\"#mwt2\" data-parsoid=\"{&amp;quot;group&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;content&amp;quot;:&amp;quot;foo&amp;quot;,&amp;quot;hasRefInRef&amp;quot;:false,&amp;quot;dsr&amp;quot;:[64,78,5,6],&amp;quot;tmp&amp;quot;:{}}\" data-mw=\"{}\">"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">foo</span></li></ol>
!! end

!! test
T93580: 3. Templated <ref> inside inline images
!! wikitext
[[File:Foobar.jpg|Undisplayed caption in inline image with ref: {{echo|<ref>{{echo|foo}}</ref>}}]]

<references />
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"caption","ak":"Undisplayed caption in inline image with ref: {{echo|&lt;ref>{{echo|foo}}&lt;/ref>}}"}]}' data-mw='{"caption":"Undisplayed caption in inline image with ref: &lt;span about=\"#mwt2\" class=\"mw-ref\" id=\"cite_ref-1\" rel=\"dc:references\" typeof=\"mw:Transclusion  mw:Extension/ref\" data-parsoid=\"{&amp;quot;dsr&amp;quot;:[64,96,null,null],&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;&lt;ref>{{echo|foo}}&lt;/ref>&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">&lt;a href=\"#cite_note-1\" style=\"counter-reset: mw-Ref 1;\">&lt;span class=\"mw-reflink-text\">[1]&lt;/span>&lt;/a>&lt;/span>&lt;meta typeof=\"mw:Transclusion mw:Extension/ref/Marker\" about=\"#mwt2\" data-parsoid=\"{&amp;quot;group&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;content&amp;quot;:&amp;quot;foo&amp;quot;,&amp;quot;hasRefInRef&amp;quot;:false,&amp;quot;dsr&amp;quot;:[64,96,null,null],&amp;quot;pi&amp;quot;:[[{&amp;quot;k&amp;quot;:&amp;quot;1&amp;quot;,&amp;quot;spc&amp;quot;:[&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;,&amp;quot;&amp;quot;]}]],&amp;quot;tmp&amp;quot;:{}}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;echo&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Echo&amp;quot;},&amp;quot;params&amp;quot;:{&amp;quot;1&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;&lt;ref>{{echo|foo}}&lt;/ref>&amp;quot;}},&amp;quot;i&amp;quot;:0}}]}\">"}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">foo</span></li></ol>
!! end

###
### Subpages
###
!! 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 (bug 51090)
!! wikitext
[[./../foo|bar]]
[[foo�|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~bar]]
[[foo>bar]]
[[foo[bar]]
[[.]]
[[..]]
[[foo././bar]]

[[{{echo|./../foo}}|bar]]
[[{{echo|foo/.}}|bar]]
[[{{echo|foo/..}}|bar]]
[[{{echo|foo~~~~bar}}]]
[[{{echo|foo>bar}}]]
[[{{echo|foo././bar}}]]
[[{{echo|foo{bar}}]]
[[{{echo|foo}bar}}]]
[[{{echo|foo[bar}}]]
[[{{echo|foo]bar}}]]
[[{{echo|foo<bar}}]]
!!html/php
<p>[[./../foo|bar]]
[[foo�|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~bar]]
[[foo&gt;bar]]
[[foo[bar]]
[[.]]
[[..]]
[[foo././bar]]
</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]]</p>

<p>[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"./../foo"}},"i":0}}]}'>./../foo</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo/."}},"i":0}}]}'>foo/.</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo/.."}},"i":0}}]}'>foo/..</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo~~~~bar"}},"i":0}}]}'>foo~~~~bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo>bar"}},"i":0}}]}'>foo>bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo././bar"}},"i":0}}]}'>foo././bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo{bar"}},"i":0}}]}'>foo{bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo}bar"}},"i":0}}]}'>foo}bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo[bar"}},"i":0}}]}'>foo[bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo]bar"}},"i":0}}]}'>foo]bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"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
BUG 561: {{/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

###
### 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's Guide">Category:MediaWiki User's Guide</a>
</p>
!! end

!! test
Simple category
!! options
cat
!! wikitext
[[Category:MediaWiki User's Guide]]
!! html
<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
!! 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
<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
!! end

!! test
Category with identical sort key
!! options
cat
!! wikitext
[[Category:MediaWiki User's Guide|MediaWiki User's Guide]]
!! html
<a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User's Guide">MediaWiki User's Guide</a>
!! end

!! test
Category with empty sort key
!! options
cat
pst
!! wikitext
[[Category:MediaWiki User's Guide|]]
!! html
[[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
[[Category:Foo (bar)|Foo]]
!! end

!! test
Category with link tail
!! options
cat
pst
!! wikitext
123[[Category:Foo]]456
!! html
123[[Category:Foo]]456
!! end

!! test
Category with template
!! options
cat
pst
!! wikitext
[[Category:{{echo|Foo}}]]
!! html
[[Category:{{echo|Foo}}]]
!! end

!! test
Category with template in sort key
!! options
cat
pst
!! wikitext
[[Category:Foo|{{echo|Bar}}]]
!! html
[[Category:Foo|{{echo|Bar}}]]
!! end

!! test
Category with template in sort key and title
!! options
cat
pst
!! wikitext
[[Category:{{echo|Foo}}|{{echo|Bar}}]]
!! html
[[Category:{{echo|Foo}}|{{echo|Bar}}]]
!! end

!! test
Category / paragraph interactions
!! 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]]
 {{echo|[[Category:Baz]]}}
[[Category:Baz]]
!! html
<p>Foo Bar
</p><p>Foo
Bar
</p><p>Foo
Bar
</p><p>Foo Bar
</p><p>Foo
Bar
</p>
!! end

## 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 bug 87)
!! options
parsoid=wt2html,wt2wt
!! wikitext
This
   
[[Category:Foo]] and this should be part of same paragraph (not an indent-pre)
   
{{echo|[[Category:Foo]] and so should this!}}
!! html
<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":"echo","href":"./Template:Echo"},"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 bug 87)
!! options
parsoid=wt2html
!! wikitext
* This
   
[[Category:Foo]] and this should be part of the same list item
* So should this

{{echo|[[Category:Foo]] and this should be part of the same list item}}
!! html
<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":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Category:Foo]] and this should be part of the same list item"}},"i":0}}]}'/><span> and this should be part of the same list item</span></li>
</ul>
!! end

## 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]]
!! html/parsoid
<ul><li> a</li>
<li> b</li></ul> 
   
<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/>
   
<link rel="mw:PageProp/Category" href="./Category:Bar" data-parsoid='{"stx":"simple","a":{"href":"./Category:Bar"},"sa":{"href":"Category:Bar"}}'/>
<link rel="mw:PageProp/Category" href="./Category:Baz" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:Baz"}}'/>
!! 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

!! test
6. Categories and newlines: migrateTrailingCategories dom pass should not migrate categories not preceded by newlines
!! 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
* {{echo|a
[[Category:Foo]]}}
!! html/parsoid
<ul><li> <span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n[[Category:Foo]]"}},"i":0}}]}'>a</span><span about="#mwt1">
</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

{{echo|[[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","spc":["","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Category:Foo]]\n[[Category:Bar]]"}},"i":0}}]}'/><span about="#mwt1">
</span><link rel="mw:PageProp/Category" href="./Category:Bar" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Bar"},"sa":{"href":"Category:Bar"}}'/>
<link rel="mw:PageProp/Category" href="./Category:Baz" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:Baz"}}'/>
!! end

!! test
Parsoid: Serialize link to category page with colon escape
!! options
parsoid
!! wikitext

[[:Category:Foo]]
[[:Category:Foo|Bar]]
!! html
<p>
<a rel="mw:WikiLink" href="./Category:Foo" title="Category:Foo">Category:Foo</a>
<a rel="mw:WikiLink" href="./Category:Foo" title="Category:Foo">Bar</a>
</p>
!! end

# html2wt localizes the "Category" namespace.
# XXX the <link> element needs an empty data-parsoid attribute, or
# else the html2html test fails because spaces are inserted.
!! test
Link prefix/suffixes aren't applied to category links
!! options
parsoid=wt2html,wt2wt,html2html
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
Parsoid: Serialize link to file page with colon escape
!! options
parsoid
!! wikitext

[[:File:Foo.png]]
[[:File:Foo.png|Bar]]
!! html
<p>
<a rel="mw:WikiLink" href="./File:Foo.png" title="File:Foo.png">File:Foo.png</a>
<a rel="mw:WikiLink" href="./File:Foo.png" title="File:Foo.png">Bar</a>
</p>
!! end

!! test
Parsoid: Serialize a genuine category link without colon escape
!! options
parsoid
!! wikitext
[[Category:Foo]]
[[Category:Foo|Bar]]
!! html
<link rel="mw:PageProp/Category" href="./Category:Foo">
<link rel="mw:PageProp/Category" href="./Category:Foo#Bar">
!! end

!! test
Normalize hrefs properly before testing for invalid link targets (bug 70894)
!! options
parsoid=html2wt
!! html/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 (template-generated)
!! wikitext
{{{{echo|DEFAULTSORT}}:Foo}}
!! html/parsoid
<meta property="mw:PageProp/categorydefaultsort" content="Foo" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,28,null,null],"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"{{echo|DEFAULTSORT}}:Foo"},"params":{},"i":0}}]}'/>
!! 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 (bug 24502)
!! 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"><div id="toctitle"><h2>Contents</h2></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"><div id="toctitle"><h2>Contents</h2></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'
!! test
Handling of sections up to level 6 and beyond
!! 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
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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="#.3D_Level_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.3D_Level_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.3D_Level_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.3D_Level_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=".3D_Level_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.3D_Level_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.3D_Level_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.3D_Level_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>

!! 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"><div id="toctitle"><h2>Contents</h2></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"><div id="toctitle"><h2>Contents</h2></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 (bug 6204)
!! 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"><div id="toctitle"><h2>Contents</h2></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 (bug 6204)
!! 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"><div id="toctitle"><h2>Contents</h2></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 (bug 10721)
!! 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="Template:Sections">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="Template:Sections">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"><div id="toctitle"><h2>Contents</h2></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

!! test
BUG 1219 URL next to image (good)
!! wikitext
http://example.com [[File:Foobar.jpg]]
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a> <a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a> <span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!!end

!! test
Short headings with trailing space should match behavior of Parser::doHeadings (bug 19910)
!! wikitext
=== 
The line above must have a trailing space!
=== <!--
--> <!-- -->
But just in case it doesn't...
!! html
<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>
!! end

!! test
Header with special characters (bug 25462)
!! 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
<p>The tooltips shall not show entities to the user (ie. be double escaped)
</p>
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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 ' 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>
!! 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
<p>Id should not contain + for spaces
</p>
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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>
!! end

!! test
Headers with excess '=' characters
(Are similar tests necessary beyond the 1st level?)
!! wikitext
=foo==
==foo=
=''italic'' heading==
==''italic'' heading=
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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>

!! end

!! test
HTML headers vs TOC (bug 23393)
(__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
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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>

!! end

!! test
Single-line or multiline-comments can follow headings
!! options
parsoid=wt2html,wt2wt
!! wikitext
==foo==<!---->
==bar==<!--c1-->
==baz==<!--
c2
c3-->
!! html
<h2><span class="mw-headline" id="foo">foo</span></h2>
<h2><span class="mw-headline" id="bar">bar</span></h2>
<h2><span class="mw-headline" id="baz">baz</span></h2>

!! end

!! test
BUG 1219 URL next to image (broken)
!! wikitext
http://example.com[[File:Foobar.jpg]]
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a><span class="mw-default-size" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a></span></p>
!!end

!! test
Bug 1186 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

# FIXME: produce empty string instead of "class" in the PHP parser, following
# the HTML5 spec.
!! test
div with empty attribute value, space before equals
!! options
parsoid
!! wikitext
<div class =>HTML rocks</div>
!! html
<div class="">HTML rocks</div>

!! end

!! test
div with multiple empty attribute values
!! options
parsoid
!! wikitext
<div id= title=>HTML rocks</div>
!! html
<div id="" title="">HTML rocks</div>

!! end

!! test
table with multiple empty attribute values
!! options
parsoid
!! wikitext
{| title= id=
| hi
|}
!! html
<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;}">Foo</div>

!! html/parsoid
<div title="{}">Foo</div>
!! end

# This it very inconsistent in the PHP parser: it returns 
# class="class" if there is a space between the name and the equal sign (see
# 'div with empty attribute value, space before equals'), but strips the
# attribute completely if the space is missing. We hope that not much content
# depends on this, so are implementing the behavior below in Parsoid for
# consistencies' sake.
# FIXME: fix this behavior in the PHP parser?
!! test
div with empty attribute value, no space before equals
!! options
parsoid=wt2html,html2html
!! wikitext
<div class=>HTML rocks</div>
!! html/php
<div>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>
<tr>
<th class="awesome"> status
</th></tr></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
<p>I always thought &#233; was a cute letter.
</p>
!! html+tidy
<p>I always thought é 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
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

###
### Nesting tests (see bug 41545, 50604, 51081)
###

# This test case is fixed in Parsoid by domino 1.0.12. (bug 50604)
# Note that html2wt is considerably more difficult if we use <b> in
# the test case, instead of <big>
!! test
Ensure that HTML adoption agency algorithm is properly implemented.
!! wikitext
<big>X<big>Y</big>Z</big>
!! html
<p><big>X<big>Y</big>Z</big>
</p>
!! end

# This was bug 41545 in the PHP parser.
# Note that tidy doesn't handle this correctly.
!! test
Nesting of <kbd>
!! wikitext
<kbd>X<kbd>Y</kbd>Z</kbd>
!! html
<p><kbd>X<kbd>Y</kbd>Z</kbd>
</p>
!! end

# The following cases were bug 51081 in the PHP parser.
# Note that there are some other nestable tags (b, i, etc) which are
# not covered; see bug 51081 for discussion.

# Note that tidy doesn't handle this correctly.
!! test
Nesting of <em>
!! wikitext
<em>X<em>Y</em>Z</em>
!! html
<p><em>X<em>Y</em>Z</em>
</p>
!! end

# Note that tidy doesn't handle this correctly.
!! test
Nesting of <strong>
!! wikitext
<strong>X<strong>Y</strong>Z</strong>
!! html
<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

# Note that tidy doesn't handle this correctly.
!! test
Nesting of <ruby>
!! wikitext
<ruby>X<ruby>Y</ruby>Z</ruby>
!! html
<p><ruby>X<ruby>Y</ruby>Z</ruby>
</p>
!! end

# Note that tidy doesn't handle this correctly.
!! 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]]
!! html
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Media:Foobar.jpg</a>
</p>
!! end

!! test
Media link with text
!! wikitext
[[Media:Foobar.jpg|A neat file to look at]]
!! html
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">A neat file to look at</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
!! test
Media link with nasty text
!! wikitext
[[Media:Foobar.jpg|Safe Link<div style=display:none>" onmouseover="alert(document.cookie)" onfoo="</div>]]
!! html
<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+tidy
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Safe Link</a></p>
<div style="display:none">" onmouseover="alert(document.cookie)" onfoo="</div>
!! end

!! test
Media link to nonexistent file (bug 1702)
!! wikitext
[[Media:No such.jpg]]
!! html
<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=No_such.jpg" class="new" title="No such.jpg">Media:No such.jpg</a>
</p>
!! end

!! test
Image link to nonexistent file (bug 1850 - good)
!! wikitext
[[File:No_such.jpg]]
!! html/php
<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=No_such.jpg" class="new" title="File:No such.jpg">File:No such.jpg</a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:No_such.jpg"><img resource="./File:No_such.jpg" src="./Special:FilePath/No_such.jpg" height="220" width="220"/></a></span></p>
!! end

!! test
:Image link to nonexistent file (bug 1850 - bad)
!! wikitext
[[:Image:No such.jpg]]
!! html/php
<p><a href="/index.php?title=File:No_such.jpg&amp;action=edit&amp;redlink=1" class="new" title="File:No such.jpg (page does not exist)">Image:No such.jpg</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./File:No_such.jpg" title="File:No such.jpg">Image:No such.jpg</a></p>
!! end



!! test
Character reference normalization in link text (bug 1938)
!! 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

!! test
(bug 19451) Links should refer to the normalized form.
!! wikitext
[[&#xFB2E;]]
[[&#x5d0;&#x5b7;]]
[[&#x5d0;ַ]]
[[א&#x5b7;]]
[[אַ]]
!! html
<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>
!! end

!! test
Empty attribute crash test (bug 2067)
!! wikitext
<font color="">foo</font>
!! html
<p><font color="">foo</font>
</p>
!! end

!! test
Empty attribute crash test single-quotes (bug 2067)
!! wikitext
<font color=''>foo</font>
!! html
<p><font color="">foo</font>
</p>
!! end

!! test
Attribute test: equals, then nothing
!! wikitext
<font color=>foo</font>
!! html
<p><font>foo</font>
</p>
!! end

!! test
Attribute test: unquoted value
!! wikitext
<font color=x>foo</font>
!! html
<p><font color="x">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
Bug 2095: 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
Bug 2095: 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
Bug 2095: 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
Bug 2304: HTML attribute safety (safe template; regression bug 2309)
!! wikitext
<div title="{{test}}"></div>
!! html
<div title="This is a test template"></div>

!! end

# Parsoid has enough context to handle this case
!! test
Bug 2304: 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=\"{&amp;quot;pi&amp;quot;:[[]],&amp;quot;dsr&amp;quot;:[12,35,null,null]}\" data-mw=\"{&amp;quot;parts&amp;quot;:[{&amp;quot;template&amp;quot;:{&amp;quot;target&amp;quot;:{&amp;quot;wt&amp;quot;:&amp;quot;dangerous attribute&amp;quot;,&amp;quot;href&amp;quot;:&amp;quot;./Template:Dangerous_attribute&amp;quot;},&amp;quot;params&amp;quot;:{},&amp;quot;i&amp;quot;:0}}]}\">\" onmouseover=\"alert(document.cookie)&lt;/span>"}]]}'></div>
!! end

!! test
Bug 2304: HTML attribute safety (dangerous style template; 2309)
!! wikitext
<div style="{{dangerous style attribute}}"></div>
!! html
<div style="/* insecure input */"></div>

!! end

!! test
Bug 2304: HTML attribute safety (safe parameter; 2309)
!! wikitext
{{div style|width: 200px}}
!! html
<div style="float: right; width: 200px">Magic div</div>

!! end

!! test
Bug 2304: HTML attribute safety (unsafe parameter; 2309)
!! wikitext
{{div style|width: expression(alert(document.cookie))}}
!! html
<div style="/* insecure input */">Magic div</div>

!! end

!! test
Bug 2304: 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

!! test
Bug 2304: 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
Bug 2304: HTML attribute safety (link)
!! wikitext
<div title="[[Main Page]]"></div>
!! html
<div title="&#91;&#91;Main Page]]"></div>

!! end

!! test
Bug 2304: HTML attribute safety (italics)
!! wikitext
<div title="''foobar''"></div>
!! html
<div title="&#39;&#39;foobar&#39;&#39;"></div>

!! end

!! test
Bug 2304: HTML attribute safety (bold)
!! wikitext
<div title="'''foobar'''"></div>
!! html
<div title="&#39;&#39;&#39;foobar&#39;&#39;&#39;"></div>

!! end


!! test
Bug 2304: HTML attribute safety (ISBN)
!! wikitext
<div title="ISBN 1234567890"></div>
!! html
<div title="&#73;SBN 1234567890"></div>

!! end

!! test
Bug 2304: HTML attribute safety (RFC)
!! wikitext
<div title="RFC 1234"></div>
!! html
<div title="&#82;FC 1234"></div>

!! end

!! test
Bug 2304: HTML attribute safety (PMID)
!! wikitext
<div title="PMID 1234567890"></div>
!! html
<div title="&#80;MID 1234567890"></div>

!! end

!! test
Bug 2304: HTML attribute safety (web link)
!! wikitext
<div title="http://example.com/"></div>
!! html
<div title="http&#58;//example.com/"></div>

!! end

!! test
Bug 2304: HTML attribute safety (named web link)
!! wikitext
<div title="[http://example.com/ link]"></div>
!! html
<div title="&#91;http&#58;//example.com/ link]"></div>

!! end

!! test
Bug 3244: HTML attribute safety (extension; safe)
!! wikitext
<div style="<nowiki>background:blue</nowiki>"></div>
!! html
<div style="background:blue"></div>

!! end

!! test
Bug 3244: HTML attribute safety (extension; unsafe)
!! wikitext
<div style="<nowiki>border-left:expression(alert(document.cookie))</nowiki>"></div>
!! html
<div style="/* insecure input */"></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
<div style="/* insecure input */">evil</div>

!! end

!! test
MSIE CSS safety test: hex code
!! wikitext
<div style="background-image:u\72l(javascript:alert('boo'))">evil</div>
!! html
<div style="/* insecure input */">evil</div>

!! end

!! test
MSIE CSS safety test: comment in url
!! wikitext
<div style="background-image:u/**/rl(javascript:alert('boo'))">evil</div>
!! html
<div 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
<div style="background-image:expres sion(alert(&#39;boo4&#39;))">evil4</div>

!! end

!! test
CSS safety test (all browsers): vertical tab (bug 55332 / CVE-2013-4567)
!! wikitext
<p style="font-size: 100px; background-image:url\b(https://www.google.com/images/srpr/logo6w.png)">A</p>
!! html
<p style="/* invalid control char */">A</p>

!! end

!! test
MSIE 6 CSS safety test: Fullwidth (bug 55332)
!! wikitext
<p style="font-size: 100px; color: ｅｘｐｒｅｓｓｉｏｎ((title='XSSed'),'red')">A</p>
<div style="top:ＥＸＰＲＥＳＳＩＯＮ(alert())">B</div>
!! html
<p style="/* insecure input */">A</p>
<div style="/* insecure input */">B</div>

!! end

!! test
MSIE 6 CSS safety test: IPA extensions (bug 55332)
!! wikitext
<div style="background-image:uʀʟ(javascript:alert())">A</div>
<p style="font-size: 100px; color: expʀessɪoɴ((title='XSSed'),'red')">B</p>
!! html
<div style="/* insecure input */">A</div>
<p style="/* insecure input */">B</p>

!! end

!! test
MSIE 6 CSS safety test: sup/sub script (bug 55332)
!! wikitext
<div style="background-image:url⁽javascript:alert())">A</div>
<div style="background-image:url₍javascript:alert())">B</div>
<p style="font-size: 100px; color: expressioⁿ((title='XSSed'),'red')">C</p>
!! html
<div style="/* insecure input */">A</div>
<div style="/* insecure input */">B</div>
<p style="/* insecure input */">C</p>

!! end

# FIXME: Parsoid fails to sanitize this! See T58846.
!! test
Opera -o-link CSS
!! 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
<div title="data:text/html,&lt;img src=1 onerror=alert(1)&gt;" style="/* insecure input */">X</div>

!! end

!! test
MSIE 6 CSS safety test: Repetition markers (bug 55332)
!! wikitext
<p style="font-size: 100px; color: expres〱ion((title='XSSed'),'red')">A</p>
<p style="font-size: 100px; color: expresゝion((title='XSSed'),'red')">B</p>
<p style="font-size: 100px; color: expresーion((title='XSSed'),'red')">C</p>
<p style="font-size: 100px; color: expresヽion((title='XSSed'),'red')">D</p>
<p style="font-size: 100px; color: expresﹽion((title='XSSed'),'red')">E</p>
<p style="font-size: 100px; color: expresﹼion((title='XSSed'),'red')">F</p>
<p style="font-size: 100px; color: expresｰion((title='XSSed'),'red')">G</p>
!! html
<p style="/* insecure input */">A</p>
<p style="/* insecure input */">B</p>
<p style="/* insecure input */">C</p>
<p style="/* insecure input */">D</p>
<p style="/* insecure input */">E</p>
<p style="/* insecure input */">F</p>
<p style="/* insecure input */">G</p>

!! end

!! test
Table attribute legitimate extension
!! wikitext
{|
!+ style="<nowiki>color:blue</nowiki>"| status
|}
!! html
<table>
<tr>
<th style="color:blue"> status
</th></tr></table>

!!end

!! test
Table attribute safety
!! wikitext
{|
!+ style="<nowiki>border-width:expression(0+alert(document.cookie))</nowiki>"| status
|}
!! html
<table>
<tr>
<th style="/* insecure input */"> status
</th></tr></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 (bug 6255)
!! wikitext
<div style="background: {{identity|#00FF00}}">-</div>
!! html
<div style="background: #00FF00">-</div>

!! end


!! test
Expansion of multi-line templates in attribute values (bug 6255 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 (bug 6255 sanity check 2)
!! wikitext
<div style="background: &#10;#00FF00">-</div>
!! html
<div style="background: &#10;#00FF00">-</div>

!! end

!! test
evil <math>-wiki-tags without Extension:Math enabled
!! wikitext
<math><img src="some evil external link"><script>some_evil_javascript();</script></math>
!! html+tidy
<p>&lt;math&gt;&lt;img src="some evil external link"&gt;&lt;script&gt;some_evil_javascript();&lt;/script&gt;&lt;/math&gt;</p>
!! end

###
### Parser hooks (see tests/parser/parserTestsParserHook.php for the <tag> extension)
###
!! test
Parser hook: empty input
!! wikitext
<tag></tag>
!! html/php
<pre>
''
array (
)
</pre>

!! end

!! test
Parser hook: empty input using terminated empty elements
!! wikitext
<tag/>
!! html/php
<pre>
NULL
array (
)
</pre>

!! end

!! test
Parser hook: empty input using terminated empty elements (space before)
!! wikitext
<tag />
!! html/php
<pre>
NULL
array (
)
</pre>

!! end

!! test
Parser hook: basic input
!! wikitext
<tag>input</tag>
!! html/php
<pre>
'input'
array (
)
</pre>

!! end


!! test
Parser hook: case insensitive
!! wikitext
<TAG>input</TAG>
!! html/php
<pre>
'input'
array (
)
</pre>

!! end


!! test
Parser hook: case insensitive, redux
!! wikitext
<TaG>input</TAg>
!! html/php
<pre>
'input'
array (
)
</pre>

!! end

!! test
Parser hook: nested tags
!! options
noxml
!! wikitext
<tag><tag></tag></tag>
!! html/php
<pre>
'<tag>'
array (
)
</pre>&lt;/tag&gt;

!! end

!! test
Parser hook: basic arguments
!! wikitext
<tag width=200 height = "100" depth = '50' square></tag>
!! html/php
<pre>
''
array (
  'width' => '200',
  'height' => '100',
  'depth' => '50',
  'square' => '',
)
</pre>

!! end

!! test
Parser hook: argument containing a forward slash (bug 5344)
!! wikitext
<tag filename='/tmp/bla'></tag>
!! html/php
<pre>
''
array (
  'filename' => '/tmp/bla',
)
</pre>

!! end

!! test
Parser hook: empty input using terminated empty elements (bug 2374)
!! wikitext
<tag foo=bar/>text
!! html/php
<pre>
NULL
array (
  'foo' => 'bar',
)
</pre>text

!! end

# </tag> should be output literally since there is no matching tag that begins it
!! test
Parser hook: basic arguments using terminated empty elements (bug 2374)
!! wikitext
<tag width=200 height = "100" depth = '50' square/>
other stuff
</tag>
!! html/php
<pre>
NULL
array (
  'width' => '200',
  'height' => '100',
  'depth' => '50',
  'square' => '',
)
</pre>
<p>other stuff
&lt;/tag&gt;
</p>
!! end

###
### (see tests/parser/parserTestsParserHook.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>hello, world
</p>
!! end


!! test
Parser hook: static parser hook inside a comment
!! wikitext
<!-- <statictag>hello, world</statictag> -->
<statictag action=flush/>
!! html/php
<p><br />
</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
###

# HTML+Tidy effectively strips out the empty tags completely
# But since Parsoid doesn't it wraps the <s></s> tags in p-tags
# which Tidy would have done for the PHP parser had there been content inside it.
!! test
Sanitizer: Closing of open tags
!! wikitext
<s></s><table></table>
!! html
<s></s><table></table>

!! html/parsoid
<p><s></s></p><table></table>
!! end

!! test
Sanitizer: Closing of open but not closed tags
!! wikitext
<s>foo
!! html
<p><s>foo</s>
</p>
!! end

!! test
Sanitizer: Closing of closed but not open tags
!! options
parsoid=wt2html
!! wikitext
</s>
!! html/php+tidy
!! html/parsoid
!! end

!! test
Sanitizer: Closing of closed but not open table tags
!! options
parsoid=wt2html
!! wikitext
Table not started</td></tr></table>
!! html/php+tidy
<p>Table not started</p>
!! html/parsoid
<p>Table not started</p>
!! end

!! test
Sanitizer: Escaping of spaces, multibyte characters, colons & other stuff in id=""
!! wikitext
<span id="æ: v">byte</span>[[#æ: v|backlink]]
!! html
<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 (bug 4515)
!! 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 (bug 4515, bug 6301)
!! 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" />
</p>
	<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" />
</div>

!! end

!! test
Language converter: output gets cut off unexpectedly (bug 5757)
!! 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
<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>
!! end

!! test
Self closed html pairs (bug 5487)
!! options
!! wikitext
<center><font id="bug" />Centered text</center>
<div><font id="bug2" />In div text</div>
!! html
<center>&lt;font id="bug" /&gt;Centered text</center>
<div>&lt;font id="bug2" /&gt;In div text</div>

!! end

#
#
#

!! test
Punctuation: nbsp before exclamation
!! wikitext
C'est grave !
!! html
<p>C'est grave&#160;!
</p>
!! end

!! test
Punctuation: CSS !important (bug 11874)
!! wikitext
<div style="width:50% !important">important</div>
!! html
<div style="width:50% !important">important</div>

!!end

!! test
Punctuation: CSS ! important (bug 11874; 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 (bug 5497)
!! 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 (bug 5497)
!! 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 (bug 5497)
!! 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 (bug 5497)
!! 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 (bug 5497)
!! wikitext
<ul>
<li>One</li>
<li>Two:
<ul>
<li>Sub-one</li>
<li>Sub-two</li>
</ul>
</li>
</ul>
!! html
<ul>
<li>One</li>
<li>Two:
<ul>
<li>Sub-one</li>
<li>Sub-two</li>
</ul>
</li>
</ul>

!! end

!! test
HTML nested bullet list, open tags (bug 5497)
!! wikitext
<ul>
<li>One
<li>Two:
<ul>
<li>Sub-one
<li>Sub-two
</ul>
</ul>
!! html/php+tidy
<ul>
<li>One</li>
<li>Two:
<ul>
<li>Sub-one</li>
<li>Sub-two</li>
</ul>
</li>
</ul>
!! html/parsoid
<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 (bug 5497)
!! 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 (bug 5497)
!! wikitext
<ol>
<li>One
<li>Two:
<ol>
<li>Sub-one
<li>Sub-two
</ol>
</ol>
!! html/php
<ol>
<li>One
<li>Two:
<ol>
<li>Sub-one
<li>Sub-two
</ol>
</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 bug 53505
!!test
bug 5918: 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/"></a> <a rel="mw:ExtLink" href="http://second"></a> <a rel="mw:ExtLink" href="ftp://ftp"></a></p>
<p><a rel="mw:ExtLink" href="ftp://inlineftp">ftp://inlineftp</a></p>
<p><a rel="mw:ExtLink" href="mailto:enclosed@mail.tld">With target</a></p>
<p><a rel="mw:ExtLink" href="mailto:enclosed@mail.tld"></a></p>
<p><a rel="mw:ExtLink" href="mailto:inline@mail.tld">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>
<tr>
<td>
</td>
</tr>
</table>

!! end

!! test
Fuzz testing: Parser14
!! wikitext
== onmouseover= ==
http://__TOC__
!! html
<h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
http://<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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+tidy
<h2><span class="mw-headline" id="onmouseover.3D">onmouseover=</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>http://</p>
<div id="toc" class="toc">
<div id="toctitle">
<h2>Contents</h2>
</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>
<p></p>
!! end

!! test
Fuzz testing: Parser14-table
!! wikitext
==a==
{| STYLE=__TOC__
!! html
<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+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="__TOC__">
<tr>
<td></td>
</tr>
</table>
!! end

# Known to produce bogus xml (extra </td>)
!! test
Fuzz testing: Parser16
!! options
noxml
!! wikitext
{|
!https://||||||
!! html
<table>
<tr>
<th>https://</th>
<th></th>
<th></th>
<th>
</td>
</tr>
</table>

!! html+tidy
<table>
<tr>
<th>https://</th>
<th></th>
<th></th>
<th></th>
</tr>
</table>
!! end

!! test
Fuzz testing: Parser21
!! wikitext
{|
! irc://{{ftp://a" onmouseover="alert('hello world');"
|
!! html
<table>
<tr>
<th> <a rel="nofollow" class="external free" href="irc://{{ftp://a">irc://{{ftp://a</a>" onmouseover="alert('hello world');"
</th>
<td>
</td>
</tr>
</table>

!! end

!! test
Fuzz testing: Parser22
!! wikitext
http://===r:::https://b

{|
!! html
<p><a rel="nofollow" class="external free" href="http://===r:::https://b">http://===r:::https://b</a>
</p>
<table>
<tr><td></td></tr>
</table>

!! end

# Known to produce bad XML for now
!! test
Fuzz testing: Parser24
!! options
noxml
!! wikitext
{|
{{{|
<u CLASS=
| {{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}} >
<br style="onmouseover='alert(document.cookie);' " />

MOVE YOUR MOUSE CURSOR OVER THIS TEXT
|
!! html
<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>

!! 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 (bug 6055)
!! wikitext
{{{
| 
<LI CLASS=||
 >
}}}blah" onmouseover="alert('hello world');" align="left"'''MOVE MOUSE CURSOR OVER HERE
!! html
<p>&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" 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" 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
<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" data-parsoid='{"stx":"url"}'>http://example.com</a></p><pre data-parsoid='{"stx":"html"}'>junk</pre>
!!end

!!test
Fuzz testing: image with bogus manual thumbnail
!! wikitext
[[Image:foobar.jpg|thumbnail= ]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;">Error creating thumbnail:   <div class="thumbcaption"></div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Error mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"manualthumb","ak":"thumbnail= "}],"dsr":[0,32,2,2]}' data-mw='{"errors":[{"key":"missing-thumbnail","message":"This thumbnail does not exist.","params":{"name":""}}],"thumb":""}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{},"dsr":[2,30,null,null]}'><img resource="./File:Foobar.jpg" src="./Special:FilePath/" height="220" width="220" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"220"},"sa":{"resource":"Image:foobar.jpg"}}'/></a></figure>
!!end

!! test
Fuzz testing: encoded newline in generated HTML replacements (bug 6577)
!! wikitext
<pre dir="&#10;"></pre>
!! html
<pre dir="&#10;"></pre>

!! end

!! test
Parsing optional HTML elements (Bug 6171)
!! options
!! wikitext
<table>
  <tr>
    <td> Some tabular data</td>
    <td> More tabular data ...
    <td> And yet som tabular data</td>
  </tr>
</table>
!! html
<table>
  <tr>
    <td> Some tabular data</td>
    <td> More tabular data ...
    </td><td> And yet som tabular data</td>
  </tr>
</table>

!! end

!! test
Correct handling of <td>, <tr> (Bug 6171)
!! 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>
  <tr>
    <td> Some tabular data</td>
    <td> More tabular data ...</td>
    <td> And yet som tabular data</td>
  </tr>
</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
<p><b>Bold paragraph
</p><p>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
<table class="mw-prefixindex-list-table"><tr><td><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></td></tr></table>

!! end

!! test
Special page transclusion twice (bug 5021)
!! options
!! wikitext
{{Special:Prefixindex/Xyzzyx}}
{{Special:Prefixindex/Xyzzyx}}
!! html
<table class="mw-prefixindex-list-table"><tr><td><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></td></tr></table>
<table class="mw-prefixindex-list-table"><tr><td><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></td></tr></table>

!! 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 bug 2587, 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 bug 2607, 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 bug 3342
!! test
Section extraction, heading surrounded by <noinclude>
!! options
section=1
!! wikitext
<noinclude>==unmarked==</noinclude>
==marked==
!! html/php
==marked==
!!end

# Test behavior of bug 19910
!! 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 (bug 13728)
!! 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 (bug 6398)
!! options
section=1
!! wikitext
==a==
                    a
!! html/php
==a==
                    a
!! end

!! test
Section extraction, heading followed by pre with 19 spaces (bug 6398 sanity check)
!! options
section=1
!! wikitext
==a==
                   a
!! html/php
==a==
                   a
!! end


!! test
Section extraction, <pre> around bogus header (bug 10309)
!! options
noxml section=2
!! wikitext
== Section One ==
<pre>
=======
</pre>

== Section Two ==
stuff
!! html/php
== Section Two ==
stuff
!! end

!! test
Section replacement, <pre> around bogus header (bug 10309)
!! options
noxml 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><ul><li> <a rel="nofollow" class="external free" href="irc://%0Aa">irc://%0Aa</a></li></ul></li></ul>

!! html/parsoid
<ul><li><ul><li> <a rel="mw:ExtLink" href="irc://
a">irc://
a</a></li></ul></li></ul>
!! end

!! test
Handling of %0A in URLs
!! wikitext
** irc://%0Aa
!! html/php
<ul><li><ul><li> <a rel="nofollow" class="external free" href="irc://%0Aa">irc://%0Aa</a></li></ul></li></ul>

!! html/parsoid
<ul><li><ul><li> <a rel="mw:ExtLink" href="irc://%0Aa">irc://%0Aa</a></li></ul></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></i>
</p>
!! html/parsoid
<p><b><i></i></b></p>
!! end

# same as previous, just swapping the <i> and <b>
!! test
5 quotes, code coverage +1 line w/ nowiki (2)
!! wikitext
'''''<nowiki/>'''''
!! html/php
<p><i></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
!! html/php
<p>| is a magic word there and | is still a magic word here
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"!","href":"./Template:!"},"params":{},"i":0}}]}' data-parsoid='{"pi":[[]]}'>|</span> is a magic word there and <span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"!","href":"./Template:!"},"params":{},"i":0}}]}' data-parsoid='{"pi":[[]]}'>|</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> </li>
<li> </li>
<li> 0</li>
<li> Talk</li>
<li> Talk</li>
<li> </li>
<li> </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
Gallery
!! wikitext
<gallery>
image1.png |
image2.gif|||||

image3|
image4    |300px| centre
 image5.svg| http://///////
[[x|xx]]]]
* image6
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Image1.png</div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Image2.gif</div>
			<div class="gallerytext">
<p>||||
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Image3</div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Image4</div>
			<div class="gallerytext">
<p>300px| centre
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Image5.svg</div>
			<div class="gallerytext">
<p><a rel="nofollow" class="external free" href="http://///////">http://///////</a>
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">* image6</div>
			<div class="gallerytext">
			</div>
		</div></li>
</ul>

!! end

!! test
Gallery (with options)
!! wikitext
<gallery widths='70px' heights='40px' perrow='2' caption='Foo [[Main Page]]' >
File:Nonexistent.jpg|caption
File:Nonexistent.jpg
image:foobar.jpg|some '''caption''' [[Main Page]]
image:foobar.jpg
image:foobar.jpg|Blabla|alt=This is a foo-bar.|blabla.
</gallery>
!! html
<ul class="gallery mw-gallery-traditional" style="max-width: 226px;_width: 226px;">
	<li class='gallerycaption'>Foo <a href="/wiki/Main_Page" title="Main Page">Main Page</a></li>
		<li class="gallerybox" style="width: 105px"><div style="width: 105px">
			<div class="thumb" style="height: 70px;">Nonexistent.jpg</div>
			<div class="gallerytext">
<p>caption
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 105px"><div style="width: 105px">
			<div class="thumb" style="height: 70px;">Nonexistent.jpg</div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 105px"><div style="width: 105px">
			<div class="thumb" style="width: 100px;"><div style="margin:31px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" width="70" height="8" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/105px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/140px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p>some <b>caption</b> <a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 105px"><div style="width: 105px">
			<div class="thumb" style="width: 100px;"><div style="margin:31px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" width="70" height="8" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/105px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/140px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 105px"><div style="width: 105px">
			<div class="thumb" style="width: 100px;"><div style="margin:31px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="This is a foo-bar." src="http://example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" width="70" height="8" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/105px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/140px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p>Blabla|blabla.
</p>
			</div>
		</div></li>
</ul>

!! end

!! test
Gallery with link that has fragment
!! wikitext
<gallery>
image:foobar.jpg|link=Main_Page
image:foobar.jpg|link=Main_Page#section
image:foobar.jpg|link=Main Page#section|caption
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/Main_Page"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/Main_Page#section"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/Main_Page#section"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p>caption
</p>
			</div>
		</div></li>
</ul>

!! end

!! test
Gallery with wikitext inside caption
!! wikitext
<gallery>
File:foobar.jpg|[[File:foobar.jpg|20px|desc|alt=inneralt]]|alt=galleryalt
File:foobar.jpg|{{Test|unamedParam|alt=param}}|alt=galleryalt
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p><a href="/wiki/File:Foobar.jpg" class="image" title="desc"><img alt="inneralt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/20px-Foobar.jpg" width="20" height="2" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/30px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/40px-Foobar.jpg 2x" /></a>
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p>This is a test template
</p>
			</div>
		</div></li>
</ul>

!! end

!! test
gallery (with showfilename option)
!! wikitext
<gallery showfilename>
File:Nonexistent.jpg|caption
File:Nonexistent.jpg
image:foobar.jpg|some '''caption''' [[Main Page]]
File:Foobar.jpg
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Nonexistent.jpg</div>
			<div class="gallerytext">
<p><a href="/wiki/File:Nonexistent.jpg" title="File:Nonexistent.jpg">Nonexistent.jpg</a><br />
caption
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Nonexistent.jpg</div>
			<div class="gallerytext">
<p><a href="/wiki/File:Nonexistent.jpg" title="File:Nonexistent.jpg">Nonexistent.jpg</a><br />
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p><a href="/wiki/File:Foobar.jpg" title="File:Foobar.jpg">Foobar.jpg</a><br />
some <b>caption</b> <a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p>
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p><a href="/wiki/File:Foobar.jpg" title="File:Foobar.jpg">Foobar.jpg</a><br />
</p>
			</div>
		</div></li>
</ul>

!! end

!! test
Gallery (with namespace-less filenames)
!! wikitext
<gallery>
File:Nonexistent.jpg
Nonexistent.jpg
image:foobar.jpg
foobar.jpg
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Nonexistent.jpg</div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">Nonexistent.jpg</div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
			</div>
		</div></li>
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
			</div>
		</div></li>
</ul>

!! end

!! 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/php+tidy
<p>JavaScript</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 (bug 26437 regression check)
!! wikitext
&#xsee;&#XSEE;
!! html/php
<p>&amp;#xsee;&amp;#XSEE;
</p>
!! html/parsoid
<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/php+tidy
<p>îî</p>
!! html/parsoid
<p><span typeof="mw:Entity">î</span><span typeof="mw:Entity">î</span></p>
!! end

# See: http://www.w3.org/TR/html5/syntax.html#character-references
# Note that U+000C (form feed) is not a valid XML character, so
# it is banned even though allowed in HTML5.
!! test
Illegal character references (T106578)
!! wikitext
; Null: &#00;
; FF: &#xC;
; CR: &#xD;
; Control (low): &#8;
; Control (high): &#x7F; &#x9F;
; Surrogate: &#xD83D;&#xDCA9;
; This is an okay astral character: &#x1F4A9;
!! html+tidy
<dl>
<dt>Null</dt>
<dd>&amp;#00;</dd>
<dt>FF</dt>
<dd>&amp;#xC;</dd>
<dt>CR</dt>
<dd>&amp;#xD;</dd>
<dt>Control (low)</dt>
<dd>&amp;#8;</dd>
<dt>Control (high)</dt>
<dd>&amp;#x7F; &amp;#x9F;</dd>
<dt>Surrogate</dt>
<dd>&amp;#xD83D;&amp;#xDCA9;</dd>
<dt>This is an okay astral character</dt>
<dd>💩</dd>
</dl>
!! end

!! test
__FORCETOC__ override
!! wikitext
__NEWSECTIONLINK__
__FORCETOC__
!! html/php
<p><br />
</p>
!! end

!! test
ISBN code coverage
!! wikitext
ISBN  978-0-1234-56&#x20;789
!! html
<p><a href="/wiki/Special:BookSources/9780123456" class="internal mw-magiclink-isbn">ISBN 978-0-1234-56</a>&#x20;789
</p>
!! html+tidy
<p><a href="/wiki/Special:BookSources/9780123456" class="internal mw-magiclink-isbn">ISBN 978-0-1234-56</a> 789</p>
!! html/parsoid
<p><a href="./Special:BookSources/9780123456" rel="mw: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
Bug 22905: <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">example.com</a></p>
!! end

!! test
Double RFC
!! wikitext
RFC RFC 1234
!! html
<p>RFC <a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc1234">RFC 1234</a>
</p>
!! end

!! test
Double RFC with a wiki link
!! wikitext
RFC [[RFC 1234]]
!! html
<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>
!! end

!! test
RFC code coverage
!! wikitext
RFC   983&#x20;987
!! html
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc983">RFC 983</a>&#x20;987
</p>
!! html+tidy
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc983">RFC 983</a> 987</p>
!! end

!! test
Centre-aligned image
!! wikitext
[[Image:foobar.jpg|centre]]
!! html
<div class="center"><div class="floatnone"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div></div>

!!end

!! test
None-aligned image
!! wikitext
[[Image:foobar.jpg|none]]
!! html
<div class="floatnone"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></div>

!!end

!! test
Width + Height sized image (using px) (height is ignored)
!! wikitext
[[Image:foobar.jpg|640x480px]]
!! html
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg" width="640" height="73" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/960px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/1280px-Foobar.jpg 2x" /></a>
</p>
!!end

!! test
Width-sized image (using px, no following whitespace)
!! wikitext
[[Image:foobar.jpg|640px]]
!! html
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg" width="640" height="73" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/960px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/1280px-Foobar.jpg 2x" /></a>
</p>
!!end

!! test
Width-sized image (using px, with following whitespace - test regression from r39467)
!! wikitext
[[Image:foobar.jpg|640px ]]
!! html
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg" width="640" height="73" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/960px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/1280px-Foobar.jpg 2x" /></a>
</p>
!!end

!! test
Width-sized image (using px, with preceding whitespace - test regression from r39467)
!! wikitext
[[Image:foobar.jpg| 640px]]
!! html
<p><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg" width="640" height="73" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/960px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/1280px-Foobar.jpg 2x" /></a>
</p>
!!end

!! test
Image with page parameter
!! options
djvu
!! wikitext
[[File:LoremIpsum.djvu|page=2]]
!! html/php
<p><a href="/index.php?title=File:LoremIpsum.djvu&amp;page=2" class="image"><img alt="LoremIpsum.djvu" src="http://example.com/images/thumb/5/5f/LoremIpsum.djvu/page2-2480px-LoremIpsum.djvu.jpg" width="2480" height="3508" srcset="http://example.com/images/thumb/5/5f/LoremIpsum.djvu/page2-3720px-LoremIpsum.djvu.jpg 1.5x, http://example.com/images/thumb/5/5f/LoremIpsum.djvu/page2-4960px-LoremIpsum.djvu.jpg 2x" /></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"page","ak":"page=2"}]}'><a href="./File:LoremIpsum.djvu" data-parsoid='{"a":{"href":"./File:LoremIpsum.djvu"},"sa":{}}'><img resource="./File:LoremIpsum.djvu" src="//example.com/images/5/5f/LoremIpsum.djvu" data-file-width="2480" data-file-height="3508" data-file-type="bitmap" height="3508" width="2480" data-parsoid='{"a":{"resource":"./File:LoremIpsum.djvu","height":"3508","width":"2480"},"sa":{"resource":"File:LoremIpsum.djvu"}}'/></a></span></p>
!! end

!! test
Another italics / bold test
!! wikitext
 ''' ''x'
!! html
<pre>'<i> </i>x'
</pre>
!!end

# FIXME: The php output seems broken. It's interleaving some open/close tags.
!! test
dt/dd/dl test
!! wikitext
:;;;::
!! html/php
<dl><dd><dl><dt><dl><dt><dl><dt><dl><dd><dl><dd></dt></dl></dd></dl></dd></dl></dd></dl></dd></dl></dd></dl>

!! html/parsoid
<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


# Images with the "|" character in external URLs in comment tags; Eats half the comment, leaves unmatched "</a>" tag.
!! test
Images with the "|" character in the comment
!! wikitext
[[File:Foobar.jpg|thumb|An [http://test/?param1=|left|&param2=|x external] URL]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>An <a rel="nofollow" class="external text" href="http://test/?param1=%7Cleft%7C&amp;param2=%7Cx">external</a> URL</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>An <a rel="mw:ExtLink" href="http://test/?param1=|left|&amp;param2=|x">external</a> URL</figcaption></figure>
!! 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
<p><script>alert(1);</script>
</p>
!! end

!! test
Parents of subpages, one level up
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../|L2]]
!! html
<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>
!! end


!! test
Parents of subpages, one level up, not named
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../]]
!! html
<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>
!! end



!! test
Parents of subpages, two levels up
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../../|L1]]2

[[../../|L1]]l
!! html
<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>
!! 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
<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>
!! 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

!! test
Non-transclusion because of too many up levels
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
{{../../../../More than parent}}
!! html
<p>{{../../../../More than parent}}
</p>
!! end

!! test
Definition list code coverage
!! wikitext
; title   : def
; title : def
;title: def
!! html/php
<dl><dt> title  &#160;</dt>
<dd> def</dd>
<dt> title&#160;</dt>
<dd> def</dd>
<dt>title</dt>
<dd> def</dd></dl>

!! html/parsoid
<dl><dt> title  <span typeof="mw:Placeholder"> </span></dt><dd> def</dd>
<dt> title<span typeof="mw:Placeholder"> </span></dt><dd> def</dd>
<dt>title</dt><dd> def</dd></dl>
!! 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="MediaWiki:Fake">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"><div id="toctitle"><h2>Contents</h2></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
<p><a href="/wiki/Special:BookSources/9290170328" class="internal mw-magiclink-isbn">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
<p>ISBN 123456789
</p><p><a href="/wiki/Special:BookSources/1234567890" class="internal mw-magiclink-isbn">ISBN 1234567890</a>
</p><p>ISBN 12345678901
</p>
!! end


!! test
ISBN with trailing year (bug 8110)
!! wikitext
ISBN 1-234-56789-0 - 2006

ISBN 1 234 56789 0 - 2006
!! html
<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>
!! end


!! test
anchorencode
!! wikitext
{{anchorencode:foo bar©#%n}}
!! html
<p>foo_bar.C2.A9.23.25n
</p>
!! end

!! test
anchorencode trims spaces
!! wikitext
{{anchorencode: __pretty__please__}}
!! html
<p>pretty_please
</p>
!! end

!! test
anchorencode deals with links
!! wikitext
{{anchorencode: [[hello|world]] [[hi]]}}
!! html
<p>world_hi
</p>
!! end

!! test
anchorencode deals with templates
!! wikitext
{{anchorencode: {{Foo}} }}
!! html
<p>FOO
</p>
!! end

!! test
anchorencode encodes like the TOC generator: (bug 18431)
!! wikitext
=== _ +:.3A%3A&&amp;]] ===
{{anchorencode: _ +:.3A%3A&&amp;]] }}
__NOEDITSECTION__
!! html
<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
Bug 6200: blockquotes and paragraph formatting
!! wikitext
<blockquote>
foo
</blockquote>

bar

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

!! test
Bug 8293: 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/php
<p><span><s>x&lt;/span&gt;</s></span>
</p>
!! html/parsoid
<p><span><s>x</s></span>
</p>
!!end

###
### Language variants related tests
###
!! test
Self-link in language variants
!! options
title=[[Dunav]] language=sr
!! wikitext
Both [[Dunav]] and [[Дунав]] are names for this river.
!! html
<p>Both <strong class="selflink">Dunav</strong> and <strong class="selflink">Дунав</strong> are names for this river.
</p>
!!end

!! article
Дуна
!! text
content
!! endarticle

!! 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
<p><a href="/wiki/%D0%94%D1%83%D0%BD%D0%B0" title="Дуна">Дуна</a> is not a self-link while <strong class="selflink">Duna</strong> and <strong class="selflink">Dуна</strong> are still self-links.
</p>
!! end

!! 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
<p><strong class="selflink">Dуна</strong> 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>
!! end

!! test
Link to pages in language variants
!! options
language=sr
!! wikitext
Main Page can be written as [[Маин Паге]]
!! html
<p>Main Page can be written as <a href="/wiki/Main_Page" title="Main Page">Маин Паге</a>
</p>
!!end


!! test
Multiple links to pages in language variants
!! options
language=sr
!! wikitext
[[Main Page]] can be written as [[Маин Паге]] same as [[Маин Паге]].
!! html
<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>
!!end


!! test
Simple template in language variants
!! options
language=sr
!! wikitext
{{тест}}
!! html
<p>This is a test template
</p>
!! end


!! test
Template with explicit namespace in language variants
!! options
language=sr
!! wikitext
{{Template:тест}}
!! html
<p>This is a test template
</p>
!! end


!! test
Basic test for template parameter in language variants
!! options
language=sr
!! wikitext
{{парамтест|param=foo}}
!! html
<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
<a href="/wiki/%D0%9A%D0%B0%D1%82%D0%B5%D0%B3%D0%BE%D1%80%D0%B8%D1%98%D0%B0:MediaWiki_User%27s_Guide" title="Категорија:MediaWiki User's Guide">MediaWiki User's Guide</a>
!! end


!! article
Category:分类
!! text
blah
!! endarticle

!! article
Category:分類
!! text
blah
!! endarticle

!! test
Don't convert blue categorylinks to another variant (bug 33210)
!! options
language=zh cat
!! wikitext
[[A]][[Category:分类]]
!! html
<a href="/wiki/Category:%E5%88%86%E7%B1%BB" title="Category:分类">分类</a>
!! end


!! test
Stripping -{}- tags (language variants)
!! options
language=sr
!! wikitext
Latin proverb: -{Ne nuntium necare}-
!! html
<p>Latin proverb: Ne nuntium necare
</p>
!! end


!! test
Prevent conversion with -{}- tags (language variants)
!! options
language=sr variant=sr-ec
!! wikitext
Latinski: -{Ne nuntium necare}-
!! html
<p>Латински: Ne nuntium necare
</p>
!! end


!! test
Prevent conversion of text with -{}- tags (language variants)
!! options
language=sr variant=sr-ec
!! wikitext
Latinski: -{Ne nuntium necare}-
!! html
<p>Латински: Ne nuntium necare
</p>
!! end


!! test
Prevent conversion of links with -{}- tags (language variants)
!! options
language=sr variant=sr-ec
!! wikitext
-{[[Main Page]]}-
!! html
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p>
!! end


!! test
-{}- tags within headlines (within html for parserConvert())
!! options
language=sr variant=sr-ec
!! wikitext
== -{Naslov}- ==
!! html
<h2><span class="mw-headline" id="-.7BNaslov.7D-">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>

!! end


!! test
Explicit definition of language variant alternatives
!! options
language=zh variant=zh-tw
!! wikitext
-{zh:China;zh-tw:Taiwan}-, not China
!! html
<p>Taiwan, not China
</p>
!! end


!! 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
<p>
<span title="ЛаCтин">ски</span>
</p>
!! end


!! test
Explicit session-wise language variant mapping (A flag and - flag)
!! options
language=zh variant=zh-tw
!! wikitext
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
<p>Taiwan is not China.
But Taiwan is Taiwan,
(This should be stripped!)
and China is China.
</p>
!! end

!! test
Explicit session-wise 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
<p>(This should be stripped!)
Taiwan is Taiwan.
</p>
!! end

!! 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}-!
!! html
Taiwan
<p>Should be stripped!
</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
China
<p>Should be stripped!
</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
China
<p>
Should be stripped<span title="Exclamation">!</span>
</p>
!! end

!! test
Bug 24072: 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
Taiwan
<p>This should be stripped!
This won't take interferes with the title rule.
</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
ZH
<p>
</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
ZH
<p>
</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
<p>Raw: zh:China;zh-tw:Taiwan
</p>
!! end

!! test
Strings evaluating false shouldn't be ignored by Language converter (T51072)
!! options
language=zh variant=zh-cn
!! input
-{zh-cn:0;zh-sg:1;zh-tw:2;zh-hk:3}-
!! result
<p>0
</p>
!! end

!! test
Conversion rules from [numeric-only string] to [something else] (T48634)
!! options
language=zh variant=zh-cn
!! input
-{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
!! result
<p>D12345EE12345
</p>
!! end

!! test
Bidirectional converter rule entries with an empty value should be ignored (T53551)
!! options
language=zh variant=zh-cn
!! input
-{H|zh-cn:foo;zh-tw:;}-foobar
!! result
<p>foobar
</p>
!! end

!! test
Unidirectional converter rule entries with an empty "from" string should be ignored (T53551)
!! options
language=zh variant=zh-cn
!! input
-{H|=>zh-cn:foo;}-foobar
!! result
<p>foobar
</p>
!! end

!! test
Empty converter rule entries shouldn't be inserted into the conversion table (T53551)
!! options
language=zh variant=zh-cn
!! input
-{H|}-foobar
!! result
<p>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
<p>Nested: Hello Hong Kong!
</p>
!! end

!! test
Proper conversion of text in external links
!! options
language=sr variant=sr-ec
!! 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
<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 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="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>
!! end

!! test
Do not convert roman numbers to language variants
!! options
language=sr variant=sr-ec
!! wikitext
Fridrih IV je car.
!! html
<p>Фридрих IV је цар.
</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
<p>=&gt;
</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
<p><a href="/wiki/Main_Page" title="Маин Паге">main page</a>
</p>
!! end

# FIXME: This test is currently broken in the PHP parser (bug 52661)
!! test
Don't break image parsing if language converter markup is in the caption.
!! options
language=sr
!! wikitext
[[File:Foobar.jpg|-{R|caption}-]]
!! html/parsoid
<p><a href="/wiki/File:Foobar.jpg" class="image" title="caption"><img alt="caption" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a>
</p>
!! end

# FIXME: This test is currently broken in the PHP parser (bug 52661)
!! test
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}-
!! html/php
<dl><dt><span class="error">在手动语言转换规则中检测到错误</span></dd></dl>

!! html/parsoid
<dl><dt>AAA
</dt></dl>
!! end

# FIXME: This test is currently broken in the PHP parser (bug 52661)
!! test
Don't break table handling if language converter markup is in the cell.
!! options
language=sr variant=sr-ec
!! wikitext
{|
|-
| -{R|B}-
|}
!! html/php
<table>

<tr>
<td>Б}-
</td></tr></table>

!! html/parsoid
<table>

<tr>
<td> B
</td></tr></table>

!! end

!! test
Bug 529: Uncovered bullet
!! wikitext
* Foo {{bullet}}
!! html
<ul><li> Foo </li>
<li> Bar</li></ul>

!! end

# Plain MediaWiki does not remove empty lists, but tidy actually does.
# Templates in Wikipedia rely on this behavior, as tidy has always been
# enabled there. These tests are normally run *without* tidy, so specify the
# full output here. 
# To test realistic parsing behavior, apply a tidy-like transformation to both
# the expected output and your parser's output.
!! test
Bug 529: Uncovered bullet leaving empty list, normally removed by tidy
!! 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
Bug 529: Uncovered table already at line-start
!! wikitext
x

{{table}}
y
!! html
<p>x
</p>
<table>
<tr>
<td> 1 </td>
<td> 2
</td></tr>
<tr>
<td> 3 </td>
<td> 4
</td></tr></table>
<p>y
</p>
!! end

!! test
Bug 529: Uncovered bullet in parser function result
!! wikitext
* Foo {{lc:{{bullet}} }}
!! html
<ul><li> Foo </li>
<li> bar</li></ul>

!! end

!! test
Bug 5678: Double-parsed template argument
!! wikitext
{{lc:{{{1}}}|hello}}
!! html
<p>{{{1}}}
</p>
!! end

!! test
Bug 5678: 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 (bug 8143)
!! 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
<!-- ~~~~ -->
!! 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

!! test
Nesting tags, paragraphs on lines which begin with <div>
!! wikitext
<div></div><strong>A
B</strong>
!! html/php+tidy
<p><strong>A</strong></p>
<p><strong>B</strong></p>
!! html/parsoid
<div></div>
<p><strong>A
B</strong>
</p>
!! end

# Bug 6200: <blockquote> should behave like <div> with respect to line breaks
!! test
Bug 6200: paragraphs inside blockquotes (no extra line breaks)
!! wikitext
<blockquote>Line one

Line two</blockquote>
!! html
<blockquote>Line one
Line two</blockquote>

!! html+tidy
<blockquote>
<p>Line one Line two</p>
</blockquote>
!! end

!! test
Bug 6200: paragraphs inside blockquotes (extra line break on open)
!! wikitext
<blockquote>
Line one

Line two</blockquote>
!! html
<blockquote>
<p>Line one
</p>
Line two</blockquote>

!! html+tidy
<blockquote>
<p>Line one</p>
Line two</blockquote>
!! end

!! test
Bug 6200: paragraphs inside blockquotes (extra line break on close)
!! wikitext
<blockquote>Line one

Line two
</blockquote>
!! html
<blockquote>Line one
<p>Line two
</p>
</blockquote>

!! html+tidy
<blockquote>
<p>Line one</p>
<p>Line two</p>
</blockquote>
!! end

!! test
Bug 6200: 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>

!! html+tidy
<blockquote>
<p>Line one</p>
<p>Line two</p>
</blockquote>
!! end

!! 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 replaceExternalLinks 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
Free external link invading image caption
!! wikitext
[[Image:Foobar.jpg|thumb|http://x|hello]]
!! html
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>  <div class="thumbcaption"><div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>hello</div></div></div>

!! end

!! test
Bug 15196: 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/"></a></p>
!! end

!! test
Multibyte character in padleft
!! wikitext
{{padleft:-Hello|7|Æ}}
!! html
<p>Æ-Hello
</p>
!! end

!! test
Multibyte character in padright
!! wikitext
{{padright:Hello-|7|Æ}}
!! html
<p>Hello-Æ
</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

#
#
#

#
# Edit comments
#

!! test
Edit comment with link
!! options
comment
!! wikitext
I like the [[Main Page]] a lot
!! html
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
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
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
<a href="/wiki/Main_Page#External_links" title="Main Page">→</a>‎<span dir="auto"><span class="autocomment">External links: </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
pre-comment text <a href="/wiki/Main_Page#External_links" title="Main Page">→</a>‎<span dir="auto"><span class="autocomment">External links: </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
<a href="#External_links">→</a>‎<span dir="auto"><span class="autocomment">External links: </span> removed bogus entries</span>
!!end

!! test
Edit comment with subpage link (bug 14080)
!! options
comment
subpage
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage]] here...
!! html
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 (bug 14080)
!! options
comment
subpage
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage|neat little page]] here...
!! html
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 (bug 14080)
!! options
comment
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage]] here...
!! html
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
<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
<a href="/wiki/Main_Page#section" title="Main Page">#section</a>
!! end

!! test
Anchor starting with underscore
!! wikitext
[[#_ref|One]]
!! html
<p><a href="#_ref">One</a>
</p>
!! end

!! test
Id starting with underscore
!! wikitext
<div id="_ref"></div>
!! html
<div id="_ref"></div>

!! end

!! test
Space normalisation on autocomment (bug 22784)
!! options
comment
title=[[Main Page]]
!! wikitext
/* __hello__world__ */
!! html
<a href="/wiki/Main_Page#hello_world" title="Main Page">→</a>‎<span dir="auto"><span class="autocomment">__hello__world__</span></span>
!! end

!! test
percent-encoding and + signs in comments (Bug 26410)
!! 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 bug 73581
# 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]]
!! DISABLED/html/php
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"bad-image","message":"This image is blacklisted in this context."}]}'><a href="./File:Bad.jpg"><img resource="./File:Bad.jpg" height="220" width="220"/></a></span></p>
!! end

!! test
Bad images - bug 16039: text after bad image disappears
!! wikitext
Foo bar
[[File:Bad.jpg]]
Bar foo
!! DISABLED/html/php
<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":"bad-image","message":"This image is blacklisted in this context."}]}'><a href="./File:Bad.jpg"><img resource="./File:Bad.jpg" height="220" width="220"/></a></span>
Bar foo</p>
!! end

!! test
Verify that displaytitle works (bug #22501) no displaytitle
!! options
showtitle
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! wikitext
this is not the the title
!! html/php
Parser test
<p>this is not the the title
</p>
!! end

!! test
Verify that displaytitle works (bug #22501) RestrictDisplayTitle=false
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! wikitext
this is not the the title
{{DISPLAYTITLE:whatever}}
!! html/php
whatever
<p>this is not the the title
</p>
!! end

!! test
Verify that displaytitle works (bug #22501) RestrictDisplayTitle=true mismatch
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the the title
{{DISPLAYTITLE:whatever}}
!! html/php
Screen
<p>this is not the the title
</p>
!! end

!! test
Verify that displaytitle works (bug #22501) RestrictDisplayTitle=true matching
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the the title
{{DISPLAYTITLE:screen}}
!! html/php
screen
<p>this is not the the title
</p>
!! end

!! test
Verify that displaytitle works (bug #22501) AllowDisplayTitle=false
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=false
!! wikitext
this is not the the title
{{DISPLAYTITLE:screen}}
!! html/php
Screen
<p>this is not the 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 (bug #22501) AllowDisplayTitle=false no DISPLAYTITLE
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=false
!! wikitext
this is not the the title
!! html/php
Screen
<p>this is not the the title
</p>
!! end

!! test
Verify that displaytitle handles inline CSS styles (bug 26547) - rejected value
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the 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 the title
</p>
!! end

!! test
Verify that displaytitle handles inline CSS styles (bug 26547) - accepted value
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the the title
{{DISPLAYTITLE:<span style="color: red;">s</span>creen}}
!! html/php
<span style="color: red;">s</span>creen
<p>this is not the the title
</p>
!! end

!! test
Page status indicators: Empty name is invalid
!! options
showindicators
!! wikitext
<indicator name=" "></indicator>
<indicator></indicator>
!! html
<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
empty=
name=
<p><br />
</p>
!! end

!! test
Page status indicators: Torture test
!! options
showindicators
!! 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
01=hello world
02=<a href="/wiki/Main_Page" title="Main Page">Main Page</a>
03=<img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/25px-Foobar.jpg" 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" />
04=<a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/25px-Foobar.jpg" 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>
05=<ul><li> foo</li>
<li> bar</li></ul>

06=foo
07=<pre>Preformatted
</pre>
08=<div>Broken tag</div>

09=<table class="wikitable">
<tr>
<td> cell
</td></tr></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 bug 3158
!! 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% !important">&#160;</div>
<div style="width:50% !important">&#160;</div>
<div style="border&#160;: 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
HTML5 data attributes
!! wikitext
<span data-foo="bar">Baz</span>
<p data-abc-def_hij="">Quuz</p>
!! html
<p><span data-foo="bar">Baz</span>
</p>
<p data-abc-def_hij="">Quuz</p>

!! end

!! test
percent-encoding and + signs in internal links (Bug 26410)
!! 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> <a href="/index.php?title=Special:Upload&amp;wpDestFile=%25%2Babc9" class="new" title="File:%+abc9">bar</a>
<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:+%">User:+%</a> <a rel="mw:WikiLink" href="Page+title%25" title="Page+title%">Page+title%</a>
<a rel="mw:WikiLink" href="%25+" title="%+">%+</a> <a rel="mw:WikiLink" href="%25+" title="%+">%20</a> <a rel="mw:WikiLink" href="%25+" title="%+">%+ </a> <a rel="mw:WikiLink" href="%25+r" title="%+r">%+r</a>
<a rel="mw:WikiLink" href="%25" title="%">%</a> <a rel="mw:WikiLink" href="+" title="+">+</a> <span class="mw-default-size" typeof="mw:Error mw:Image" data-parsoid='{"optList":[{"ck":"bogus","ak":"foo"},{"ck":"caption","ak":"[[bar]]"}]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&lt;a rel=\"mw:WikiLink\" href=\"./Bar\" title=\"Bar\" data-parsoid=\"{&amp;quot;stx&amp;quot;:&amp;quot;simple&amp;quot;,&amp;quot;a&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;./Bar&amp;quot;},&amp;quot;sa&amp;quot;:{&amp;quot;href&amp;quot;:&amp;quot;bar&amp;quot;},&amp;quot;dsr&amp;quot;:[94,101,2,2]}\">bar&lt;/a>"}'><a href="./File:%25+abc9"><img resource="./File:%25+abc9" src="./Special:FilePath/%25+abc9" height="220" width="220" data-parsoid='{"a":{"resource":"./File:%25+abc9","height":"220","width":"220"},"sa":{"resource":"File:%+abc%39"}}'/></a></span>
<a rel="mw:WikiLink" href="./3E" title="3E" data-parsoid='{"stx":"simple","a":{"href":"./3E"},"sa":{"href":"%33%45"}}'>3E</a> <a rel="mw:WikiLink" href="./3E+" title="3E+" data-parsoid='{"stx":"simple","a":{"href":"./3E+"},"sa":{"href":"%33%45+"}}'>3E+</a></p>
!! end

!! test
Special characters in embedded file links (bug 27679)
!! wikitext
[[File:Contains & ampersand.jpg]]
[[File:Does not exist.jpg|Title with & ampersand]]
!! html/php
<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=Contains_%26_ampersand.jpg" class="new" title="File:Contains &amp; ampersand.jpg">File:Contains &amp; ampersand.jpg</a>
<a href="/index.php?title=Special:Upload&amp;wpDestFile=Does_not_exist.jpg" class="new" title="File:Does not exist.jpg">Title with &amp; ampersand</a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:Contains_&amp;_ampersand.jpg"><img resource="./File:Contains_&amp;_ampersand.jpg" src="./Special:FilePath/Contains_&amp;_ampersand.jpg" height="220" width="220"/></a></span>
<span class="mw-default-size" typeof="mw:Error mw:Image" data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"Title with &amp;amp; ampersand"}'><a href="./File:Does_not_exist.jpg"><img resource="./File:Does_not_exist.jpg" src="./Special:FilePath/Does_not_exist.jpg" height="220" width="220"/></a></span></p>
!! end

!! test
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
Bug 19052 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
Bug 19052 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
Bug 19052 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
Bug 31098 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
Bug31490 Turkish: ucfirst 'blah'
!! options
language=tr
!! wikitext
{{ucfirst:blah}}
!! html
<p>Blah
</p>
!! end

!! test
Bug31490 Turkish: ucfirst 'ix'
!! options
language=tr
!! wikitext
{{ucfirst:ix}}
!! html
<p>İx
</p>
!! end

!! test
Bug31490 Turkish: lcfirst 'BLAH'
!! options
language=tr
!! wikitext
{{lcfirst:BLAH}}
!! html
<p>bLAH
</p>
!! end

!! test
Bug31490 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
Bug31490 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

!! test
Bug 26375: TOC with italics
!! options
title=[[Main Page]]
!! wikitext
__TOC__
== ''Lost'' episodes ==
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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>

!! end

!! test
Bug 26375: TOC with bold
!! options
title=[[Main Page]]
!! wikitext
__TOC__
== '''should be bold''' then normal text ==
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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>

!! end

!! test
Bug 33845: Headings become cursive in TOC when they contain an image
!! options
title=[[Main Page]]
!! wikitext
__TOC__
== Image [[Image:foobar.jpg]] ==
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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 <a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" width="1941" height="220" /></a></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>

!! end

!! test
Bug 33845 (2): Headings become bold in TOC when they contain a blockquote
!! options
title=[[Main Page]]
!! wikitext
__TOC__
== <blockquote>Quote</blockquote> ==
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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+tidy
<p></p>
<div id="toc" class="toc">
<div id="toctitle">
<h2>Contents</h2>
</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>
<p></p>
<h2><span class="mw-headline" id="Quote"></span></h2>
<blockquote>
<p><span class="mw-headline" id="Quote">Quote</span></p>
</blockquote>
<p><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></p>
!! end

!! test
Unclosed tags in TOC
!! options
title=[[Main Page]]
!! wikitext
__TOC__
== Proof: 2 < 3 ==
<small>Hanc marginis exiguitas non caperet.</small>
QED
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Proof:_2_.3C_3"><span class="tocnumber">1</span> <span class="toctext">Proof: 2 &lt; 3</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="Proof:_2_.3C_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>
!! end

!! test
Multiple tags in TOC
!! wikitext
__TOC__
== <i>Foo</i> <b>Bar</b> ==

== <i>Foo</i> <blockquote>Bar</blockquote> ==
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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+tidy
<p></p>
<div id="toc" class="toc">
<div id="toctitle">
<h2>Contents</h2>
</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>
<p></p>
<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></span></h2>
<blockquote>
<p><span class="mw-headline" id="Foo_Bar_2">Bar</span></p>
</blockquote>
<p><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></p>
!! 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"><div id="toctitle"><h2>Contents</h2></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> <sup class="in-h2" data-parsoid='{"stx":"html"}'>Hello</sup> </h2>

<h2> <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
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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>

!! end

!! test
Bug 72884: bdi element in ToC
!! wikitext
__TOC__
== <bdi>test</bdi> ==
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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>

!! end

# Note that the html output does not have the <p></p>, but the
# html+tidy output *does*.  This is because the empty <p></p> is
# removed by the sanitizer, but only when tidy is *not* enabled (!).
!! test
Empty <p> tag in TOC, removed by Sanitizer (T92892)
!! wikitext
__TOC__
== x ==
!! html
<div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2></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+tidy
<p></p>
<div id="toc" class="toc">
<div id="toctitle">
<h2>Contents</h2>
</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>
<p></p>
<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>
!! end

!! article
MediaWiki:Bug32057
!! text
== {{int:headline_sample}} ==
!! endarticle

!! test
Bug 32057: Title needed when expanding <h> nodes.
!! options
title=[[Main Page]]
!! wikitext
{{int:Bug32057}}
!! html
<h2><span class="mw-headline" id="Headline_text">Headline 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: Headline text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>

!! 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
<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 456,78
123456.78
</p>
!! end

!! test
Wrong option for formatNum (bug 56199)
!! 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
<p>xy
</p>
!! end

!! test
nowiki inside link inside heading (bug 18295)
!! 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 (bug 31817)
!! 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>
<tr>
<td> quux
</td></tr>
<tr id="foo" style="color: red">
<td> bar
</td></tr></table>

!! end

!!test
Gallery override link with WikiLink (bug 34852)
!! wikitext
<gallery>
File:foobar.jpg|caption|alt=galleryalt|link=InterWikiLink
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/InterWikiLink"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p>caption
</p>
			</div>
		</div></li>
</ul>

!! end

!!test
Gallery override link with absolute external link (bug 34852)
!! wikitext
<gallery>
File:foobar.jpg|caption|alt=galleryalt|link=http://www.example.org
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="http://www.example.org"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p>caption
</p>
			</div>
		</div></li>
</ul>

!! end

!!test
Gallery override link with malicious javascript (bug 34852)
!! wikitext
<gallery>
File:foobar.jpg|caption|alt=galleryalt|link=" onclick="alert('malicious javascript code!');
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/%22_onclick%3D%22alert(%27malicious_javascript_code!%27);"><img alt="galleryalt" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
<p>caption
</p>
			</div>
		</div></li>
</ul>

!! end

!!test
Gallery with invalid title as link (bug 43964)
!! wikitext
<gallery>
File:foobar.jpg|link=<
</gallery>
!! html
<ul class="gallery mw-gallery-traditional">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="width: 150px;"><div style="margin:68px auto;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" width="120" height="14" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/240px-Foobar.jpg 2x" /></a></div></div>
			<div class="gallerytext">
			</div>
		</div></li>
</ul>

!! end

!!test
Language parser function
!! wikitext
{{#language:ar}}
!! html
<p>العربية
</p>
!! end

!!test
Padleft and padright as substr
!! wikitext
{{padleft:|3|abcde}}
{{padright:|3|abcde}}
!! html
<p>abc
abc
</p>
!! end

!!test
Special parser function
!! wikitext
{{#special:RandomPage}}
{{#special:BaDtItLe}}
{{#special:Foobar}}
!! html
<p>Special:Random
Special:Badtitle
Special:Foobar
</p>
!! end

!!test
Bug 34939 - 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/"></a></p>
!! end

!!test
Bug 34939 - 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
Bug 34939 - 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/">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
{{echo|*a}}
{{echo|#a}}
{{echo|:a}}
!! html
<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
#### -----------------------------------------------------------------

# Bug 63642/66749: Formatting elt fixup around images is cleaned up.
# We know wt2wt will fail, but we expect selser to pass.
# Due to the nature of our testing, wt2wt and selser tests will enter the
# blacklist and we'll catch selser regressions based on changes to the
# blacklist entries for selser tests.
!! test
1. Bad treebuilder fixup of formatting elt is cleaned up
!! options
parsoid=wt2html,wt2wt
!! wikitext
{|
|
<small>
[[Image:Foobar.jpg|right|Test]]
</small>
|}
!! html/parsoid
<table>
<tbody><tr><td>
<small>
<figure class="mw-default-size mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941"/></a><figcaption>Test</figcaption></figure>
</small>
</td></tr>
</tbody></table>
!! end

!! test
2. Bad treebuilder fixup of formatting elt is cleaned up
!! options
parsoid=wt2html,wt2wt
!! wikitext
'''foo[[File:Foobar.jpg|thumb|caption]]bar'''

<small>[[Image:Foobar.jpg|right|300px]]</small>
!! html/parsoid

<p><b>foo</b></p>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><b>caption</b></figcaption></figure>
<p><b>bar</b></p>
<small><figure class="mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300"/></a></figure></small>
!! end

!! test
3. Bad treebuilder fixup of formatting elt is cleaned up
!! options
parsoid=wt2html,wt2wt
!! wikitext
<small>'''foo[[File:Foobar.jpg|thumb|caption]]bar'''</small>
!! html/parsoid
<p><small><b>foo</b></small></p>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><small><b>caption</b></small></figcaption></figure>
<p><small><b>bar</b></small></p>
!! end

!! test
4. Bad treebuilder fixup of formatting elt is cleaned up: formatting tags around captionless images are ignored
!! options
parsoid=wt2html,wt2wt
!! wikitext
'''<small>[[Image:Foobar.jpg|right|300px]]</small>'''
!! html/parsoid
<p><b><small></small></b></p>
<figure class="mw-halign-right" typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300"/></a></figure>
<p></p>
!! end

#### ----------------------------------------------------------------
#### Parsoid-only testing of Parsoid's impl of <ref> and <references>
#### tags. Parsoid's output for these tags differs from that of the
#### PHP parser.
#### ----------------------------------------------------------------

!!test
Ref: 1. ref-location should be replaced with an index span
!!options
parsoid
!! wikitext
A <ref>foo</ref>
B <ref name="x">foo</ref>
C <ref name="y" />
<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
B <span about="#mwt4" class="mw-ref" id="cite_ref-x_2-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-x-2"},"attrs":{"name":"x"}}'><a href="#cite_note-x-2"><span class="mw-reflink-text">[2]</span></a></span>
C <span about="#mwt6" class="mw-ref" id="cite_ref-y_3-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"y"}}'><a href="#cite_note-y-3"><span class="mw-reflink-text">[3]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt8" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li>
<li about="#cite_note-x-2" id="cite_note-x-2"><a href="#cite_ref-x_2-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-x-2" class="mw-reference-text">foo</span></li>
<li about="#cite_note-y-3" id="cite_note-y-3"><a href="#cite_ref-y_3-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-y-3" class="mw-reference-text"></span></li>
</ol>
!!end

!!test
Ref: 2. ref-tags with identical names should all get the same index
!!options
parsoid
!! wikitext
A <ref name="x">foo</ref>
B <ref name="x" />
<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-x_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-x-1"},"attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span>
B <span about="#mwt4" class="mw-ref" id="cite_ref-x_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-x-1" id="cite_note-x-1"><span rel="mw:referencedBy"><a href="#cite_ref-x_1-0"><span class="mw-linkback-text">1 </span></a><a href="#cite_ref-x_1-1"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-x-1" class="mw-reference-text">foo</span></li>
</ol>
!!end

!!test
Ref: 3. spaces in ref-names should be ignored
!!options
parsoid
!! wikitext
A <ref name="x">foo</ref>
B <ref name=" x " />
C <ref name= x  />
<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-x_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-x-1"},"attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span>
B <span about="#mwt4" class="mw-ref" id="cite_ref-x_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span>
C <span about="#mwt6" class="mw-ref" id="cite_ref-x_1-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt8" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-x-1" id="cite_note-x-1"><span rel="mw:referencedBy"><a href="#cite_ref-x_1-0"><span class="mw-linkback-text">1 </span></a><a href="#cite_ref-x_1-1"><span class="mw-linkback-text">2 </span></a><a href="#cite_ref-x_1-2"><span class="mw-linkback-text">3 </span></a></span> <span id="mw-reference-text-cite_note-x-1" class="mw-reference-text">foo</span></li>
</ol>
!!end

# NOTE: constructor is a predefined property in JS and constructor as a ref-name can clash with it if not handled properly)
!!test
Ref: 4. 'constructor' should be accepted as a valid ref-name
!!options
parsoid
!! wikitext
A <ref name="constructor">foo</ref>
<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-constructor_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-constructor-1"},"attrs":{"name":"constructor"}}'><a href="#cite_note-constructor-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-constructor-1" id="cite_note-constructor-1"><a href="#cite_ref-constructor_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-constructor-1" class="mw-reference-text">foo</span></li>
</ol>
!!end

!!test
Ref: 5. body should accept generic wikitext
!!options
parsoid
!! wikitext
A <ref>
 This is a '''[[bolded link]]''' and this is a {{echo|transclusion}}
</ref>

<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">This is a <b><a rel="mw:WikiLink" href="Bolded_link" title="Bolded link">bolded link</a></b> and this is a <span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"transclusion"}},"i":0}}]}'>transclusion</span>
</span></li>
</ol>
!!end

!!test
Ref: 6. indent-pres should not be output in ref-body
!!options
parsoid
!! wikitext
A <ref>
 foo
 bar
 baz
</ref>

<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo
 bar
 baz
</span></li>
</ol>
!!end

!!test
Ref: 7. No p-wrapping in ref-body
!!options
parsoid
!! wikitext
A <ref>
foo

bar


baz



booz
</ref>

<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo

bar


baz



booz
</span></li>
</ol>
!!end

!!test
Ref: 8. transclusion wikitext has lower precedence
!!options
parsoid
!! wikitext
A <ref> foo {{echo|</ref> B C}}

<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B C<span typeof="mw:Nowiki">}}</span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo <span typeof="mw:Nowiki" data-parsoid='{"src":"{{","dsr":[12,14,0,0]}'>{{</span>echo|</span></li>
</ol>
!!end

!!test
Ref: 9. unclosed comments should not leak out of ref-body
!!options
parsoid
!! wikitext
A <ref> foo <!--</ref> B C
<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B C</p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo <!----></span></li>
</ol>
!!end

!!test
Ref: 10. Unclosed HTML tags should not leak out of ref-body
!!options
parsoid
!! wikitext
A <ref> <b> foo </ref> B C

<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B C</p>


<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"><b data-parsoid='{"stx":"html","autoInsertedEnd":true}'> foo </b></span></li>
</ol>
!!end

!!test
Ref: 11. ref-tags acts like an inline element wrt P-wrapping
!!options
parsoid
!! wikitext
A <ref>foo</ref> B
C <ref>bar</ref> D
<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B
C <span about="#mwt4" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{}}'><a href="#cite_note-2"><span class="mw-reflink-text">[2]</span></a></span> D</p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li>
<li about="#cite_note-2" id="cite_note-2"><a href="#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">bar</span></li>
</ol>
!!end

!!test
Ref: 12. ref-tags act as trailing newline migration barrier
!! wikitext
<!--the newline at the end of this line moves out of the p tag-->a

b<!--the newline at the end of this line stays inside the p tag--> <ref />
<ref />

c
<references />
!! html/parsoid
<!--the newline at the end of this line moves out of the p tag--><p>a</p>


<p>b<!--the newline at the end of this line stays inside the p tag--> <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
<span about="#mwt4" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{}}'><a href="#cite_note-2"><span class="mw-reflink-text">[2]</span></a></span></p>

<p>c</p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"></span></li>
<li about="#cite_note-2" id="cite_note-2"><a href="#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"></span></li></ol>
!!end

!!test
Ref: 13. ref-tags are not SOL-transparent and block indent-pres
!!options
parsoid
!! wikitext
<ref>foo</ref> A
<ref>bar
</ref> B
<references />
!! html
<p><span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> A
<span about="#mwt4" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{}}'><a href="#cite_note-2"><span class="mw-reflink-text">[2]</span></a></span> B</p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li>
<li about="#cite_note-2" id="cite_note-2"><a href="#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">bar
</span></li>
</ol>
!!end

!!test
Ref: 14. A nested ref-tag should be emitted as plain text
!!options
parsoid
!! wikitext
<ref>foo <ref>bar</ref> baz</ref>

<references />
!! html
<p><span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
</p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo &lt;ref>bar&lt;/ref> baz</span></li>
</ol>
!!end

!!test
Ref: 15. ref-tags with identical names should get identical indexes
!!options
parsoid
!! wikitext
A1 <ref name="a">foo</ref> A2 <ref name="a" />
B1 <ref name="b" /> B2 <ref name="b">bar</ref>

<references />
!! html
<p>A1 <span about="#mwt3" class="mw-ref" id="cite_ref-a_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-a-1"},"attrs":{"name":"a"}}'><a href="#cite_note-a-1"><span class="mw-reflink-text">[1]</span></a></span> A2 <span about="#mwt4" class="mw-ref" id="cite_ref-a_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a"}}'><a href="#cite_note-a-1"><span class="mw-reflink-text">[1]</span></a></span>
B1 <span about="#mwt7" class="mw-ref" id="cite_ref-b_2-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"b"}}'><a href="#cite_note-b-2"><span class="mw-reflink-text">[2]</span></a></span> B2 <span about="#mwt8" class="mw-ref" id="cite_ref-b_2-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-b-2"},"attrs":{"name":"b"}}'><a href="#cite_note-b-2"><span class="mw-reflink-text">[2]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt10" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-a-1" id="cite_note-a-1"><span rel="mw:referencedBy"><a href="#cite_ref-a_1-0"><span class="mw-linkback-text">1 </span></a><a href="#cite_ref-a_1-1"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-a-1" class="mw-reference-text">foo</span></li><li about="#cite_note-b-2" id="cite_note-b-2"><span rel="mw:referencedBy"><a href="#cite_ref-b_2-0"><span class="mw-linkback-text">1 </span></a><a href="#cite_ref-b_2-1"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-b-2" class="mw-reference-text">bar</span></li>
</ol>
!!end

## We don't bother wt2wt-ing non-standard whitespace
!!test
Ref: 16. Tokenizer should accept non-standard whitespace in <ref> and </ref> tags
!!options
parsoid=wt2html
!! wikitext
A <ref >foo</ref >

<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li></ol>
!!end

!!test
Ref: 17. Generate valid HTML5 id/about attributes
!!options
parsoid
!!wikitext
<ref name="a b">foo</ref>

<references />
!!html
<p><span class="mw-ref" id="cite_ref-a_b_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-a_b-1"},"attrs":{"name":"a b"}}'><a href="#cite_note-a_b-1"><span class="mw-reflink-text">[1]</span></a></span>
</p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-a_b-1" id="cite_note-a_b-1"><a href="#cite_ref-a_b_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-a_b-1" class="mw-reference-text">foo</span></li>
</ol>
!!end

!!test
Ref: 18. T58916: Extension attributes should be parsed as plain text
!!options
parsoid
!!wikitext
<ref name="{{echo|a}}">foo</ref>

<references />
!!html
<p><span class="mw-ref" id="cite_ref-.7B.7Becho.7Ca.7D.7D_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-.7B.7Becho.7Ca.7D.7D-1"},"attrs":{"name":"{{echo|a}}"}}'><a href="#cite_note-.7B.7Becho.7Ca.7D.7D-1"><span class="mw-reflink-text">[1]</span></a></span>
</p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-.7B.7Becho.7Ca.7D.7D-1" id="cite_note-.7B.7Becho.7Ca.7D.7D-1"><a href="#cite_ref-.7B.7Becho.7Ca.7D.7D_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-.7B.7Becho.7Ca.7D.7D-1" class="mw-reference-text">foo</span></li>
</ol>
!!end

!!test
Ref: 19. ref-tags with identical name encodings should get identical indexes
!!options
parsoid
!! wikitext
1 <ref name="a & b">foo</ref> 2 <ref name="a &amp; b" />

<references />
!! html
<p>1 <span about="#mwt3" class="mw-ref" id="cite_ref-a_.26_b_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-a_.26_b-1"},"attrs":{"name":"a &amp; b"}}'><a href="#cite_note-a_.26_b-1"><span class="mw-reflink-text">[1]</span></a></span> 2 <span about="#mwt4" class="mw-ref" id="cite_ref-a_.26_b_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a &amp;amp; b"}}'><a href="#cite_note-a_.26_b-1"><span class="mw-reflink-text">[1]</span></a></span>
</p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-a_.26_b-1" id="cite_note-a_.26_b-1"><span rel="mw:referencedBy"><a href="#cite_ref-a_.26_b_1-0"><span class="mw-linkback-text">1 </span></a><a href="#cite_ref-a_.26_b_1-1"><span class="mw-linkback-text">2 </span></a></span> <span id="mw-reference-text-cite_note-a_.26_b-1" class="mw-reference-text">foo</span></li>
</ol>
!!end

!!test
Ref: 20. ref-tags with identical names but different content should keep it
!!options
parsoid
!! wikitext
A <ref name="foo">Foo one</ref>
B <ref name="foo">Foo two</ref>
C <ref name="foo" />

<references />
!! html
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-foo_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-foo-1"},"attrs":{"name":"foo"}}'><a href="#cite_note-foo-1"><span class="mw-reflink-text">[1]</span></a></span>
B <span about="#mwt4" class="mw-ref" id="cite_ref-foo_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"html":"Foo two"},"attrs":{"name":"foo"}}'><a href="#cite_note-foo-1"><span class="mw-reflink-text">[1]</span></a></span>
C <span about="#mwt6" class="mw-ref" id="cite_ref-foo_1-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"foo"}}'><a href="#cite_note-foo-1"><span class="mw-reflink-text">[1]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt8" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-foo-1" id="cite_note-foo-1"><span rel="mw:referencedBy"><a href="#cite_ref-foo_1-0"><span class="mw-linkback-text">1 </span></a><a href="#cite_ref-foo_1-1"><span class="mw-linkback-text">2 </span></a><a href="#cite_ref-foo_1-2"><span class="mw-linkback-text">3 </span></a></span> <span id="mw-reference-text-cite_note-foo-1" class="mw-reference-text">Foo one</span></li>
</ol>
!!end

!!test
References: 1. references tag without any refs should be handled properly
!! wikitext
<references />
!! html/parsoid
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt2" data-mw='{"name":"references","attrs":{}}'></ol>
!!end

!!test
References: 2. references tag with group only outputs references from that group
!! wikitext
A <ref group="a">foo</ref>
B <ref group="b">bar</ref>
C <ref>baz</ref>

<references group="a" />
<references />
<references group="b" />
!! html/parsoid
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{"group":"a"}}'><a href="#cite_note-1" data-mw-group="a"><span class="mw-reflink-text">[a 1]</span></a></span>
B <span about="#mwt4" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{"group":"b"}}'><a href="#cite_note-2" data-mw-group="b"><span class="mw-reflink-text">[b 1]</span></a></span>
C <span class="mw-ref" id="cite_ref-3" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-3"},"attrs":{}}'><a href="#cite_note-3"><span class="mw-reflink-text">[1]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt8" data-mw-group="a" data-mw='{"name":"references","attrs":{"group":"a"}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" data-mw-group="a" 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>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt10" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-3" id="cite_note-3"><a href="#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">baz</span></li>
</ol>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt12" data-mw-group="b" data-mw='{"name":"references","attrs":{"group":"b"}}'>
<li about="#cite_note-2" id="cite_note-2"><a href="#cite_ref-2" data-mw-group="b" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-2" class="mw-reference-text">bar</span></li>
</ol>
!!end

!!test
References: 3. ref list should be cleared after processing references
!! wikitext
A <ref>foo</ref>

<references />

B <ref>bar</ref>

<references />
!! html/parsoid
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li>
</ol>

<p>B <span about="#mwt6" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{}}'><a href="#cite_note-2"><span class="mw-reflink-text">[1]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt8" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-2" id="cite_note-2"><a href="#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">bar</span></li>
</ol>
!!end

!!test
References: 4. only referenced group should be cleared after processing references
!! wikitext
A <ref group="a">afoo</ref>
B <ref>bfoo</ref>

<references group="a" />

C <ref>cfoo</ref>

<references />
!! html/parsoid
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{"group":"a"}}'><a href="#cite_note-1" data-mw-group="a"><span class="mw-reflink-text">[a 1]</span></a></span>
B <span about="#mwt4" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{}}'><a href="#cite_note-2"><span class="mw-reflink-text">[1]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw-group="a" data-mw='{"name":"references","attrs":{"group":"a"}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" data-mw-group="a" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">afoo</span></li>
</ol>

<p>C <span about="#mwt8" class="mw-ref" id="cite_ref-3" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-3"},"attrs":{}}'><a href="#cite_note-3"><span class="mw-reflink-text">[2]</span></a></span></p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt10" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-2" id="cite_note-2"><a href="#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">bfoo</span></li><li about="#cite_note-3" id="cite_note-3"><a href="#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">cfoo</span></li>
</ol>
!!end

!!test
References: 5. ref tags in references should be processed while ignoring all other content
!! wikitext
A <ref name="a" />
B <ref name="b">bar</ref>

<references>
<ref name="a">foo</ref>
This should just get lost.
</references>
!! html/parsoid
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-a_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a"}}'><a href="#cite_note-a-1"><span class="mw-reflink-text">[1]</span></a></span>
B <span about="#mwt4" class="mw-ref" id="cite_ref-b_2-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-b-2"},"attrs":{"name":"b"}}'><a href="#cite_note-b-2"><span class="mw-reflink-text">[2]</span></a></span></p>


<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","body":{"extsrc":"&lt;ref name=\"a\">foo&lt;/ref>\nThis should just get lost.","html":"\n&lt;span about=\"#mwt8\" class=\"mw-ref\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid=&#39;{\"dsr\":[59,82,14,6]}&#39; data-mw=&#39;{\"name\":\"ref\",\"body\":{\"id\":\"mw-reference-text-cite_note-a-1\"},\"attrs\":{\"name\":\"a\"}}&#39;>&lt;a href=\"#cite_note-a-1\" style=\"counter-reset: mw-Ref 1;\">&lt;span class=\"mw-reflink-text\">[1]&lt;/span>&lt;/a>&lt;/span>\n"},"attrs":{}}'><li about="#cite_note-a-1" id="cite_note-a-1"><a href="#cite_ref-a_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-a-1" class="mw-reference-text">foo</span></li><li about="#cite_note-b-2" id="cite_note-b-2"><a href="#cite_ref-b_2-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-b-2" class="mw-reference-text">bar</span></li>
</ol>
!!end

!!test
References: 6. <references /> from a transclusion
!! wikitext
<ref>Foo</ref> {{echo|<references />}}
!! html/parsoid
<p><span about="#mwt3" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p> <ol class="mw-references" typeof="mw:Extension/references mw:Transclusion" about="#mwt4" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;references />"}},"i":0}}]}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">Foo</span></li>
</ol>
!!end

!! test
References: 7. Multiple references tags (one without and one with nested refs) should be correctly handled
!! wikitext
A <ref>foo bar for a</ref>
B <ref group="X" name="b" />

<references />

<references group="X">
<ref name="b">foo</ref>
</references>
!! html/parsoid
<p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
B <span about="#mwt4" class="mw-ref" id="cite_ref-b_2-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"group":"X","name":"b"}}'><a href="#cite_note-b-2" data-mw-group="X"><span class="mw-reflink-text">[X 1]</span></a></span>
</p>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo bar for a</span></li>
</ol>

<ol class="mw-references" typeof="mw:Extension/references" about="#mwt8" data-mw-group="X" data-mw='{"name":"references","body":{"extsrc":"&lt;ref name=\"b\">foo&lt;/ref>","html":"\n&lt;span about=\"#mwt10\" class=\"mw-ref\" rel=\"dc:references\" typeof=\"mw:Extension/ref\" data-parsoid=&#39;{\"dsr\":[96,119,14,6]}&#39; data-mw=&#39;{\"name\":\"ref\",\"body\":{\"id\":\"mw-reference-text-cite_note-b-2\"},\"attrs\":{\"name\":\"b\"}}&#39;>&lt;a href=\"#cite_note-b-2\" style=\"counter-reset: mw-Ref 1;\" data-mw-group=\"X\">&lt;span class=\"mw-reflink-text\">[X 1]&lt;/span>&lt;/a>&lt;/span>\n"},"attrs":{"group":"X"}}'>
<li about="#cite_note-b-2" id="cite_note-b-2"><a href="#cite_ref-b_2-0" data-mw-group="X" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-b-2" class="mw-reference-text">foo</span></li>
</ol>
!! end

!! test
References: 8. T88019: Remove <meta>s from templates inside <ref> that's itself inside a template
!! wikitext
X{{echo|<ref>foo {{echo|<b>bar</b>}} and {{echo|baz}} boo</ref>}}
<references />
!! html/parsoid
<p>X<span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Transclusion  mw:Extension/ref" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;ref>foo {{echo|&lt;b>bar&lt;/b>}} and {{echo|baz}} boo&lt;/ref>"}},"i":0}}]}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt7" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo <b data-parsoid='{"stx":"html"}'>bar</b> and baz boo</span></li>
</ol>
!!end

# This test only works in wt2html now as the <references /> are always generated
# unless selser is active. Once T72722 is fixed, we should add a changes test
# here to ensure that unrelated changes don't add the new <references /> in
# wt2wt.
!! test
References: 9. Generate missing references list at the end
!! wikitext
A <ref>foo</ref>
B <ref group="inexistent">bar</ref>
!! html/parsoid
<p>A <span class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B <span class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{"group":"inexistent"}}'><a href="#cite_note-2" data-mw-group="inexistent"><span class="mw-reflink-text">[inexistent 1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li>
</ol>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw-group="inexistent" data-mw='{"name":"references","attrs":{"group":"inexistent"}}'>
<li about="#cite_note-2" id="cite_note-2"><a href="#cite_ref-2" data-mw-group="inexistent" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-2" class="mw-reference-text">bar</span></li>
</ol>
!! end

!! test
References: 10. New <references/> shouldn't be added for unrelated edits.
!! options
parsoid={
  "modes": ["selser"],
  "changes": [["#x", "remove"]],
  "selser": "noauto"
}
!! wikitext
Unrelated text<span id="x"> that's going to disappear</span>.
A <ref>foo</ref>
!! wikitext/edited
Unrelated text.
A <ref>foo</ref>
!!end

!! test
Entities in ref name
!! wikitext
<ref name="test &amp; me">hi</ref>
<references />
!! html/parsoid
<p><span about="#mwt2" class="mw-ref" id="cite_ref-test_.26_me_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-test_.26_me-1"},"attrs":{"name":"test &amp;amp; me"}}'><a href="#cite_note-test_.26_me-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-test_.26_me-1" id="cite_note-test_.26_me-1"><a href="#cite_ref-test_.26_me_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-test_.26_me-1" class="mw-reference-text">hi</span></li>
</ol>
!! end

# This test is wt2html only because we're permitting the serializer to produce
# dirty diffs, normalizing the unclosed references to the self-closed version.
!! test
Generate references for unclosed references tag
!! options
parsoid=wt2html
!! wikitext
a<ref>foo</ref>

<references>
!! html/parsoid
<p>a<span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li></ol>
!! end

!! test
New reference serializes on its own line
!! options
parsoid=wt2wt,html2wt
!! wikitext
foo
<references />
!! html/parsoid
foo<ol class="mw-references" typeof="mw:Extension/references" about="#mwt2" data-mw='{"name":"references","attrs":{}}'></ol>
!! end

#### ----------------------------------------------------------------
#### Parsoid-only testing of Parsoid's impl of LST
#### Not implemented yet, see
#### https://www.mediawiki.org/wiki/Parsoid/HTML_based_LST
#### ----------------------------------------------------------------

!!test
LST Sections: 1. Simple section start and end
!! 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 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></li>
<li> b</li>
</ul>
<table>
<tbody>
<tr></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'''<nowiki>foo=</nowiki> =
!!end

!! test
Headings: 4a. No escaping needed (testing just h1 and h2)
!! options
parsoid=html2wt
!! html/parsoid
<h1>=foo</h1>
<h1>foo=</h1>
<h1> =foo= </h1>
<h1>=foo= bar</h1>
<h2>=foo</h2>
<h2>foo=</h2>
<h1>=</h1>
<h1><i>=</i>foo=</h1>
!! wikitext
= =foo =

= 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>
!!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

#### --------------- 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

!! test
Lists: 1. Nested inside html
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>*foo</li></ul>
<ul><li>#foo</li></ul>
<ul><li>:foo</li></ul>
<ul><li>;foo</li></ul>
<ol><li>*foo</li></ol>
<ol><li>#foo</li></ol>
<ol><li>:foo</li></ol>
<ol><li>;foo</li></ol>

!! wikitext
*<nowiki>*foo</nowiki>

*<nowiki>#foo</nowiki>

*<nowiki>:foo</nowiki>

*<nowiki>;foo</nowiki>

#<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
;<nowiki>;foo</nowiki>

;<nowiki>:foo</nowiki>

;<nowiki>:foo</nowiki>
:bar

:<nowiki>:foo</nowiki>
!!end

!! test
Lists: 3. Only bullets at start of text should be escaped
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>*foo*bar</li></ul>
<ul><li>*foo<i>it</i>*bar</li></ul>

!! wikitext
*<nowiki>*foo*bar</nowiki>

*<nowiki>*foo</nowiki>''it''*bar
!!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>
<tr>
<td>foo|bar</td>
</tr>
<tr>
<td>x
<div>a|b</div>
</td>
</tr>
</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>
<tr>
<td>foo||bar
</td>
<td>a<i>b||c</i>
</td>
<td>a<i><div>b||c</div></i>
</td></tr></table>

!! end

!! test
Tables: 2c. Nested in td -- no escaping needed
!! options
parsoid=html2wt
!! html/*
<table>

<tr>
<td>foo!!bar
</td></tr></table>

!! wikitext
{|

|foo!!bar
|}
!! end

!! test
Tables: 3a. Nested in th
!! options
parsoid=html2wt
!! html/*
<table>

<tr>
<th>foo!bar
</th></tr></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>
<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></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>
<tr>
<th>foo||bar
</th>
<th>foo||bar
</th></tr></table>

!! end

!! test
Tables: 4a. Escape -
!! options
parsoid=html2wt
!! html/*
<table>

<tr>
<th>-bar
</th></tr>
<tr>
<td>-bar
</td></tr></table>

!! wikitext
{|

!-bar

|-
|<nowiki>-bar</nowiki>
|}
!! end

!! test
Tables: 4b. Escape +
!! options
parsoid=html2wt
!! html/*
<table>

<tr>
<th>+bar
</th></tr>
<tr>
<td>+bar
</td></tr></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>
<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></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>
<tr>
<td><a href="/wiki/Foo" title="Foo">Foo</a>-bar
</td>
<td>+1
</td>
<td>-2
</td></tr></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>
<tr>
<td> &lt;foo
</td>
<td> bar&gt;
</td></tr></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|<nowiki>|Bar</nowiki>]]
[[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></p>
<p>[http://google.com]</p>
<p>[http://google.com google]</p>
!! wikitext
[http://google.com <nowiki>[google]</nowiki>]
[http://google.com <nowiki>google]</nowiki>]

<nowiki>[http://google.com]</nowiki>

<nowiki>[http://google.com google]</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>
</p><p>[http://google.com]
</p><p>[http://google.com google]
</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>
!! wikitext
[http://google.com [google]
!! html/php
<p><a rel="nofollow" class="external text" href="http://google.com">[google</a>
</p>
!! end

!! test
Links 6. Add <nowiki/>s between text-nodes and url-links when required (bug 64300)
!! options
parsoid=html2wt
!! html/parsoid
<p>x<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>y
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>?x
<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 (bug 64300)
!! options
parsoid=html2wt
!! html/parsoid
<p>x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>
y
"<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>"
(<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 (bug 64300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>.,;:!?\
-<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>:</p>
!! 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 (bug 64300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>4
<a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>y
X<a href="//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 (bug 64300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>?foo
<a href="//tools.ietf.org/html/rfc123" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>RFC 123</a>&amp;foo
-<a href="//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="//tools.ietf.org/html/rfc123">RFC 123</a>?foo
<a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc123">RFC 123</a>&amp;foo
-<a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc123">RFC 123</a>-
</p>
!! end

!! test
Links 10. Add <nowiki/>s between text-nodes and PMID-links when required (bug 64300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>4
<a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>y
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 (bug 64300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>?foo
<a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>&foo
-<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 (bug 64300)
!! 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 (bug 64300)
!! 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
<nowiki>this is not a link: http://example.com</nowiki>
!! end

!! test
Links 15. Link trails can't become link prefixes.
!! options
language=is
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:WikiLink" href="Söfnuður" title="Söfnuður" data-parsoid='{"stx":"simple","tail":"-"}'>Söfnuður-</a><a rel="mw:WikiLink" href="00" title="00">00</a></p>
!! wikitext
[[Söfnuður]]-[[00]]
!! html/php
<p><a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">Söfnuður-</a><a href="/wiki/00" title="00">00</a>
</p>
!! 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":"echo","href":"./Template:Echo"},"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" 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="#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" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">test</span></li>
</ol>
!! wikitext
'''a'' foo ''[[bar]]''
''a''' foo ''[[bar]]''
''a''' foo '''{{echo|[[bar]]}}'''
[[foo]] x'''[[bar]]''
'''foo'' <ref>test</ref>
'''foo'' <div title="name">test</div>
'''foo'' and <br> bar
<references />
!! end

!! test
2. Link fragments separated by <i> and <b> tags
!! options
parsoid=html2wt
!! html/parsoid
<p>[[<i>foo</i>hello]]</p>
<p>[[<b>foo</b>hello]]</p>
!! wikitext
[[''foo''<nowiki>hello]]</nowiki>

[['''foo'''<nowiki>hello]]</nowiki>
!! 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
options=html2wt
!! html/parsoid
<p>'<span><i>bar</i></span>'
'<span><b>bar</b></span>'
'a:b'foo
</p>
!! wikitext
'<span>''bar''</span>'
'<span>'''bar'''</span>'
'a:b'foo
!! end

#### ----------- Paragraphs ---------------
#### 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 --------------------------
#### 1. Leading whitespace in SOL context should be escaped
#### ------------------------------------------------------
!! 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=htm2wt
!! html/parsoid
<p>foo <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"><i data-parsoid='{"dsr":[9,14,2,2]}'>a</i>
 b</span></li>
</ol>
!! wikitext
foo <ref>''a''
 b</ref>
<references />
!! end

!! test
3. Leading whitespace in indent-pre suppressing contexts should not be escaped
!! options
parsoid=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
options=html2wt
!! html/parsoid
 <figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption>caption</figcaption></figure>
!! wikitext
 [[File:Foobar.jpg|thumb|caption]]
!! end

!! test
5. Nowiki escaping should account for indent-pres
!! options
parsoid=html2wt
!! html/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

#### --------------- 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

#### --------------- 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

#### --------------- 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
(Bug 52035) 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
!! 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
Table with broken attribute value quoting
!! wikitext
{|
| title="Hello world|Foo
|}
!! html/php
<table>
<tr>
<td title="Hello world">Foo
</td></tr></table>

!! html/parsoid
<table>
<tr>
<td title="Hello world">Foo
</td></tr></table>

!! end

!! test
Table with broken attribute value quoting on consecutive lines
!! wikitext
{|
| title="Hello world|Foo
| style="color:red|Bar
|}
!! html/php
<table>
<tr>
<td title="Hello world">Foo
</td>
<td style="color:red">Bar
</td></tr></table>

!! html/parsoid
<table><tbody>
<tr>
<td title="Hello world">Foo
</td><td style="color: red">Bar
</td></tr></tbody></table>

!! end

!! test
2. Parsoid-only: Don't wrap broken template tags in <nowiki> on wt2wt (Bug 42353)
!! options
parsoid
!! wikitext
{{}}
!! html
{{}}
!! end

!! test
1. Parsoid-only: Don't wrap broken template tags in <nowiki> on wt2wt (Bug 42353)
!! options
parsoid
!! wikitext
}}{{
!! html
}}{{
!! end

!!test
Accept empty td cell attribute
!! wikitext
{|
| align="center" | foo ||  |
|}
!! html
<table>
<tr>
<td align="center"> foo </td>
<td>
</td></tr></table>

!!end

!!test
Non-empty attributes in th-cells
!! wikitext
{|
! Foo !! style="color: red" | Bar
|}
!! html
<table>
<tr>
<th> Foo </th>
<th style="color: red"> Bar
</th></tr></table>

!!end

!!test
Accept empty attributes in th-cells
!! wikitext
{|
!| foo !!| bar
|}
!! html
<table>
<tr>
<th> foo </th>
<th> bar
</th></tr></table>

!!end

!!test
Empty table rows go away
!! wikitext
{|
| Hello
| there
|- class="foo"
|-
|}
!! html
<table>
<tr>
<td> Hello
</td>
<td> there
</td></tr>

</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
<table>

</table>

!!end

# Parsoid-only since PHP parser relies on Tidy for correct output
!!test
Trailing newlines in a deep dom-subtree that ends a wikitext line should be migrated out
!!options
parsoid
!! wikitext
{|
|<small>foo
bar
|}

{|
|<small>foo<small>
|}
!! html
<table>
<tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"autoInsertedEnd":true}'><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'>foo
<p>bar</p></small></td></tr>
</tbody></table>

<table>
<tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"autoInsertedEnd":true}'><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
{|
|-
|
|{{echo|style='color:red'}}|foo
|}
!! html
<table>

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

!!end

!!test
Indented table with an empty td
!! wikitext
 {|
 |-
 |
 |foo
 |}
!! html
<table>

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

!!end

## We have some newline diffs RT-ing this edge case
## and it is not important enough -- we seem to be emitting
## at most 2 newlines after a </tr> and this is unrelated to
## the issue from T85627 that this is testing.
!!test
Indented table with blank lines in between (T85627)
!! options
parsoid=wt2html
!! wikitext
 {|
 |foo
 
 
 |}
!! html
<table>

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

!!end

!!test
Indented block & table
!! wikitext
 <div>foo</div>
 {|
 |foo
 |}
!! html/php
 <div>foo</div>
<table>
<tr>
<td>foo
</td></tr></table>

!! html/parsoid
 <div data-parsoid='{"stx":"html"}'>foo</div>
 <table><tbody>
 <tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"autoInsertedEnd":true}'>foo</td></tr>
 </tbody></table>
!!end

!! test
Indent and comment before table row
!! wikitext
{|
 <!--hi-->|-
 | there
|}
!! html/php
<table>

<tr>
<td> there
</td></tr></table>

!! html/parsoid
<table>
 <!--hi--><tbody><tr data-parsoid='{"startTagSrc":"|-","autoInsertedEnd":true}'>
 <td data-parsoid='{"autoInsertedEnd":true}'> there</td></tr>
</tbody></table>
!! end

# Parsoid-specific since PHP parser doesn't handle this mixed tbl-wikitext
!!test
Empty TR followed by a template-generated TR
!!options
parsoid
!! wikitext
{|
|-
{{echo|<tr><td>foo</td></tr>}}
|}
!! html
<table>
<tbody>
<tr></tr>
<tr about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"<tr><td>foo</td></tr>"}},"i":0}}]}'>
<td>foo</td></tr>
</tbody></table>
!!end

## PHP and parsoid output differ for this, and since this is primarily
## for testing Parsoid's serializer, marking this Parsoid only
!!test
Empty TR followed by mixed-ws-comment line should RT correctly
!!options
parsoid
!! wikitext
{|
|-
 <!--c-->
|-
<!--c--> <!--d-->
|}
!! html
<table>
<tbody>
<tr></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{{echo|A}}\n{{echo|B}}\n{{echo|C}}]]
[[File:Foobar.jpg|thumb|300x300px|foo\n{{echo|A}}\n{{echo|B}}\n{{echo|C}}\n\n]]
!! html/parsoid
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300"/></a><figcaption>foo\n<span about="#mwt9" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"A"}},"i":0}}]}'>A</span>\n<span about="#mwt10" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"B"}},"i":0}}]}'>B</span>\n<span about="#mwt11" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"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="//example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300"/></a><figcaption>foo\n<span about="#mwt12" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"A"}},"i":0}}]}'>A</span>\n<span about="#mwt13" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"B"}},"i":0}}]}'>B</span>\n<span about="#mwt14" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"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>"}'/><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>
!! html/parsoid
<body><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>
</body>
!!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
plain text
!!end

!!test
1. Ensure fostered text content is wrapped in element nodes
!!options
parsoid=wt2html
!! wikitext
<table>hi</table><table>ho</table>
!! html/parsoid
<p>hi</p>
<table></table>
<p>ho</p>
<table></table>
!!end

!!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/parsoid
<p> || ||
</p><table>
<tbody><tr><td> a</td></tr>
</tbody></table>
!!end

!!test
Encapsulation properly handles null DSR information from foster box
!!options
parsoid=wt2html,wt2wt
!! wikitext
{{echo|<table>foo<tr><td>bar</td></tr></table>}}
!! html/parsoid
<span typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;<table>foo<tr><td>bar</td></tr></table>&quot;}},&quot;i&quot;:0}}]}">foo</span><table><tbody><tr><td>bar</td></tr></tbody></table>
!!end

!!test
1. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{echo|foo<tr><td>bar</td></tr>}}</table>
!! html/parsoid
<p typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo<tr><td>bar</td></tr>&quot;}},&quot;i&quot;:0}},&quot;</table>&quot;]}">foo</p><table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!!end

!!test
2. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table><div>{{echo|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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&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>{{echo|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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&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>{{echo|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;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&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
5. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table><tr><td><div><p>{{echo|foo</p></div></td>foo}}</tr></table>
!! html/parsoid
<p typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><tr><td><div><p>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo</p></div></td>foo&quot;}},&quot;i&quot;:0}},&quot;</tr></table>&quot;]}">foo</p>
<table>
<tbody>
<tr>
<td>
<div>
<p>foo</p>
</div>
</td>
</tr>
</tbody>
</table>
!!end

!!test
6. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table><tr><td><div><p>{{echo|foo</p></div></td>foo</tr></table>}}<p>ok</p>
!! html/parsoid
<p typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><tr><td><div><p>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo</p></div></td>foo</tr></table>&quot;}},&quot;i&quot;:0}}]}">foo</p>
<table>
<tbody>
<tr>
<td>
<div>
<p>foo</p>
</div>
</td>
</tr>
</tbody>
</table>
<p>ok</p>
!!end

!!test
7. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{echo|<p>foo</p>}}<td>bar</td></table>
!! html/parsoid
<p typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;echo&quot;,&quot;href&quot;:&quot;./Template:Echo&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;<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

# 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
{{echo|a
}}{|{{echo|style='color:red'}}
|-
|b
|}
!! html/parsoid
<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n"}},"i":0}}]}'>a</p>
<span> </span>
<p typeof="mw:Transclusion" data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"style":{"wt":"&#39;color:red&#39;"}},"i":0}},"\n|-\n|b\n|}"]}'>{{{1}}}</p>
<table>
<tbody>
<tr>
<td>b</td>
</tr>
</tbody>
</table>
!!end

!!test
9. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{echo|hi</table>hello}}
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi&lt;/table>hello"}},"i":0}}]}' data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"pi":[[{"k":"1","spc":["","","",""]}]]}'>hi</p><table about="#mwt2" data-parsoid='{"stx":"html"}'></table><p about="#mwt2">hello</p>
!!end

!!test
Table in fosterable position
!!options
parsoid=wt2html,wt2wt
!! 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>"]}' 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 bug 64747
!! 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","spc":["","","",""]}]]}'>

</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
Don't block XML namespace declaration
!! wikitext
<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">MediaWiki</span>
!! html/php
<p><span>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 serialization of new/edited content.
#
# All these tests are marked Parsoid html2wt and html2html only
# ----------------------------------------------------------------

# 'mi' is a localinterwiki prefix as well as a language
!! test
Serialize interwiki links pointing to the current wiki as plain wiki links (bug 65869)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://mi.wikipedia.org/wiki/Foo">Foo</a></p>
!! wikitext
[[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>
!! wikitext
[[Foo]]
[[Foo]]
!! 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

!! test
Image: Modifying size of an image (1)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["img[height]", "attr", "height", "22"],
    ["img[width]", "attr", "width", "200"]
  ]
}
!! wikitext
[[Image:Foobar.jpg|230x230px]]
!! wikitext/edited
[[Image:Foobar.jpg|200x200px]]
!!end

!! test
Image: Modifying size of an image (2)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["img[height]", "attr", "height", "100"],
    ["img[width]", "attr", "width", "500"]
  ]
}
!! wikitext
[[Image:Foobar.jpg|230x230px]]
!! wikitext/edited
[[Image:Foobar.jpg|500x500px]]
!!end

# Change in size is ignored so long as class='mw-default-size'
!! test
Image: Modifying size of an image (3)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["figure[class]", "removeClass", "mw-default-size"],
    ["figure img", "attr", "height", "19"],
    ["figure img", "attr", "width", "170"]
  ]
}
!! wikitext
[[Image:Foobar.jpg|thumb]]
!! wikitext/edited
[[Image:Foobar.jpg|thumb|170x170px]]
!!end

!! test
Image: Modifying alignment of an image (bug 48665)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["figure[class]", "removeClass", "mw-halign-right"],
    ["figure[class]", "addClass", "mw-halign-left"]
  ]
}
!! wikitext
[[Image:Foobar.jpg|thumb|caption|right]]
!! wikitext/edited
[[Image:Foobar.jpg|thumb|caption|left]]
!! end

!! test
Image: Modifying mw-default-size of an frameless image (bug 62805)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["figure.mw-default-size", "removeClass", "mw-default-size"]
  ]
}
!! wikitext
[[Image:Foobar.jpg|frameless|right]]
!! wikitext/edited
[[Image:Foobar.jpg|frameless|right|220x220px]]
!! end

!! test
Image: Modifying valign of an image (bug 49221)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["*[typeof=\"mw:Image\"]", "removeClass", "mw-valign-middle"],
    ["*[typeof=\"mw:Image\"]", "addClass", "mw-valign-text-top"]
  ]
}
!! wikitext
[[File:Foobar.jpg|20px|middle]]
!! wikitext/edited
[[File:Foobar.jpg|20px|text-top]]
!! end

!! test
Image: Modifying alt attribute of an image (bug 56400)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["img[alt]", "attr", "alt", "some alternate edited text"]
  ]
}
!! wikitext
[[File:Foobar.jpg|thumb|some caption|alt=some alternate text]]
!! wikitext/edited
[[File:Foobar.jpg|thumb|some caption|alt=some alternate edited text]]
!!end

!! test
Image: Modifying caption of an image
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["figcaption", "text", "new caption"]
  ]
}
!! wikitext
[[Image:Foobar.jpg|thumb|original caption]]
!! wikitext/edited
[[Image:Foobar.jpg|thumb|new caption]]
!!end

!! test
Image: empty alt attribute (bug 48924)
!! options
parsoid
!! wikitext
[[File:Foobar.jpg|thumb|alt=|bar]]
!! html
<figure class="mw-default-size" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"alt","ak":"alt="},{"ck":"caption","ak":"bar"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img alt="" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220" data-parsoid='{"a":{"alt":"","resource":"./File:Foobar.jpg","height":"25","width":"220"},"sa":{"alt":"alt=","resource":"File:Foobar.jpg"}}'/></a><figcaption>bar</figcaption></figure>
!! end

!! test
Image: new attributes should be serialized in wiki's language for RTL languages (bug 51852)
!! options
parsoid=html2wt
language=ar
disabled
!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:Image/Thumb"><a href="./Imagen:Foobar.jpg"><img resource="./Imagen:Foobar.jpg" src="//example.com/images/3/3a/Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="20" width="180"/></a></figure>
!! wikitext
[[Imagen:Foobar.jpg|derecha|miniaturadeimagen]]
!! end

!! test
Image: Block level image should have \n before and after
!! wikitext
123
[[File:Foobar.jpg|right|thumb|150x150px]]
456
!! html/parsoid
<p>123</p>
<figure class="mw-halign-right" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/150px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="17" width="150"/></a></figure>
<p>456</p>
!!end

!! test
Image: New block level image should have \n before and after (existing content)
!! wikitext
123
[[File:Foobar.jpg|right|thumb|150x150px]]
456
!! html/parsoid
<p>123</p>
<figure class="mw-halign-right" typeof="mw:Image/Thumb" data-parsoid='{"optList":[{"ck":"right","ak":"right"},{"ck":"thumbnail","ak":"thumb"},{"ck":"width","ak":"150x150px"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"}}'><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/150px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="17" width="150" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"17","width":"150"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></figure>
<p>456</p>
!!end

!! test
Image: upright option (parsoid)
!! wikitext
[[File:Foobar.jpg|thumb|upright|caption]]
[[File:Foobar.jpg|thumb|upright=0.5|caption]]
[[File:Foobar.jpg|thumb|500x500px|upright=0.5|caption]]
!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/170px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="19" width="170"/></a><figcaption>caption</figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/110px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="12" width="110"/></a><figcaption>caption</figcaption></figure>
<figure typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/500px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="57" width="500"/></a><figcaption>caption</figcaption></figure>
!!end

!! test
Image: upright option is ignored on inline and frame images (parsoid)
!! wikitext
[[File:Foobar.jpg|500x500px|upright=0.5|caption]]
!! html/parsoid
<p><span typeof="mw:Image" data-mw='{"caption":"caption"}'><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/500px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="57" width="500"/></a></span></p>
!!end

!! test
Image: from basic HTML (1)
!! options
parsoid=html2wt
!! html/parsoid
<span typeof="mw:Image">
  <img src="./File:Foobar.jpg" width=100 height=100 alt="Alt">
</span>
!! wikitext
[[File:Foobar.jpg|link=|alt=Alt|100x100px]]
!! end

!! test
Image: from basic HTML (2)
!! options
parsoid=html2wt
!! html/parsoid
<img src="./File:Foobar.jpg" width=100 height=100 alt="Alt">
!! wikitext
[[File:Foobar.jpg|link=|alt=Alt|100x100px]]
!! end

!! test
Image: from basic HTML (3)
!! options
parsoid=html2wt
!! html/parsoid
<a href="Main"><img src="./File:Foobar.jpg" width=100 height=100 alt="Alt"></a>
!! wikitext
[[File:Foobar.jpg|link=Main|alt=Alt|100x100px]]
!! end

!! test
Image: from basic HTML (4)
!! options
parsoid=html2wt
!! html/parsoid
<img src="./File:Foobar.jpg">
!! wikitext
[[File:Foobar.jpg|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
<nowiki> </nowiki><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":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo [[Category:Foo]]"}},"i":0}}]}'>foo </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" data-parsoid="{}" /></h2>
!! wikitext
== {{echo|foo [[Category:Foo]]}} ==
!! 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" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> </h2>

<ol class="references" typeof="mw:Extension/references" about="#mwt3" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">bar <link rel="mw:PageProp/Category" href="./Category:Baz" /> </span></li></ol>
!! wikitext
== 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":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"f=oo"}},"i":0}}]}'>foo</p>

<p about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"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","spc":["","","",""]},{"k":"2","spc":["","","",""]}]]}' about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"f=oo"},"2":{"wt":"bar"}},"i":0}}]}'>foo</p>
!! wikitext
{{echo|1 = f=oo}}

{{echo|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-->
{{echo|<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":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"http://stuff?is=ok"}},"i":0}}]}'>http://stuff?is=ok</a></p>
!! wikitext
{{echo|1 = http://stuff?is=ok}}
!! 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" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> </h2>

<ol class="references" typeof="mw:Extension/references" about="#mwt3" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">hello
there</span></li></ol>

<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

!! test
Serialize new placeholder space without spans
!! options
parsoid=html2wt
!! html/parsoid
<p>foo<span typeof="mw:Placeholder"> </span>: bar</p>

<p>foo<span typeof="mw:DisplaySpace mw:Placeholder" data-parsoid='{"src":" ","isDisplayHack":true}'> </span>: bar</p>

<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:Placeholder\&quot;>&amp;nbsp;</span>: bar&quot;}}"><sup>[1]</sup></span>ok</p>
!! wikitext
foo : bar

foo : bar

<ref>foo : bar</ref>ok
!! 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":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&#39;&#39;B&#39;&#39;"}},"i":0}}]}'>B</i>
<p><i>A</i><b about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&#39;&#39;&#39;&#39;&#39;B&#39;&#39;&#39;&#39;&#39;"}},"i":0}}]}'><i>B</i></b>
!! wikitext
''A''{{echo|''B''}}

''A''{{echo|'''''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|''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

#------------------------------
# End of tag minimization tests
#------------------------------

!!test
Bug 54262: 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="//tools.ietf.org/html/rfc123" rel="mw:ExtLink">New RFC</a>
!! wikitext
[//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<nowiki/>'''foo'''

http://cscott.net<b>foo</b>

'''http://cscott.net<nowiki/>'''

'''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">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": [
    [ "meta", "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 is not a link.</nowiki>
!! end

!! test
WTS of autolink-like text after an autolink (T108563)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a> http://example.com is not a link.</p>
!! wikitext
http://example.com<nowiki> http://example.com is not a link.</nowiki>
!! end

!! test
Magic links inside links (not autolinked)
!! wikitext
[[Foo|http://example.com]]
[[Foo|RFC 1234]]
[[Foo|PMID 1234]]
[[Foo|ISBN 123456789x]]

[http://foo.com http://example.com]
[http://foo.com RFC 1234]
[http://foo.com PMID 1234]
[http://foo.com ISBN 123456789x]
!! html+tidy
<p><a href="/wiki/Foo" title="Foo">http://example.com</a> <a href="/wiki/Foo" title="Foo">RFC 1234</a> <a href="/wiki/Foo" title="Foo">PMID 1234</a> <a href="/wiki/Foo" title="Foo">ISBN 123456789x</a></p>
<p><a rel="nofollow" class="external text" href="http://foo.com">http://example.com</a> <a rel="nofollow" class="external text" href="http://foo.com">RFC 1234</a> <a rel="nofollow" class="external text" href="http://foo.com">PMID 1234</a> <a rel="nofollow" class="external text" href="http://foo.com">ISBN 123456789x</a></p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo" title="Foo">http://example.com</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">RFC 1234</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">PMID 1234</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">ISBN 123456789x</a></p>

<p><a rel="mw:ExtLink" href="http://foo.com">http://example.com</a>
<a rel="mw:ExtLink" href="http://foo.com">RFC 1234</a>
<a rel="mw:ExtLink" href="http://foo.com">PMID 1234</a>
<a rel="mw:ExtLink" href="http://foo.com">ISBN 123456789x</a></p>
!! end

!! test
Magic links inside image captions (autolinked)
!! wikitext
[[File:Foobar.jpg|thumb|http://example.com]]
[[File:Foobar.jpg|thumb|RFC 1234]]
[[File:Foobar.jpg|thumb|PMID 1234]]
[[File:Foobar.jpg|thumb|ISBN 123456789x]]
!! html+tidy
<div class="thumb tright">
<div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>
<div class="thumbcaption">
<div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></div>
</div>
</div>
<div class="thumb tright">
<div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>
<div class="thumbcaption">
<div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>
<a class="external mw-magiclink-rfc" rel="nofollow" href="//tools.ietf.org/html/rfc1234">RFC 1234</a></div>
</div>
</div>
<div class="thumb tright">
<div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>
<div class="thumbcaption">
<div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>
<a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a></div>
</div>
</div>
<div class="thumb tright">
<div class="thumbinner" style="width:182px;"><a href="/wiki/File:Foobar.jpg" class="image"><img alt="" src="http://example.com/images/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" width="180" height="20" class="thumbimage" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/270px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/360px-Foobar.jpg 2x" /></a>
<div class="thumbcaption">
<div class="magnify"><a href="/wiki/File:Foobar.jpg" class="internal" title="Enlarge"></a></div>
<a href="/wiki/Special:BookSources/123456789X" class="internal mw-magiclink-isbn">ISBN 123456789x</a></div>
</div>
</div>
!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a rel="mw:ExtLink" href="http://example.com">http://example.com</a></figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="//tools.ietf.org/html/rfc1234" rel="mw:ExtLink">RFC 1234</a></figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink">PMID 1234</a></figcaption></figure>
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/220px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="25" width="220"/></a><figcaption><a href="./Special:BookSources/123456789X" rel="mw:WikiLink">ISBN 123456789x</a></figcaption></figure>
!! end

!! test
WTS of magic word text (T109371)
!! options
parsoid=html2wt
!! html/parsoid
<p>RFC 1234</p>
<p><a href="http://foo.com" rel="mw:ExtLink">RFC 1234</a></p>
<p><a href="./Foo" rel="mw:WikiLink">RFC 1234</a></p>
!! wikitext
<nowiki>RFC 1234</nowiki>

[http://foo.com RFC 1234]

[[Foo|RFC 1234]]
!! end

!! test
Edited Redirect link should emit a non-piped wikitext link
!! options
parsoid=html2wt
!! html/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=html2wt
!! 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>
<tr>
<th>-</th>
<th>-</th>
</tr>
<tr>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td><small>-</small></td>
<td><br />
<p>-</p>
</td>
<td><br />
<p>-</p>
</td>
</tr>
</table>
!! 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
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=html2wt
!! 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=html2wt
!! html/parsoid
<a bad='true' href='http://boo.org'><img src='http://boohoo.org' /></a>
!! wikitext
[http://boo.org http://boohoo.org]
!! end

# Misnested is an indication that selser can reuse the source but these have
# shown to sneak through on occasion. See T101768.
# The original wikitext here is: [http://test.com [[one]] two three]
!! test
Strip span tags added to mark as misnested
!! options
parsoid=html2wt
!! html/parsoid
<p data-parsoid='{}'><a rel="mw:ExtLink" href="http://test.com" data-parsoid='{"targetOff":17,"contentOffsets":[17,34]}'></a><a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"simple","a":{"href":"./One"},"sa":{"href":"one"},"misnested":true}'>one</a><span data-parsoid='{"misnested":true}'> two three</span></p>
!! wikitext
[http://test.com][[one]] two three
!! end

# --------------------------------------------
# Tests spec'ing wikitext serialization norms |
# --------------------------------------------

!! 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
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
<h2><i></i></h2>
<p><a href='Foo' rel='mw:WikiLink'>foo<i></i>
 </a><b><i></i></b>x</p>
!! wikitext

[[foo]]
x

!! end

!! test
2. Multiple normalizations (selser)
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    [ "#x", "after", "<h1><i></i></h1>\n<p> x<b></b></p>"]
  ]
}
!! wikitext
<span id="x">foo</span>
!! wikitext/edited
<span id="x">foo</span>

x
!! end

!! test
1. Indent Pre Nowiki: suppress whitespace at the start of new paragraph
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<p> hi</p>
<p>    hello</p>
!! wikitext
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
<table>
<tr><td>a</td></tr>
<tr><td>-</td></tr>
<tr><td>+</td></tr>
</table>
!! wikitext
{|
|a
|-
|<nowiki>-</nowiki>
|-
|<nowiki>+</nowiki>
|}
!! end

!! test
2. Table cells with escapable prefixes
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html
<table>
<tr><td>a</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

!! test
Escape nowiki DOM elements
!! options
parsoid=html2wt
!! html/parsoid
<nowiki><i>foo</i></nowiki>
!! wikitext
&lt;nowiki&gt;''foo''&lt;/nowiki&gt;
!! end

# ---------------------------------------------------
# End of tests spec'ing wikitext serialization norms |
# ---------------------------------------------------

# -----------------------------------------------------------------
# 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
