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

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

!!article
Foo
!!text
FOO
!!endarticle

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

!! article
Template:CircularRef
!! text
<ref>{{CircularRef}}</ref>
!! endarticle

###
### Basic tests
###
!! test
Blank input
!! wikitext
!! html
!! end

!! test
CircularRef
!! wikitext
{{CircularRef}}
<references />
!! html/parsoid
<p><span about="#mwt1" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Transclusion  mw:Extension/ref" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"CircularRef","href":"./Template:CircularRef"},"params":{},"i":0}}]}'><a href="./Main_Page#cite_note-1" style="counter-reset: mw-Ref 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-1" id="cite_note-1"><a href="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">Error: Expansion loop detected at <a data-parsoid='{"a":{"href":null},"sa":{"href":"Template:CircularRef"}}'>Template:CircularRef</a></span></li></ol>
!! 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
Heading with line break in nowiki
!! options
parsoid=wt2html
!! wikitext
== A <nowiki>B
C</nowiki> ==
!! html
<h2><span class="mw-headline" id="A_B.0AC">A B
C</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: A B&#10;C">edit</a><span class="mw-editsection-bracket">]</span></span></h2>

!! html/parsoid
<h2 id="A_B.0AC">A <span typeof="mw:Nowiki">B
C</span> </h2>
!! end

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

# Note that the html+tidy output removes the spaces after the <li>,
# which is a bug (https://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 (T49326)
!! test
Italics and possessives (1)
!! wikitext
obtained by ''[[Lunar Prospector]]'''s gamma-ray spectrometer
!! html
<p>obtained by <i><a href="/index.php?title=Lunar_Prospector&amp;action=edit&amp;redlink=1" class="new" title="Lunar Prospector (page does not exist)">Lunar Prospector</a>'</i>s gamma-ray spectrometer
</p>
!! end

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

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


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

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

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

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

# 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
!! wikitext
'''foo''''bar''<nowiki/>''
!! html/php
<p><b>foo'</b>bar
</p>
!! html/parsoid
<p><b>foo'</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
'''foo''''bar'''<nowiki/>'''
!! html/php
<p><b>foo'</b>bar
</p>
!! html/parsoid
<p><b>foo'</b>bar<b></b>
</p>
!! end

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


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


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


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


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


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


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

!! test
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 (T54468)
!! wikitext
<wbr>
!! html
<p><wbr />
</p>
!! end

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

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

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

# test cases taken from
# https://www.w3.org/TR/html5/text-level-semantics.html#the-ruby-element
!! test
Ruby markup (W3C-style)
!! wikitext
; Mono-ruby for individual base characters
: <ruby>日<rt>に</rt>本<rt>ほん</rt>語<rt>ご</rt></ruby>
; Group ruby
: <ruby>今日<rt>きょう</rt></ruby>
; Jukugo ruby
: <ruby>法<rb>華</rb><rb>経</rb><rt>ほ</rt><rt>け</rt><rt>きょう</rt></ruby>
; Inline ruby
: <ruby>東<rb>京</rb><rp>(</rp><rt>とう</rt><rt>きょう</rt><rp>)</rp></ruby>
; Double-sided ruby
: <ruby><rb>旧</rb><rb>金</rb><rb>山</rb><rt>jiù</rt><rt>jīn</rt><rt>shān</rt><rtc>San Francisco</rtc></ruby>
<ruby>
<rb>♥</rb><rtc><rt>Heart</rt></rtc><rtc lang="fr"><rt>Cœur</rt></rtc>
<rb>☘</rb><rtc><rt>Shamrock</rt></rtc><rtc lang="fr"><rt>Trèfle</rt></rtc>
<rb>✶</rb><rtc><rt>Star</rt></rtc><rtc lang="fr"><rt>Étoile</rt></rtc>
</ruby>
!! html
<dl><dt> Mono-ruby for individual base characters</dt>
<dd> <ruby>日<rt>に</rt>本<rt>ほん</rt>語<rt>ご</rt></ruby></dd>
<dt> Group ruby</dt>
<dd> <ruby>今日<rt>きょう</rt></ruby></dd>
<dt> Jukugo ruby</dt>
<dd> <ruby>法<rb>華</rb><rb>経</rb><rt>ほ</rt><rt>け</rt><rt>きょう</rt></ruby></dd>
<dt> Inline ruby</dt>
<dd> <ruby>東<rb>京</rb><rp>(</rp><rt>とう</rt><rt>きょう</rt><rp>)</rp></ruby></dd>
<dt> Double-sided ruby</dt>
<dd> <ruby><rb>旧</rb><rb>金</rb><rb>山</rb><rt>jiù</rt><rt>jīn</rt><rt>shān</rt><rtc>San Francisco</rtc></ruby></dd></dl>
<p><ruby>
<rb>♥</rb><rtc><rt>Heart</rt></rtc><rtc lang="fr"><rt>Cœur</rt></rtc>
<rb>☘</rb><rtc><rt>Shamrock</rt></rtc><rtc lang="fr"><rt>Trèfle</rt></rtc>
<rb>✶</rb><rtc><rt>Star</rt></rtc><rtc lang="fr"><rt>Étoile</rt></rtc>
</ruby>
</p>
!! end

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

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

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

<boo> doesn't terminate </boo>

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

<sub-ID#1>
!! html
<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: https://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>

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

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

<s.foo>s</s>
!! html/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 (T54363)
!! wikitext
|
!! html
<p>|
</p>
!! end

!! test
Bare pipe character from a template (T54363)
!! 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
Don't parse <nowiki><span class="error"></nowiki> (T149622)
!! wikitext
<nowiki><span class="error"></nowiki>
!! html/php
<p>&lt;span class="error"&gt;
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">&lt;span class="error"></span></p>
!! end

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

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

*There is not nowiki.
*There is <nowiki>nowiki</nowiki>.
!! html/php
<dl><dd>There is not nowiki.</dd>
<dd>There is nowiki.</dd></dl>
<ol><li>There is not nowiki.</li>
<li>There is nowiki.</li></ol>
<ul><li>There is not nowiki.</li>
<li>There is nowiki.</li></ul>

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

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

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

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

!! test
Entities inside template parameters
!! wikitext
{{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|<nowiki>a }} b</nowiki>}}
{{echo|<nowiki>a [[ b</nowiki>}}
{{echo|<nowiki>a | {{ ]]</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
T54763: 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
T53086: Double newlines in blockquotes should be turned into paragraphs
!! wikitext
<blockquote>
Foo

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

!! end

!! test
T17491: <ins>/<del> in blockquote
!! wikitext
<blockquote>
Foo <del>bar</del> <ins>baz</ins> quux
</blockquote>
!! html
<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 T8200)
!! test
T17491: <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 (T5202)
!! wikitext
<pre style="background: blue; color:white">Bluescreen of WikiDeath</pre>
!! html
<pre style="background: blue; color:white">Bluescreen of WikiDeath</pre>

!! end

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

!! end

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

!! end

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

!! end

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

!! end

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

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

!! end

!! test
<nowiki> inside of #tag:pre
!! wikitext
{{#tag:pre|Foo <nowiki>&rarr;bar</nowiki>}}
!! html/php
<pre>Foo &#8594;bar</pre>

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

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

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

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

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


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

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

# Parsoid doesn't strip empty tags, like Tidy does.
!! test
Empty pre; pre inside other HTML tags (T56946)
!! 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 data-parsoid='{"stx":"html"}'><pre typeof="mw:Extension/pre" about="#mwt2" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"\nfoo\n"}}'>foo
</pre></div>
<pre typeof="mw:Extension/pre" about="#mwt4" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{},"body":{"extsrc":""}}'></pre>
!! end

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

# 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 typeof="mw:Extension/pre" about="#mwt2" data-parsoid='{"stx":"html"}' data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"foo"}}'>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

## Hmm, should Parsoid rt this?
!! test
Pres with newline attributes
!! options
parsoid=wt2html,html2html
!! wikitext
<pre class="one
two">hi</pre>
!! html/php
<pre class="one two">hi</pre>

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

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

!! test
Handle broken pre-like tags (T66025)
!! options
parsoid=wt2html
!! wikitext
{{echo|<pre <pre>x</pre>}}

<table><pre </table>
!! html/php
<pre>x</pre>
<table>&lt;pre </table>

!! html/php+tidy
<pre>
x
</pre>
<p>&lt;pre</p>
!! html/parsoid
<pre about="#mwt1" typeof="mw:Transclusion mw:Extension/pre" data-parsoid='{"a":{"&lt;pre":null},"sa":{"&lt;pre":""},"stx":"html","pi":[[{"k":"1"}]]}' 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 typeof="mw:Extension/pre" about="#mwt2" style="width:50%;" data-mw='{"name":"pre","attrs":{"style":"width:50%;"},"body":{"extsrc":"{{echo|foo}}"}}'>{{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/php
<p>foo
bar
</p>
!! html/parsoid
<p typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"foo\n&lt;!--should be ignored-->\n &lt;!--should be ignored as well-->\nbar"}},"i":0}}]}'>foo <!--should be ignored--> <!--should be ignored as well--> bar</p>
!! end

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

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

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

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

{{<!-- should be ignored -->echo|foo}}
!! html/php
<p>foo
</p><p>foo
</p><p>foo
</p><p>foo
</p><p>foo
</p>
!! 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\n&lt;!-- should be ignored and spaces on next line should not trip us up (T147742) -->\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 (T69657)
!! 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/php
<p>foo
</p><p>foo
</p><p>foo
</p><p>foo
</p>
!! 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 (T69657)
!! wikitext
{{echo|''1''=foo}}
!! html/php
<p>{{{1}}}
</p>
!! 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>
!!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%7Cb" 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%7Cb</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

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

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

## 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"},{"k":"","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"blank_param","href":"./Template:Blank_param"},"params":{"1":{"wt":"bar"},"":{"wt":"foo"}},"i":0}}]}'>bar
foo</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 (T44252)
!! 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
2g. Indented table markup mixed with indented pre content (proposed in T8200)
!! wikitext
 <table>
 <tr>
 <td>
 Text that should be rendered preformatted
 </td>
 </tr>
 </table>
!! html
 <table>
 <tr>
 <td>
<pre>Text that should be rendered preformatted
</pre>
 </td>
 </tr>
 </table>

!! end

!!test
3a. Indent-Pre and block tags (single-line html)
!! wikitext
 a <p> foo </p>
 b <div> foo </div>
 c <blockquote> foo </blockquote>
 <span> foo </span>
!! html
 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 <tag />
!! html/php
 a <pre>
NULL
array (
)
</pre>

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

!! test
5. Indent-Pre and html pre
!! wikitext
 <pre class="123">hi</pre>
!! html/php
 <pre class="123">hi</pre>

!! html/parsoid
 <pre typeof="mw:Extension/pre" about="#mwt2" class="123" data-mw='{"name":"pre","attrs":{"class":"123"},"body":{"extsrc":"hi"}}'>hi</pre>
!! 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

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

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

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

foo
</pre>

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


foo
</pre>
!!end

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




haha




haha




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




haha




haha




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




haha




haha




</pre>
!! end

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

!!end

!!test
HTML-pre: 3: other wikitext
!! wikitext
<pre>
* foo
# bar
= no-h =
'' no-italic ''
[[ NoLink ]]
</pre>
!! html/php
<pre>
* foo
# bar
= no-h =
'' no-italic ''
[[ NoLink ]]
</pre>

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

###
### Definition lists
###
!! test
Simple definition
!! 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
Definition lists: ignore colons inside tags
!! wikitext
;one <b>two : tag <i>fun:</i>:</b>: def
!! html
<dl><dt>one <b>two&#160;: tag <i>fun:</i>:</b></dt>
<dd> def</dd></dl>

!! end

!! test
Definition lists: excess closed tags
!! wikitext
;one</b>two : bad tag fun
!! html/php+tidy
<dl>
<dt>onetwo&#160;</dt>
<dd>bad tag fun</dd>
</dl>
!! html/parsoid
<dl>
<dt>onetwo</dt>
<dd>bad tag fun</dd>
</dl>
!! end

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

!! end

!! test
Definition and unordered list using wiki syntax nested in unordered list using html tags.
!! 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>
!! html
<dl><dt>x</dt>
<dd>a</dd>
<dd>b</dd></dl>

!! end

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

!! end

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

!! end

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

!! end

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

!! end

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

!! test
Definition Lists: Hacky use to indent tables, with comment before table
!! 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 https://lists.wikimedia.org/pipermail/wikitext-l/2011-November/000483.html

!! test
Table / list interaction: indented table with lists in table contents
!! wikitext
:{|
|-
| a
* b
|-
| c
* d
|}
!! html
<dl><dd><table>

<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"}]]}' 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"}]]}' 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 T55505
!! test
External links: numbered
!! wikitext
Numbered: [http://example.com]
Numbered: [http://example.net]
Numbered: [http://example.com]
!! html/php
<p>Numbered: <a rel="nofollow" class="external autonumber" href="http://example.com">[1]</a>
Numbered: <a rel="nofollow" class="external autonumber" href="http://example.net">[2]</a>
Numbered: <a rel="nofollow" class="external autonumber" href="http://example.com">[3]</a>
</p>
!! html/parsoid
<p>Numbered: <a rel="mw:ExtLink" href="http://example.com"></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 T55505
!! test
External links: dollar sign in URL (autonumber)
!! wikitext
[http://example.com/1$2345]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://example.com/1$2345">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/1$2345"></a></p>
!!end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

# Since Parsoid is starting to emit canonical wikitext for links,
# [http://example.com http://example.com] will not RT back to that
# form anymore.
!! test
External links: URL in text
!! options
parsoid=wt2html
!! wikitext
URL in text: [http://example.com http://example.com]
!! html/php
<p>URL in text: <a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
</p>
!! html/parsoid
<p>URL in text: <a rel="mw:ExtLink" 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 (T8102)
!! wikitext
http://example.com/?foo&#61;bar
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com/?foo=bar">http://example.com/?foo=bar</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/?foo=bar">http://example.com/?foo=bar</a></p>
!! end

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

!! test
External links: [raw ampersand]
!! wikitext
Old &amp; use: [http://x&y]
!! html/php
<p>Old &amp; use: <a rel="nofollow" class="external autonumber" href="http://x&amp;y">[1]</a>
</p>
!! html/parsoid
<p>Old <span typeof="mw:Entity">&amp;</span> use: <a rel="mw:ExtLink" href="http://x&amp;y"></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] (T8102)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[http://example.com/?foo&#61;bar]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://example.com/?foo=bar">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/?foo=bar"></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 (T2554)
!! wikitext
http://www.jpeg.org
!! html
<p><a rel="nofollow" class="external free" href="http://www.jpeg.org">http://www.jpeg.org</a>
</p>
!! end

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

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

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

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

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

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

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

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

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

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

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

!! test
External links: wiki links within external link (T5695)
!! options
parsoid=wt2html,html2html
!! 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
T2787: Links with one slash after the url protocol are invalid
!! wikitext
http:/example.com

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

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

!! test
T4702: Mismatched <i>, <b> and <a> tags are invalid
!! wikitext
''[http://example.com text'']
[http://example.com '''text]'''
''Something [http://example.com in italic'']
''Something [http://example.com mixed''''', even bold]'''
'''''Now [http://example.com both''''']
!! html
<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
T6781: %26 in URL
!! wikitext
http://www.example.com/?title=AT%26T
!! html/php
<p><a rel="nofollow" class="external free" href="http://www.example.com/?title=AT%26T">http://www.example.com/?title=AT%26T</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.example.com/?title=AT%26T">http://www.example.com/?title=AT%26T</a></p>
!! end

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

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


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

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

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


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

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

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

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

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

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

[//foo.org/bar'baz bang]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="//foo.org/bar'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 '' (T6598 sanity check)
!! wikitext
Some [http://example.com/ pretty ''italics'' and stuff]!
!! html
<p>Some <a rel="nofollow" class="external text" href="http://example.com/">pretty <i>italics</i> and stuff</a>!
</p>
!! end

!! test
External link containing double-single-quotes in text embedded in italics (T6598 sanity check)
!! wikitext
''Some [http://example.com/ pretty ''italics'' and stuff]!''
!! html
<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%5B%5D=bar" data-parsoid='{"stx":"url","a":{"href":"http://example.com/index.php?foozoid%5B%5D=bar"},"sa":{"href":"http://example.com/index.php?foozoid&amp;#x5B;&amp;#x5D;=bar"}}'>http://example.com/index.php?foozoid%5B%5D=bar</a></p>
!! end

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

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

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

!! html/php
<p><a rel="nofollow" class="external free" href="http://[2404:130:0:1000::187:2]/index.php">http://[2404:130:0:1000::187:2]/index.php</a>
</p><p>Examples from <a class="external mw-magiclink-rfc" rel="nofollow" href="//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=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[20,31,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"hi\"}},\"i\":0}}]}&#39;>hi&lt;/span>"}]]}'>http://example.com/hi</a>)</p>

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

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

!! test
mw:ExtLink -vs- mw:WikiLink (T94723)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"piped","a":{"href":"./Foo"},"sa":{"href":"Foo"}}'>Bar</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">Bar</a>
<a rel="mw:WikiLink" href="http://en.wikipedia.org/wiki/Foo" title="Foo">Bar</a>
<a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/Foo" title="Foo">Bar</a>
<p>
<a rel="mw:ExtLink" href="http://en.wikipedia.org/wiki/European_Robin">European Robin</a>
<a rel="mw:WikiLink" href="http://en.wikipedia.org/wiki/European_Robin">European Robin</a>
</p>
!! wikitext
[[Foo|Bar]]
[[Foo|Bar]]
[[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:
# https://www.w3.org/TR/xhtml-modularization/dtd_module_defs.html#a_module_Basic_Tables
# Parsoid team replies: empty table tags are legal in HTML5
!! test
A table with no data.
!! options
parsoid=wt2html
!! wikitext
{||}
!! html/php

!! html/parsoid
<table></table>

!! end

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

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

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

{|style="color: red;" |} id="foo"
|foo
|}
!! html
<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"}]]}' 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 (T3830)
!! 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://%7Cx" data-parsoid='{"stx":"url","a":{"href":"ftp://%7Cx"},"sa":{"href":"ftp://|x"}}'>ftp://%7Cx</a></td><td data-parsoid='{"stx_v":"row","autoInsertedEnd":true}'>]" onmouseover="alert(document.cookie)">test</td></tr></tbody></table>
!! end

!! test
Element attributes with double ! should not be broken up by <th>
!! wikitext
{|
! hi <div class="!!">ha</div> ho
|}
!! html/php
<table>
<tr>
<th> hi <div class="!!">ha</div> ho
</th></tr></table>

!! html/parsoid
<table>
<tbody><tr><th> hi <div class="!!" data-parsoid='{"stx":"html"}'>ha</div> ho</th></tr>
</tbody></table>
!! end

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

!! html/parsoid
<table>
<tbody><tr><td> <div style="color: red !important;" data-contrived="put this here ||" data-parsoid='{"stx":"html"}'>hi</div></td></tr>
</tbody></table>
!! end

# FIXME: The output seems broken. Filed as T110268.
!! test
! and || in td attributes should not be parsed as <th>/<td>
!! options
parsoid=wt2html
!! wikitext
{|
| style="color: red !important;" data-contrived="put this here ||" | foo
|}
!! html/php
<table>
<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
Break on | in element attribute in template
!! options
parsoid=wt2html,html2html
!! wikitext
{{echo|1=<div class="hi|ho">ha</div>}}
!! html/php
<p>ho"&gt;ha&lt;/div&gt;
</p>
!! html/parsoid
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"ho\">ha&lt;/div>"}},"i":0}}]}'>ho">ha</span>
!! end

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

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

<references />
!! html/parsoid
<p><span about="#mwt2" class="mw-ref" id="cite_ref-hi.7Cho_1-0" rel="dc:references" typeof="mw:Transclusion  mw:Extension/ref" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;ref name=\"hi|ho\">ha&lt;/ref>"}},"i":0}}]}'><a href="./Main_Page#cite_note-hi.7Cho-1" style="counter-reset: mw-Ref 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-hi.7Cho-1" id="cite_note-hi.7Cho-1"><a href="./Main_Page#cite_ref-hi.7Cho_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-hi.7Cho-1" class="mw-reference-text">ha</span></li></ol>
!! end

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

!! html/parsoid
<table style="border:1px solid black">
<tr>
<td style="color:blue"> 1</td>
<td style="color:blue"> 2</td>
</tr>
</table>
!! end

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

!! test
1. Template-generated table cell attributes and cell content
!! wikitext
{|
|{{table_attribs}}
| {{table_attribs}}
|| {{table_attribs_5}}
| <!--foo--> <!--bar--> <!--baz--> {{table_attribs}}
|align=center {{table_attribs}}
| <!--foo--> align=center <!--bar--> {{table_attribs}}
|}
!! html
<table>
<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="./Main_Page#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="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">foo</span></li></ol>
!! end

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

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


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

!! end

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

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


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

!! end

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

!! html/parsoid
<table>
<tbody><tr><td style=""> hello</td></tr>
</tbody></table>
!! end

!! test
Wikitext table with a lot of comments
!! wikitext
{|
<!-- c0 -->
| foo
<!-- c1 -->
|-<!-- c2 -->
<!-- c3 -->
|<!-- c4 -->
<!-- c5 -->
|}
!! html
<table>
<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

!! test
Implicit <td> after a |-
!! options
parsoid=wt2html,html2html
!! wikitext
{|
|-
a
|}
!! html/php
<table>

a
</table>

!! html/php+tidy
<p>a</p>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true}'>a</p><table>
<tbody><tr data-parsoid='{"startTagSrc":"|-","autoInsertedEnd":true}'>

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

!! 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
<ul data-parsoid='{"fostered":true,"autoInsertedEnd":true}'><li>a</li></ul><table>
<tbody><tr data-parsoid='{"startTagSrc":"|-","autoInsertedEnd":true}'>

</tr></tbody></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}}," || a || b"]}'> </td><td about="#mwt1"> a </td><td about="#mwt1"> b</td></tr>
!! end

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

{|
|baz
|}<b>quux</b>
!! html+tidy
<table>
<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 (T53219)
!! options
parsoid=html2wt
!! html/parsoid
<table><tbody>
<tr><td>foo</td></tr></tbody></table> bar
<table><tbody>
<tr><td>baz</td></tr></tbody></table><b>quux</b>
!! wikitext
{|
|foo
|}
<nowiki> </nowiki>bar
{|
|baz
|}
'''quux'''
!! end

!! test
Parsoid: 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

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

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

!! test
Testing serialization after deletion in references
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    ["#x", "remove"]
  ]
}
!! wikitext
hi <ref><div id="x">ho</div></ref>

<references />
!! wikitext/edited
hi <ref></ref>

<references />
!! end

!!test
Testing serialization after deletion of table cells
!!options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["#x", "remove"]
  ]
}
!!wikitext
{|
!h1 !!h2 !!h3
| id="x" |c1 {{!}}{{!}}{{!}}c2 |||c3
|}
!! wikitext/edited
{|
!h1 !!h2 !!h3
|c2 |||c3
|}
!!end

!! test
Testing selser after addition of new row before first row (T125419)
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    [ "tr", "before", "<tr><td>X</td></tr>" ]
  ]
}
!! wikitext
{|
|a
|}
!! wikitext/edited
{|
|X
|-
|a
|}
!! end

!! test
Serialize new table rows in a HTML table using HTML tags
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    [ "tr", "before", "<tr><td>X</td></tr>" ]
  ]
}
!! wikitext
<table><tr><td>a</td></tr></table>
!! wikitext/edited
<table><tr><td>X</td></tr><tr><td>a</td></tr></table>
!! end

!! test
Serialize new table cells in a HTML row using HTML tags
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    [ "td", "before", "<td>X</td>" ]
  ]
}
!! wikitext
<table><tr><td>a</td></tr></table>
!! wikitext/edited
<table><tr><td>X</td><td>a</td></tr></table>
!! end

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

!! test
Serialize wikitext list items as HTML list items when embedded in a HTML list
!! options
parsoid=html2wt
!! html
<ul data-parsoid='{"stx": "html"}'>
<li data-parsoid='{}'>a</li>
<li>b</li>
</ul>
!! wikitext
<ul>
<li>a</li>
<li>b</li>
</ul>
!! end

# SSS FIXME: Is this actually a good thing given the
# odd nested list output that is generated by MW?
# <ul><li>foo<ul>..</ul></li></ul> instead of
# <ul><li>foo</li><ul>..</ul></ul>
!! test
Wikitext lists can be nested inside HTML lists
!! options
parsoid=html2wt
!! html
<ul data-parsoid='{"stx": "html"}'>
<li data-parsoid='{"stx": "html"}'>a
<ul><li>b</li></ul>
</li>
</ul>

<ul data-parsoid='{"stx": "html"}'>
<li>x
<ul><li>y</li></ul>
</li>
</ul>
!! wikitext
<ul>
<li>a
* b
</li>
</ul>

<ul>
<li>x
* y
</li>
</ul>
!! end

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

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

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

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

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

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

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

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

!! 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
T45661: Piped links with identical prefixes
!! wikitext
[[prefixed article|prefixed articles with spaces]]

[[prefixed article|prefixed articlesaoeu]]

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


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

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

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

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

!! test
Piped link with extlink-like text
!! wikitext
[[Main Page|[bar]]]
[[Main Page|This is a [bar]]]
!! 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

!! test
Anchor containing a #. (T65430)
!! 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" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#And.23Link"},"sa":{"href":"Main Page#And#Link"}}'>Main Page#And#Link</a></p>
!! end

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

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

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

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

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

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

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

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

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

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

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

## Example for such a section: == < ==
!! test
Link containing "#<" and "#>" % as a hex sequences- these are valid section anchors
!! 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_Page#.3C" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#.3C"},"sa":{"href":"%23%3c"}}'>#&lt;</a><a rel="mw:WikiLink" href="./Main_Page#.3E" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#.3E"},"sa":{"href":"%23%3e"}}'>#></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 '' (T6598)
!! wikitext
[[Lista d''e paise d''o munno]]
!! html/php
<p><a href="/index.php?title=Lista_d%27%27e_paise_d%27%27o_munno&amp;action=edit&amp;redlink=1" class="new" title="Lista d''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 quotes and spaces
!! wikitext
[[Cool "Gator"]]
!! html/php
<p><a href="/index.php?title=Cool_%22Gator%22&amp;action=edit&amp;redlink=1" class="new" title="Cool &quot;Gator&quot; (page does not exist)">Cool "Gator"</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Cool_%22Gator%22" title='Cool "Gator"'>Cool "Gator"</a></p>
!! end

!! test
File containing double quotes and spaces
!! wikitext
[[File:Cool "Gator".png]]
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-parsoid='{"optList":[]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}]}'><a href="./File:Cool_%22Gator%22.png" data-parsoid='{"a":{"href":"./File:Cool_%22Gator%22.png"},"sa":{"href":"File:Cool \"Gator\".png"}}'><img resource='./File:Cool_"Gator".png' src="./Special:FilePath/Cool_%22Gator%22.png" height="220" width="220" data-parsoid='{"a":{"resource":"./File:Cool_\"Gator\".png","height":"220","width":"220","src":"./Special:FilePath/Cool_%22Gator%22.png"},"sa":{"resource":"File:Cool \"Gator\".png","src":"./Special:FilePath/Cool_\"Gator\".png"}}'/></a></span></p>
!! end

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

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

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

!! 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 (T41700)
!! 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-parsoid='{"optList":[{"ck":"caption","ak":"&lt;script>&lt;/script>"}]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&amp;lt;script>&amp;lt;/script>"}'><a href="./File:Nonexistent" data-parsoid='{"a":{"href":"./File:Nonexistent"},"sa":{}}'><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220" data-parsoid='{"a":{"resource":"./File:Nonexistent","height":"220","width":"220"},"sa":{"resource":"File:Nonexistent"}}'/></a></span>
<span typeof="mw:Error mw:Image" data-parsoid='{"optList":[{"ck":"width","ak":"100x100px"},{"ck":"caption","ak":"&lt;script>&lt;/script>"}]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&amp;lt;script>&amp;lt;/script>"}'><a href="./File:Nonexistent" data-parsoid='{"a":{"href":"./File:Nonexistent"},"sa":{}}'><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="100" width="100" data-parsoid='{"a":{"resource":"./File:Nonexistent","height":"100","width":"100"},"sa":{"resource":"File:Nonexistent"}}'/></a></span>
<span class="mw-default-size" typeof="mw:Error mw:Image" data-parsoid='{"optList":[{"ck":"caption","ak":"&amp;lt;"}]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&lt;span typeof=\"mw:Entity\" data-parsoid=&#39;{\"src\":\"&amp;amp;lt;\",\"srcContent\":\"&amp;lt;\",\"dsr\":[107,111,null,null]}&#39;>&amp;lt;&lt;/span>"}'><a href="./File:Nonexistent" data-parsoid='{"a":{"href":"./File:Nonexistent"},"sa":{}}'><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220" data-parsoid='{"a":{"resource":"./File:Nonexistent","height":"220","width":"220"},"sa":{"resource":"File:Nonexistent"}}'/></a></span>
<span class="mw-default-size" typeof="mw:Error mw:Image" data-parsoid='{"optList":[{"ck":"caption","ak":"a&lt;i>b&lt;/i>c"}]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"a&lt;i data-parsoid=&#39;{\"stx\":\"html\",\"dsr\":[134,142,3,4]}&#39;>b&lt;/i>c"}'><a href="./File:Nonexistent" data-parsoid='{"a":{"href":"./File:Nonexistent"},"sa":{}}'><img resource="./File:Nonexistent" src="./Special:FilePath/Nonexistent" height="220" width="220" data-parsoid='{"a":{"resource":"./File:Nonexistent","height":"220","width":"220"},"sa":{"resource":"File:Nonexistent"}}'/></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%7Can" data-parsoid='{"a":{"href":"http://www.example.com%7Can"},"sa":{"href":"http://www.example.com|an"}}'>example URL</a>]</p>
!! end

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

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

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

!! test
<nowiki> inside a link
!! wikitext
[[Main<nowiki> Page</nowiki>]] [[Main Page|the main page <nowiki>[it's not very good]</nowiki>]]
!! html
<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 (T29473 primary issue)
!! options
language=ca
!! wikitext
'''[[Main Page]]'''
!! html
<p><b><a href="/wiki/Main_Page" title="Main Page">Main Page</a></b>
</p>
!! end

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

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

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

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

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

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

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

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

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

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

!! test
1. Interaction of linktrail and template encapsulation
!! wikitext
{{echo|[[Foo]]}}l
!! html/parsoid
<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"}]]}'>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"}]]}'>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
!! wikitext
[[Foo|{{echo|a}} b {{echo|c}}]]
!! html/parsoid
<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 (T4372)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[MeatBall:]]
!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl" class="extiw" title="meatball:">MeatBall:</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.usemod.com/cgi-bin/mb.pl?" title="meatball:">MeatBall:</a></p>
!! end

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

!! test
Link scenarios with escaped fragments
!! wikitext
[[#Is this great?]]
[[Foo#Is this great?]]
[[meatball:Foo#Is this great?]]
!! html/php
<p><a href="#Is_this_great.3F">#Is this great?</a>
<a href="/wiki/Foo#Is_this_great.3F" title="Foo">Foo#Is this great?</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F" class="extiw" title="meatball:Foo">meatball:Foo#Is this great?</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page#Is_this_great.3F" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#Is_this_great.3F"},"sa":{"href":"#Is this great?"}}'>#Is this great?</a>
<a rel="mw:WikiLink" href="./Foo#Is_this_great.3F" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo#Is_this_great.3F"},"sa":{"href":"Foo#Is this great?"}}'>Foo#Is this great?</a>
<a rel="mw:ExtLink" href="http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F" title="meatball:Foo" data-parsoid='{"stx":"simple","a":{"href":"http://www.usemod.com/cgi-bin/mb.pl?Foo#Is_this_great.3F"},"sa":{"href":"meatball:Foo#Is this great?"},"isIW":true}'>meatball:Foo#Is this great?</a></p>
!! end

# 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><a class="mw-selflink selflink">local:Main Page</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">local:Main Page</a></p>
!! end

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

!! test
Local interwiki link: with additional interwiki prefix (T63357)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
[[local:meatball:Hello]]
!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?Hello" class="extiw" title="meatball:Hello">local:meatball:Hello</a>
</p>
!! html/parsoid
<p><a rel="mw: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
!! wikitext
Blah blah blah
[[zh:Chinese]]
!! html/php
<p>Blah blah blah
</p>
!! html/parsoid
<p>Blah blah blah</p>
<link rel="mw:PageProp/Language" href="http://zh.wikipedia.org/wiki/Chinese"/>
!! end

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

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

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

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

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

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

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

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

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

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

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

!! test
Parsoid T55221: Wikilinks should be properly entity-escaped
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<p>He&amp;nbsp;llo <a href="./Foo" rel="mw:WikiLink">He&amp;nbsp;llo</a></p>
<p>He&amp;nbsp;llo <a href="./He&amp;nbsp;llo" rel="mw:WikiLink">He&amp;nbsp;llo</a></p>
!! wikitext
He&amp;nbsp;llo [[Foo|He&amp;nbsp;llo]]

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

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

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

<p><a rel="mw:WikiLink" href="./Constructor:foo" title="Constructor:foo" data-parsoid='{"stx":"simple","a":{"href":"./Constructor:foo"},"sa":{"href":"constructor:foo"}}'>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 (T47209)
!! wikitext
[[mi:Foo]]
!! html/php
<p><a href="/wiki/Foo" title="Foo">mi:Foo</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"mi:Foo"}}'>mi:Foo</a></p>
!! end

!! test
Interlanguage link with preceding local interwiki link (T70085)
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
Blah blah blah
[[local:es:Spanish]]
!! html/php
<p>Blah blah blah
<a href="http://es.wikipedia.org/wiki/Spanish" class="extiw" title="es:Spanish">local:es:Spanish</a>
</p>
!! html/parsoid
<p>Blah blah blah
<a rel="mw: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 about="#mwt2" typeof="mw:ExpandedAttrs" rel="mw:PageProp/redirect" href="./Foobar" data-parsoid='{"a":{"href":"./Foobar"},"sa":{"href":"{{echo|Foo}}bar"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[12,24,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"Foo\"}},\"i\":0}}]}&#39;>Foo&lt;/span>bar"}]]}'/>
!! end

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

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

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

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

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

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

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

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

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

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

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

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

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

!! test
Redirect syntax under text isn't considered a redirect
!! wikitext
some text
#redirect [[Main Page]]
!! html/parsoid
<p>some text</p>
<ol data-parsoid='{}'><li data-parsoid='{}'>redirect <a rel="mw:WikiLink" href="./Main_Page" title="Main Page" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page"},"sa":{"href":"Main Page"}}'>Main Page</a></li></ol>
!! end

# 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 (T53055)!
!! test
Parsoid: Broken br tag recognition
!! options
parsoid=wt2html
!! wikitext
</br>

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

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

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

## 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
1. Nested mixed wikitext and html list
!! wikitext
* hi
* <ul><li>ho</li></ul>
* hi
** ho
!! html/php
<ul><li> hi</li>
<li> <ul><li>ho</li></ul></li>
<li> hi
<ul><li> ho</li></ul></li></ul>

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

!! test
2. Nested mixed wikitext and html list (incompatible)
!! wikitext
; hi
: {{echo|<li>ho</li>}}
!! html/php
<dl><dt> hi</dt>
<dd> <li>ho</li></dd></dl>

!! html/parsoid
<dl><dt> hi</dt>
<dd> <li about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;li>ho&lt;/li>"}},"i":0}}]}'>ho</li></dd></dl>
!! end

!! test
Nested lists 1
!! wikitext
*foo
**bar
!! html
<ul><li>foo
<ul><li>bar</li></ul></li></ul>

!! end

!! test
Nested lists 2
!! wikitext
**foo
*bar
!! html
<ul><li><ul><li>foo</li></ul></li>
<li>bar</li></ul>

!! end

!! test
Nested lists 3 (first element empty)
!! wikitext
*
**bar
!! html
<ul><li>
<ul><li>bar</li></ul></li></ul>

!! end

!! test
Nested lists 4 (first element empty)
!! wikitext
**
*bar
!! html
<ul><li><ul><li></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 (T2785)
!! wikitext
* <pre>foo</pre>
* <pre>bar</pre>
* zar
!! html/php
<ul><li> <pre>foo</pre></li>
<li> <pre>bar</pre></li>
<li> zar</li></ul>

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

!! 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 T70395.
!! 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 T70395.
!!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}} (T6594)
!! wikitext
{{CURRENTWEEK}}
!! html
<p>1
</p>
!! end

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

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

!! test
Magic Words LOCAL (UTC)
!! wikitext
* {{LOCALMONTH}}
* {{LOCALMONTH1}}
* {{LOCALMONTHNAME}}
* {{LOCALMONTHNAMEGEN}}
* {{LOCALMONTHABBREV}}
* {{LOCALDAY}}
* {{LOCALDAY2}}
* {{LOCALDAYNAME}}
* {{LOCALYEAR}}
* {{LOCALTIME}}
* {{LOCALHOUR}}
* {{LOCALWEEK}}
* {{LOCALDOW}}
* {{LOCALTIMESTAMP}}
!! html
<ul><li> 01</li>
<li> 1</li>
<li> January</li>
<li> January</li>
<li> Jan</li>
<li> 1</li>
<li> 01</li>
<li> Thursday</li>
<li> 1970</li>
<li> 00:02</li>
<li> 00</li>
<li> 1</li>
<li> 4</li>
<li> 19700101000203</li></ul>

!! end

!! test
Magic Word: {{FULLPAGENAME}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{FULLPAGENAME}}
!! html/*
<p>User:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{FULLPAGENAMEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{FULLPAGENAMEE}}
!! html/*
<p>User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{TALKSPACE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKSPACE}}
!! html/*
<p>User talk
</p>
!! end

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

!! test
Magic Word: {{TALKSPACE}}, main namespace
!! options
title=[[Parser Test]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKSPACE}}
!! html/*
<p>Talk
</p>
!! end

!! test
Magic Word: {{TALKSPACEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKSPACEE}}
!! html/*
<p>User_talk
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTSPACE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}, same namespace
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTSPACE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{SUBJECTSPACE}}, main namespace
!! options
title=[[Parser Test]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTSPACE}}
!! html/*

!! end

!! test
Magic Word: {{SUBJECTSPACEE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTSPACEE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{NAMESPACE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{NAMESPACEE}}
!! html/*
<p>User
</p>
!! end

!! test
Magic Word: {{NAMESPACENUMBER}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{NAMESPACENUMBER}}
!! html/*
<p>2
</p>
!! end

!! test
Magic Word: {{SUBPAGENAME}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub ö]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBPAGENAME}}
!! html/*
<p>sub ö
</p>
!! end

!! test
Magic Word: {{SUBPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub ö]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBPAGENAMEE}}
!! html/*
<p>sub_%C3%B6
</p>
!! end

!! test
Magic Word: {{ROOTPAGENAME}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub/sub2]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{ROOTPAGENAME}}
!! html/*
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{ROOTPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub/sub2]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{ROOTPAGENAMEE}}
!! html/*
<p>%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{BASEPAGENAME}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{BASEPAGENAME}}
!! html/*
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{BASEPAGENAMEE}}
!! options
title=[[Ævar Arnfjörð Bjarmason/sub]] subpage
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{BASEPAGENAMEE}}
!! html/*
<p>%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{TALKPAGENAME}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKPAGENAME}}
!! html/*
<p>User talk:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{TALKPAGENAMEE}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{TALKPAGENAMEE}}
!! html/*
<p>User_talk:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{SUBJECTPAGENAME}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTPAGENAME}}
!! html/*
<p>User:Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{SUBJECTPAGENAMEE}}
!! options
title=[[User talk:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SUBJECTPAGENAMEE}}
!! html/*
<p>User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{NUMBEROFFILES}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{NUMBEROFFILES}}
!! html/*
<p>7
</p>
!! end

!! test
Magic Word: {{PAGENAME}}
!! options
title=[[User:Ævar Arnfjörð Bjarmason]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGENAME}}
!! html/*
<p>Ævar Arnfjörð Bjarmason
</p>
!! end

!! test
Magic Word: {{PAGENAME}} with metacharacters
!! options
title=[['foo & bar = baz']]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
''{{PAGENAME}}''
!! html/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 (T28781)
!! options
title=[[*RFC 1234 http://example.com/]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! 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]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGENAMEE}}
!! html/*
<p>%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
</p>
!! end

!! test
Magic Word: {{PAGENAMEE}} with metacharacters (T28781)
!! options
title=[[*RFC 1234 http://example.com/]]
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGENAMEE}}
!! html/php
<p>&#42;RFC_1234_http&#58;//example.com/
</p>
!! html+tidy
<p>*RFC_1234_http://example.com/</p>
!! end

!! test
Magic Word: {{REVISIONID}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{REVISIONID}}
!! html/*
<p>1337
</p>
!! end

!! test
Magic Word: {{SCRIPTPATH}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SCRIPTPATH}}
!! html/*

!! end

!! test
Magic Word: {{STYLEPATH}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{STYLEPATH}}
!! html/*
<p>/skins
</p>
!! end

!! test
Magic Word: {{SERVER}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SERVER}}
!! html/*
<p><a rel="nofollow" class="external free" href="http://example.org">http://example.org</a>
</p>
!! end

!! test
Magic Word: {{SERVERNAME}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SERVERNAME}}
!! html/*
<p>example.org
</p>
!! end

!! test
Magic Word: {{SITENAME}}
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{SITENAME}}
!! html/*
<p>MediaWiki
</p>
!! end

!! test
Magic Word: {{PAGELANGUAGE}}
!! options
language=fr
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGELANGUAGE}}
!! html/*
<p>fr
</p>
!! end

!! test
Magic Word: {{PAGELANGUAGE}} on a page with no explicitly set language
!! options
parsoid={ "modes": ["wt2html","wt2wt"], "normalizePhp": true }
!! wikitext
{{PAGELANGUAGE}}
!! html/*
<p>en
</p>
!! end

!! test
Case-sensitive magic words, when cased differently, should just be template transclusions
!! wikitext
{{CurrentMonth}}
{{currentday}}
{{cURreNTweEK}}
{{currentHour}}
!! html
<p><a href="/index.php?title=Template:CurrentMonth&amp;action=edit&amp;redlink=1" class="new" title="Template:CurrentMonth (page does not exist)">Template:CurrentMonth</a>
<a href="/index.php?title=Template:Currentday&amp;action=edit&amp;redlink=1" class="new" title="Template:Currentday (page does not exist)">Template:Currentday</a>
<a href="/index.php?title=Template:CURreNTweEK&amp;action=edit&amp;redlink=1" class="new" title="Template:CURreNTweEK (page does not exist)">Template:CURreNTweEK</a>
<a href="/index.php?title=Template:CurrentHour&amp;action=edit&amp;redlink=1" class="new" title="Template:CurrentHour (page does not exist)">Template:CurrentHour</a>
</p>
!! end

!! test
Case-insensitive magic words should still work with weird casing.
!! wikitext
{{sErVeRNaMe}}
{{LCFirst:AOEU}}
{{ucFIRST:aoeu}}
{{SERver}}
!! html
<p>example.org
aOEU
Aoeu
<a rel="nofollow" class="external free" href="http://example.org">http://example.org</a>
</p>
!! end

# From plwiki:PLOS_ONE
!! test
Parsoid: Page property magic word with magic word contents
!! wikitext
{{DISPLAYTITLE:''{{PAGENAME}}''}}
!! html/parsoid
<meta property="mw:PageProp/displaytitle" content="Main Page" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"src":"{{DISPLAYTITLE:&#39;&#39;{{PAGENAME}}&#39;&#39;}}"}' data-mw='{"attribs":[[{"txt":"content"},{"html":"&lt;i data-parsoid=&#39;{\"dsr\":[15,31,2,2]}&#39;>&lt;span about=\"#mwt2\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[17,29,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"PAGENAME\",\"function\":\"pagename\"},\"params\":{},\"i\":0}}]}&#39;>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='{"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}} (T6783)
!! wikitext
{{ns:0}}
!! html

!! end

!! test
Namespace 0 {{ns:00}} (T6783)
!! wikitext
{{ns:00}}
!! html

!! end

!! test
Namespace -1 {{ns:-1}}
!! wikitext
{{ns:-1}}
!! html
<p>Special
</p>
!! end

!! test
Namespace User {{ns:User}}
!! wikitext
{{ns:User}}
!! html
<p>User
</p>
!! end

!! test
Namespace User talk {{ns:User_talk}}
!! wikitext
{{ns:User_talk}}
!! html
<p>User talk
</p>
!! end

!! test
Namespace User talk {{ns:uSeR tAlK}}
!! wikitext
{{ns:uSeR tAlK}}
!! html
<p>User talk
</p>
!! end

!! test
Namespace File {{ns:File}}
!! wikitext
{{ns:File}}
!! html
<p>File
</p>
!! end

!! test
Namespace File {{ns:Image}}
!! wikitext
{{ns:Image}}
!! html
<p>File
</p>
!! end

!! test
Namespace (lang=de) Benutzer {{ns:User}}
!! options
language=de
!! wikitext
{{ns:User}}
!! html
<p>Benutzer
</p>
!! end

!! test
Namespace (lang=de) Benutzer Diskussion {{ns:3}}
!! options
language=de
!! wikitext
{{ns:3}}
!! html
<p>Benutzer Diskussion
</p>
!! end

!! test
Urlencode
!! wikitext
{{urlencode:hi world?!}}
{{urlencode:hi world?!|WIKI}}
{{urlencode:hi world?!|PATH}}
{{urlencode:hi world?!|QUERY}}
!! html/php
<p>hi+world%3F%21
hi_world%3F!
hi%20world%3F%21
hi+world%3F%21
</p>
!! end

!! test
Magic Word: prioritize type info over data-parsoid
!! options
parsoid=html2wt
!! html/parsoid
<meta property="mw:PageProp/forcetoc" data-parsoid='{"magicSrc":"__NOTOC__"}'/>
!! wikitext
__FORCETOC__
!! end

!! test
Magic Word: serialize on separate line (parsoid)
!! options
parsoid=wt2wt,html2wt
!! wikitext
foo
__NOTOC__
bar
!! html/parsoid
foo<meta property="mw:PageProp/notoc"/>bar
!! end

!! test
Magic Word: rt non-english wikis
!! options
parsoid=wt2wt
language=de
!! wikitext
__NOEDITSECTION__
!! html/parsoid
<meta property="mw:PageProp/noeditsection" data-parsoid='{"magicSrc":"__NOEDITSECTION__"}'/>
!! end

!!test
__proto__ is treated as normal wikitext (T105997)
!!wikitext
__proto__
!!html
<p>__proto__
</p>
!!end

###
### Magic links
###
!! test
Magic links: internal link to RFC (T2479)
!! wikitext
[[RFC 123]]
!! html/php
<p><a href="/index.php?title=RFC_123&amp;action=edit&amp;redlink=1" class="new" title="RFC 123 (page does not exist)">RFC 123</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./RFC_123" title="RFC 123">RFC 123</a></p>
!! end

!! test
Magic links: RFC (T2479)
!! wikitext
RFC 822
!! html/php
<p><a class="external mw-magiclink-rfc" rel="nofollow" href="//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 (T67278)
!! wikitext
This is RFC 822 but thisRFC 822 is not RFC 822linked.
!! html/php
<p>This is <a class="external mw-magiclink-rfc" rel="nofollow" href="//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, T30950/T31025)
!! 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 (T3937)
!! wikitext
ISBN 0-306-40615-2
!! html/php
<p><a href="/wiki/Special:BookSources/0306406152" class="internal mw-magiclink-isbn">ISBN 0-306-40615-2</a>
</p>
!! html/parsoid
<p><a href="./Special:BookSources/0306406152" rel="mw:WikiLink">ISBN 0-306-40615-2</a></p>
!! end

!! test
Magic links: ISBN (T67278)
!! wikitext
This is ISBN 978-0-316-09811-3 but thisISBN 978-0-316-09811-3 is not ISBN 978-0-316-09811-3linked.
!! html/php
<p>This is <a href="/wiki/Special:BookSources/9780316098113" class="internal mw-magiclink-isbn">ISBN 978-0-316-09811-3</a> but thisISBN 978-0-316-09811-3 is not ISBN 978-0-316-09811-3linked.
</p>
!! html/parsoid
<p>This is <a href="./Special:BookSources/9780316098113" rel="mw:WikiLink">ISBN 978-0-316-09811-3</a> but thisISBN 978-0-316-09811-3 is not ISBN 978-0-316-09811-3linked.</p>
!! end

!! test
Magic links: ISBN (w/ non-newline whitespace, T30950/T31025)
!! wikitext
ISBN &nbsp;&#160;&#0160;&#xA0;&#Xa0; 978&nbsp;0&#160;316&#0160;09811&#xA0;3
ISBN
9780316098113
ISBN 978
0316098113
!! html/php
<p><a href="/wiki/Special:BookSources/9780316098113" class="internal mw-magiclink-isbn">ISBN 978 0 316 09811 3</a>
ISBN
9780316098113
ISBN 978
0316098113
</p>
!! html/parsoid
<p><a href="./Special:BookSources/9780316098113" rel="mw:WikiLink">ISBN <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 978<span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>0<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span>316<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span>09811<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span>3</a>
ISBN
9780316098113
ISBN 978
0316098113</p>
!! end

!! test
Magic links: PMID incorrectly converts space to underscore
!! wikitext
PMID 1234
!! html/php
<p><a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a>
</p>
!! html/parsoid
<p><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink">PMID 1234</a></p>
!! end

!! test
Magic links: PMID (T67278)
!! wikitext
This is PMID 1234 but thisPMID 1234 is not PMID 1234linked.
!! html/php
<p>This is <a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a> but thisPMID 1234 is not PMID 1234linked.
</p>
!! html/parsoid
<p>This is <a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink">PMID 1234</a> but thisPMID 1234 is not PMID 1234linked.</p>
!! end

!! test
Magic links: PMID (w/ non-newline whitespace, T30950/T31025)
!! wikitext
PMID &nbsp;&#160;&#0160;&#xA0;&#Xa0; 1234
PMID
1234
!! html/php
<p><a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract">PMID 1234</a>
PMID
1234
</p>
!! html/parsoid
<p><a href="//www.ncbi.nlm.nih.gov/pubmed/1234?dopt=Abstract" rel="mw:ExtLink">PMID <span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#0160;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#xA0;","srcContent":" "}'> </span><span typeof="mw:Entity" data-parsoid='{"src":"&amp;#Xa0;","srcContent":" "}'> </span> 1234</a>
PMID
1234</p>
!! end

# <nowiki> nodes shouldn't be inserted during html2wt by Parsoid,
# since these are ExtLinkText, not MagicLinkText
!! test
Magic links: use appropriate serialization for "almost" magic links.
!! wikitext
X[[Special:BookSources/0978739256|foo]]

X[//tools.ietf.org/html/rfc1234 foo]
!! html/php
<p>X<a href="/wiki/Special:BookSources/0978739256" title="Special:BookSources/0978739256">foo</a>
</p><p>X<a rel="nofollow" class="external text" href="//tools.ietf.org/html/rfc1234">foo</a>
</p>
!! html/parsoid
<p>X<a rel="mw:WikiLink" href="./Special:BookSources/0978739256" title="Special:BookSources/0978739256">foo</a></p>
<p>X<a rel="mw:ExtLink" href="//tools.ietf.org/html/rfc1234">foo</a></p>
!! end

!! test
Magic links: All disabled (T47942)
!! options
wgEnableMagicLinks={"ISBN":false, "PMID":false, "RFC":false}
!! wikitext
ISBN 0-306-40615-2
PMID 1234
RFC 4321
!! html/php
<p>ISBN 0-306-40615-2
PMID 1234
RFC 4321
</p>
!! end

###
### Templates
####

!! test
Nonexistent template
!! wikitext
{{thistemplatedoesnotexist}}
!! html
<p><a href="/index.php?title=Template:Thistemplatedoesnotexist&amp;action=edit&amp;redlink=1" class="new" title="Template:Thistemplatedoesnotexist (page does not exist)">Template:Thistemplatedoesnotexist</a>
</p>
!! end

!! test
Template with invalid target containing tags
!! wikitext
{{a<b>b</b>|{{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, T70421
!! wikitext
{{echo|{{ }}}}
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{ }}"}},"i":0}}]}'>{{ }}</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
T2553: link with two variables in a piped link
!! wikitext
{|
|[[{{{1}}}|{{{2}}}]]
|}
!! html/php
<table>
<tr>
<td>[[{{{1}}}|{{{2}}}]]
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr><td>[[<span about="#mwt5" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"1"},"params":{},"i":0}}]}'>{{{1}}}</span>|<span about="#mwt2" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"2"},"params":{},"i":0}}]}'>{{{2}}}</span>]]</td></tr>
</tbody></table>
!! end

# See: T2553
!! test
Abort table cell attribute parsing on wikilink
!! wikitext
{|
| testing [[one|two]] | three || four
| testing one two | three || four
| testing="[[one|two]]" | three || four
|}
!! html/php
<table>
<tr>
<td> testing <a href="/index.php?title=One&amp;action=edit&amp;redlink=1" class="new" title="One (page does not exist)">two</a> | three </td>
<td> four
</td>
<td> three </td>
<td> four
</td>
<td> testing="<a href="/index.php?title=One&amp;action=edit&amp;redlink=1" class="new" title="One (page does not exist)">two</a>" | three </td>
<td> four
</td></tr></table>

!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"autoInsertedEnd":true}'> testing <a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"piped","a":{"href":"./One"},"sa":{"href":"one"}}'>two</a> | three </td><td data-parsoid='{"stx_v":"row","autoInsertedEnd":true}'> four</td>
<td data-parsoid='{"a":{"testing":null,"one":null,"two":null},"sa":{"testing":"","one":"","two":""},"autoInsertedEnd":true}'> three </td><td data-parsoid='{"stx_v":"row","autoInsertedEnd":true}'> four</td>
<td> testing="<a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"piped","a":{"href":"./One"},"sa":{"href":"one"}}'>two</a>" | three </td><td data-parsoid='{"stx_v":"row","autoInsertedEnd":true}'> four</td></tr>
</tbody></table>
!! end

!! test
Don't abort table cell attribute parsing if wikilink is found in template arg
!! wikitext
{|
| Test {{#tag:ref|One two "[[three]]" four}}
|}
!! html/parsoid
<table>
<tbody><tr><td> Test <ref about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#tag:ref","function":"#tag"},"params":{"1":{"wt":"One two \"[[three]]\" four"}},"i":0}}]}'>One two "<a rel="mw:WikiLink" href="./Three" title="Three">three</a>" four</ref></td></tr>
</tbody></table>
!! end

!! test
Magic variable as template parameter
!! wikitext
{{paramtest|param={{SITENAME}}}}
!! html
<p>This is a test template with parameter MediaWiki
</p>
!! end

!! article
Template:linktest
!! text
[[{{{param}}}|link]]
!! endarticle

!! test
Template parameter as link source
!! wikitext
{{linktest|param=Main Page}}
!! html
<p><a href="/wiki/Main_Page" title="Main Page">link</a>
</p>
!! end

!!article
Template:paramtest2
!! text
including another template, {{paramtest|param={{{arg}}}}}
!! endarticle

!! test
Template passing argument to another template
!! wikitext
{{paramtest2|arg='hmm'}}
!! html
<p>including another template, This is a test template with parameter 'hmm'
</p>
!! end

!! article
Template:Linktest2
!! text
Main Page
!! endarticle

!! test
Template as link source
!! wikitext
[[{{linktest2}}]]

[[{{linktest2}}|Main Page]]

[[{{linktest2}}]]Page
!! html
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p><p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>
</p><p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>Page
</p>
!! end


!! article
Template:loop1
!! text
{{loop2}}
!! endarticle

!! article
Template:loop2
!! text
{{loop1}}
!! endarticle

!! test
Template infinite loop
!! wikitext
{{loop1}}
!! html
<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
T2529: 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
T2523: 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
T2041: 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;","href":"./Template:&#39;&#39;"},"params":{},"i":0}}]}'>bar</span> baz
</p>
!! end

## This test is about making sure Parsoid's data-mw is well formed in the
## face of multiple templates with intersecting and overlapping ranges.  The
## wikitext itself is wretched.
!! test
Templates with intersecting and overlapping ranges
!! wikitext
{|{{echo|
<p>ha</p>}}
{|{{echo|
<p>ho</p>}}
{{echo|{{!}}hi}}
|}
!! html/php+tidy
<p>ha</p>
<p>ho</p>
<table>
<tr>
<td></td>
</tr>
<tr>
<td>hi</td>
</tr>
</table>
<table>
<tr>
<td></td>
</tr>
</table>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]],"firstWikitextNode":"table"}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n&lt;p>ha&lt;/p>"}},"i":0}},"\n","{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"\n&lt;p>ho&lt;/p>"}},"i":1}},"\n",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"{{!}}hi"}},"i":2}},"\n|}"]}'>ha</p><table about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"","html":""},{"html":""}]]}'>

</table><p about="#mwt1">ho</p><table about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"","html":""},{"html":""}]]}'>

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

!! article
Template:MSGNW test
!! text
''None'' of '''this''' should be 
* interpreted
 but rather passed unmodified
{{test}}
<gallery>
File:Foobar.jpg
</gallery>
<!-- comment -->
!! endarticle

# hmm, fix this or just deprecate msgnw and document its behavior?
!! test
msgnw keyword
!! wikitext
{{msgnw:MSGNW test}}
!! html/php
<p>&#39;&#39;None&#39;&#39; of &#39;&#39;&#39;this&#39;&#39;&#39; should be 
&#42; interpreted
&#32;but rather passed unmodified
&#123;&#123;test&#125;&#125;
&#60;gallery&#62;
File:Foobar.jpg
&#60;/gallery&#62;
&#60;!-- comment --&#62;
</p>
!! end

!! test
int keyword
!! wikitext
{{int:youhavenewmessages|lots of money|not!}}
!! html
<p>You have lots of money (not!).
</p>
!! end

!! test
int keyword - non-existing message
!! wikitext
{{int:var}}
!! html
<p>⧼var⧽
</p>
!! end

!! article
Template:Includes
!! text
Foo<noinclude>zar</noinclude><includeonly>bar</includeonly>
!! endarticle

!! test
<includeonly> and <noinclude> being included
!! wikitext
{{Includes}}
!! html
<p>Foobar
</p>
!! end

!! article
Template:Includes2
!! text
<onlyinclude>Foo</onlyinclude>bar
!! endarticle

!! test
<onlyinclude> being included
!! wikitext
{{Includes2}}
!! html
<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
T8563: 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
T8563: Section extraction for section shown by <includeonly>
!! options
section=T-2
!! wikitext
<includeonly>
==Includeonly section==
</includeonly>
==Section T-2==
!! html
==Section T-2==
!! end

!! test
T8563: Edit link generation for section suppressed by <includeonly>
!! wikitext
<includeonly>
==Includeonly section==
</includeonly>
==Section 1==
!! html
<h2><span class="mw-headline" id="Section_1">Section 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>

!! end

!! test
T8563: Section extraction for section suppressed by <includeonly>
!! options
section=1
!! wikitext
<includeonly>
==Includeonly section==
</includeonly>
==Section 1==
!! html
==Section 1==
!! end

!! test
Un-closed <includeonly>
!! wikitext
<includeonly>
!! html/php
!! html/parsoid
<meta typeof="mw:Includes/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>"}'/>
!! end

## We used to, but no longer wt2wt this test since the default serializer
## will normalize the include directives to serialize on their own line.
## Selser will take care of preserving formatting in scenarios where they
## intermingled with other wikitext.
!! test
Includes and comments at SOL
!! options
parsoid=wt2html,html2html
!! 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"}]]}'>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"}]]}'>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"}]]}'>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

## We used to, but no longer wt2wt this test since the default serializer
## will normalize the include directives to serialize on their own line.
## Selser will take care of preserving formatting in scenarios where they
## intermingled with other wikitext.
!!test
2. Table tag in SOL posn. should get reparsed correctly with valid TSR
!!options
parsoid=wt2html
!!wikitext
<includeonly>a</includeonly>{| {{{b}}}
|c
|}
!!html/parsoid
<meta typeof="mw:Includes/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>a&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><table about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"a":{"{{{b}}}":null},"sa":{"{{{b}}}":""}}' data-mw='{"attribs":[[{"txt":"{{{b}}}","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Param\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[31,38,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"templatearg\":{\"target\":{\"wt\":\"b\"},\"params\":{},\"i\":0}}]}&#39;>{{{b}}}&lt;/span>"},{"html":""}]]}'>
<tbody><tr><td>c</td></tr>
</tbody></table>
!!end

!! test
Table wikitext syntax outside wiki-tables
!! wikitext
a
|+ not a caption
! not a table heading
|- not a table row
| not a table cell
| class="foo bar" | baz
b
|}
|-
c
!! html
<p>a
|+ not a caption
! not a table heading
|- not a table row
| not a table cell
| class="foo bar" | baz
b
|}
|-
c
</p>
!! end

###
### Testing parsing of templates where a template arg
### has the same name as the template itself.
###

!! article
Template:quote
!! text
{{{quote|{{{1}}}}}}
!! endarticle

!!test
Templates: Template Name/Arg clash: 1. Use of positional param
!! wikitext
{{quote|foo}}
!! html
<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=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[5,49,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"style{{=}}\\\"background:&amp;amp;#35;f9f9f9;\\\"\"}},\"i\":0}}]}&#39;>style&lt;/span>&lt;span typeof=\"mw:Nowiki\" about=\"#mwt1\" data-parsoid=\"{}\">=&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">\"background:&lt;/span>&lt;span typeof=\"mw:Entity\" about=\"#mwt1\" data-parsoid=&#39;{\"src\":\"&amp;amp;#35;\",\"srcContent\":\"#\"}&#39;>#&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">f9f9f9;\"&lt;/span>"},{"html":""}]]}'>foo</div>
!! end

!! test
2. Entities and nowikis inside templated attributes should be handled correctly
!! wikitext
{|
|{{table_attribs_3}}
|}
!! html/php
<table>
<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 (T52330)-->
<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 (T52330)-->
<link rel="mw:PageProp/Category" href="./Category:Bar1"><link rel="mw:PageProp/Category" href="./Category:Bar2"><table><tbody><tr><td>foo</td></tr></tbody></table>
!!end

!!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="./Main_Page#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="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">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

# T66017 -- ugly wikitext with fostered content generates two template ranges that
# have a true overlap (T1-start - T2-start - T1-end - T2-end).
!! test
Templates: Ugly templates: 5. Template encapsulation test: Non-trivial overlap of template ranges is properly handled
!! wikitext
{{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"}],[{"k":"1"}],[{"k":"1"}]]}'>foo
</div><table about="#mwt1" data-parsoid='{"stx":"html"}'>
</table>
!! end

# T66017 -- ugly wikitext with fostered content generates two template ranges
# that are "identical" and generate nesting cycles in the algorithm
!! test
Templates: Ugly templates: 6. Template encapsulation test: Cyclical nesting of template ranges is properly handled
!! wikitext
{{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"}],[{"k":"1"}],[{"k":"1"}]]}'><tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'><div data-parsoid='{"stx":"html"}'>
</div><table about="#mwt1" data-parsoid='{"stx":"html"}'>
</table></td></tr></tbody></table>
!! end

!! test
Templates: Parameters substituted at the top-level
!! wikitext
{{{foo|''who'' {{echo|me}}? '''never!'''}}}

{{{foo|bar|baz}}}
!! html/php
<p><i>who</i> me? <b>never!</b>
</p><p>bar
</p>
!! html/parsoid
<p about="#mwt2" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"foo"},"params":{"1":{"wt":"&#39;&#39;who&#39;&#39; {{echo|me}}? &#39;&#39;&#39;never!&#39;&#39;&#39;"}},"i":0}}]}'><i>who</i> me? <b>never!</b></p>

<p about="#mwt3" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"foo"},"params":{"1":{"wt":"bar"},"2":{"wt":"baz"}},"i":0}}]}'>bar</p>
!! end

!!test
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 T2089, which I fixed. -- wtm
!! test
pre-save transform: subst: templates with parameters
!! options
pst
!! wikitext
{{subst:paramtest|param="something else"}}
!! html/php
This is a test template with parameter "something else"
!! end

!! article
Template:nowikitest
!! text
<nowiki>'''not wiki'''</nowiki>
!! endarticle

!! test
pre-save transform: nowiki in subst (T3188)
!! options
pst
!! wikitext
{{subst:nowikitest}}
!! html/php
<nowiki>'''not wiki'''</nowiki>
!! end

!! article
Template:commenttest
!! text
This template has <!-- a comment --> in it.
!! endarticle

!! test
pre-save transform: comment in subst (T3936)
!! options
pst
!! wikitext
{{subst:commenttest}}
!! html/php
This template has <!-- a comment --> in it.
!! end

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

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

!! test
pre-save transform: unclosed comment in <nowiki>
!! options
pst
!! wikitext
wiki<nowiki>nowiki<!--nowiki</nowiki>wiki
!! html/php
wiki<nowiki>nowiki<!--nowiki</nowiki>wiki
!!end

# Leading @ in this template definition works around a limitation
# in parsoid's parserTests which otherwise strips the <span> from the
# result (confusing it for a template wrapper)
!! article
Template:dangerous
!!text
@<span onmouseover="alert('crap')">Oh no</span>
!!endarticle

!!test
(confirming safety of fix for subst T3936)
!! wikitext
{{Template:dangerous}}
!! html
<p>@<span>Oh no</span>
</p>
!! end

!! test
pre-save transform: comment containing gallery (T7024)
!! options
pst
!! wikitext
<!-- <gallery>data</gallery> -->
!! html/php
<!-- <gallery>data</gallery> -->
!!end

!! test
pre-save transform: comment containing extension
!! options
pst
!! wikitext
<!-- <tag>data</tag> -->
!! html/php
<!-- <tag>data</tag> -->
!!end

!! test
pre-save transform: comment containing nowiki
!! options
pst
!! wikitext
<!-- <nowiki>data</nowiki> -->
!! html/php
<!-- <nowiki>data</nowiki> -->
!!end

!! test
pre-save transform: <noinclude> in subst (T5298)
!! options
pst
!! wikitext
{{subst:Includes}}
!! html/php
Foobar
!! end

!! test
pre-save transform: <onlyinclude> in subst (T5298)
!! options
pst
!! wikitext
{{subst:Includes2}}
!! html/php
Foo
!! end

!! article
Template:SubstTest
!!text
{{<includeonly>subst:</includeonly>Includes}}
!! endarticle

!! article
Template:SafeSubstTest
!! text
{{<includeonly>safesubst:</includeonly>Includes}}
!! endarticle

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

!! test
T24297: safesubst: works during normal parse
!! wikitext
{{SafeSubstTest}}
!! html
<p>Foobar
</p>
!! end

!! test
subst: does not work during normal parse
!! wikitext
{{SubstTest}}
!! html
<p>{{subst:Includes}}
</p>
!! end

!! test
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, T32149)
!! options
pst
!! wikitext
[[Article（context）|]]
[[Bar:Article（context）|]]
[[:Bar:Article（context）|]]
[[|Article（context）]]
[[Bar:X（Y）Z|]]
[[:Bar:X（Y）Z|]]
!! html/php
[[Article（context）|Article]]
[[Bar:Article（context）|Article]]
[[:Bar:Article（context）|Article]]
[[Article（context）]]
[[Bar:X（Y）Z|X（Y）Z]]
[[:Bar:X（Y）Z|X（Y）Z]]
!! end

!! test
pre-save transform: context links ("pipe trick") with full-width parens and space (Japanese and Chinese style, T32149)
!! options
pst
!! wikitext
[[Article （context）|]]
[[Bar:Article （context）|]]
[[:Bar:Article （context）|]]
[[|Article （context）]]
[[Bar:X （Y） Z|]]
[[:Bar:X （Y） Z|]]
!! html/php
[[Article （context）|Article]]
[[Bar:Article （context）|Article]]
[[:Bar:Article （context）|Article]]
[[Article （context）]]
[[Bar:X （Y） Z|X （Y） Z]]
[[:Bar:X （Y） Z|X （Y） Z]]
!! end

!! test
pre-save transform: context links ("pipe trick") with parens and no space (Korean style, T32149)
!! options
pst
!! wikitext
[[Article(context)|]]
[[Bar:Article(context)|]]
[[:Bar:Article(context)|]]
[[|Article(context)]]
[[Bar:X(Y)Z|]]
[[:Bar:X(Y)Z|]]
!! html/php
[[Article(context)|Article]]
[[Bar:Article(context)|Article]]
[[:Bar:Article(context)|Article]]
[[Article(context)]]
[[Bar:X(Y)Z|X(Y)Z]]
[[:Bar:X(Y)Z|X(Y)Z]]
!! end

!! test
pre-save transform: context links ("pipe trick") with commas (T23660)
!! options
pst
!! wikitext
[[Article (context), context|]]
[[Article (context)，context|]]
[[Bar:Article (context), context|]]
[[Bar:Article (context)，context|]]
[[:Bar:Article (context), context|]]
[[:Bar:Article (context)，context|]]
!! html/php
[[Article (context), context|Article]]
[[Article (context)，context|Article]]
[[Bar:Article (context), context|Article]]
[[Bar:Article (context)，context|Article]]
[[:Bar:Article (context), context|Article]]
[[:Bar:Article (context)，context|Article]]
!! end

!! test
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 (T2093)
!! options
pst disabled
!! wikitext
Shall not expand:

<nowiki>~~~~</nowiki>

<includeonly><nowiki>~~~~</nowiki></includeonly>

<noinclude><nowiki>~~~~</nowiki></noinclude>

<onlyinclude><nowiki>~~~~</nowiki></onlyinclude>

{{subst:Foo}} shall be converted to FOO

As well as inside noinclude/onlyinclude
<noinclude>{{subst:Foo}}</noinclude>
<onlyinclude>{{subst:Foo}}</onlyinclude>

But not inside includeonly
<includeonly>{{subst:Foo}}</includeonly>
!! html/php
Shall not expand:

<nowiki>~~~~</nowiki>

<includeonly><nowiki>~~~~</nowiki></includeonly>

<noinclude><nowiki>~~~~</nowiki></noinclude>

<onlyinclude><nowiki>~~~~</nowiki></onlyinclude>

FOO shall be converted to FOO

As well as inside noinclude/onlyinclude
<noinclude>FOO</noinclude>
<onlyinclude>FOO</onlyinclude>

But not inside includeonly
<includeonly>{{subst:Foo}}</includeonly>
!! end

!! test
Parsoid: Recognize nowiki with trailing space in tags
!! options
parsoid=wt2html
!! wikitext
<nowiki ><div>[[foo]]</nowiki >

a<nowiki / >b

c<nowiki />d

e<nowiki/ >f
!! html
<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 (T6926)
!! options
msg
!! wikitext
{{Includes}}
!! html
Foobar
!! end

!! test
message transform: <onlyinclude> in transcluded template (T6926)
!! options
msg
!! wikitext
{{Includes2}}
!! html
Foo
!! end

!! test
{{#special:}} page name, known
!! options
msg
!! wikitext
{{#special:Recentchanges}}
!! html
Special:RecentChanges
!! end

!! test
{{#special:}} page name with subpage, known
!! options
msg
!! wikitext
{{#special:Recentchanges/param}}
!! html
Special:RecentChanges/param
!! end

!! test
{{#special:}} page name, unknown
!! options
msg
!! wikitext
{{#special:foobar nonexistent}}
!! html
Special:Foobar nonexistent
!! end

!! test
{{#speciale:}} page name, known
!! options
msg
!! wikitext
{{#speciale:Recentchanges}}
!! html
Special:RecentChanges
!! end

!! test
{{#speciale:}} page name with subpage, known
!! options
msg
!! wikitext
{{#speciale:Recentchanges/param}}
!! html
Special:RecentChanges/param
!! end

!! test
{{#speciale:}} page name, unknown
!! options
msg
!! wikitext
{{#speciale:foobar nonexistent}}
!! html
Special:Foobar_nonexistent
!! end

###
### 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, T55312 #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, T55312 #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, T55312 #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 (T62753)
!! 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-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"width","ak":"{{echo|137px}}"},{"ck":"caption","ak":"This is a caption"}]}' data-mw='{"attribs":[["thumbnail",{"html":"thumb"}],["width",{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[24,38,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"137px\"}},\"i\":0}}]}&#39;>137px&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/137px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="16" width="137" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"16","width":"137"},"sa":{"resource":"File:Foobar.jpg"}}'/></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-parsoid='{"optList":[{"ck":"thumbnail","ak":"{{echo|thumb}}"},{"ck":"width","ak":"{{echo|137px}}"},{"ck":"caption","ak":"This is a caption"}]}' data-mw='{"attribs":[["thumbnail",{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[18,32,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"thumb\"}},\"i\":0}}]}&#39;>thumb&lt;/span>"}],["width",{"html":"&lt;span about=\"#mwt2\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[33,47,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"137px\"}},\"i\":0}}]}&#39;>137px&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/137px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="16" width="137" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"16","width":"137"},"sa":{"resource":"File:Foobar.jpg"}}'/></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=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[18,31,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"50px\"}},\"i\":0}}]}&#39;>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" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"6","width":"50"},"sa":{"resource":"File:Foobar.jpg"}}'/></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 (T50664)
!! 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 (T15500, T53628)
!! 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 T51293 (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 T51293 (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

# wgExternalLinkTarget not supported by Parsoid
!! test
Image with link parameter, wgExternalLinkTarget
!! wikitext
[[Image:foobar.jpg|link=http://example.com/]]
!! config
wgExternalLinkTarget='foobar'
!! html/php
<p><a href="http://example.com/" target="foobar" rel="nofollow noreferrer noopener"><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

# wgExternalLinkTarget not supported by Parsoid
!! test
Image with link parameter, wgExternalLinkTarget, unnamed parameter
!! wikitext
[[Image:foobar.jpg|link=http://example.com/|Title]]
!! config
wgExternalLinkTarget='foobar'
!! html/php
<p><a href="http://example.com/" title="Title" target="foobar" rel="nofollow noreferrer noopener"><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|thumbnail=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-parsoid='{"optList":[{"ck":"caption","ak":"testing &#39;&#39;&#39;bold&#39;&#39;&#39; in alt"}]}' data-mw='{"caption":"testing &lt;b data-parsoid=&#39;{\"dsr\":[27,37,3,3]}&#39;>bold&lt;/b> in alt"}'><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":"Image:Foobar.jpg"}}'/></a></span></p>

<p><span class="mw-default-size" typeof="mw:Image" data-parsoid='{"optList":[{"ck":"alt","ak":"alt=testing &#39;&#39;&#39;bold&#39;&#39;&#39; in alt"}]}'><a href="./File:Foobar.jpg" data-parsoid='{"a":{"href":"./File:Foobar.jpg"},"sa":{}}'><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=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"./Link\"},\"sa\":{\"href\":\"link\"},\"dsr\":[65,73,2,2]}&#39;>link&lt;/a> and a &lt;i about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"dsr\":[80,106,null,null],\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"&amp;#39;&amp;#39;bold template&amp;#39;&amp;#39;\"}},\"i\":0}}]}&#39;>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
T20784  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-parsoid='{"optList":[{"ck":"caption","ak":"http://example.com"}]}' data-mw='{"caption":"&lt;a rel=\"mw:ExtLink\" href=\"http://example.com\" data-parsoid=&#39;{\"stx\":\"url\",\"dsr\":[18,36,0,0]}&#39;>http://example.com&lt;/a>"}'><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>
!! 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
T3887: 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
T3887: 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
T3887: 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 T2368
!! test
T2648: 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-parsoid='{"optList":[{"ck":"caption","ak":"text with a [[link]] in it"}]}' data-mw='{"caption":"text with a &lt;a rel=\"mw:WikiLink\" href=\"./Link\" title=\"Link\" data-parsoid=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"./Link\"},\"sa\":{\"href\":\"link\"},\"dsr\":[30,38,2,2]}&#39;>link&lt;/a> in it"}'><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>
!! end

!! test
T2648: 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-parsoid='{"optList":[{"ck":"caption","ak":"text with a [[link]]foo in it"}]}' data-mw='{"caption":"text with a &lt;a rel=\"mw:WikiLink\" href=\"./Link\" title=\"Link\" data-parsoid=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"./Link\"},\"sa\":{\"href\":\"link\"},\"dsr\":[30,41,2,5],\"tail\":\"foo\"}&#39;>linkfoo&lt;/a> in it"}'><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>
!! end

!! test
T2648: 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-parsoid='{"optList":[{"ck":"caption","ak":"text with a [[MeatBall:Link]] in it"}]}' 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=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"http://www.usemod.com/cgi-bin/mb.pl?Link\"},\"sa\":{\"href\":\"MeatBall:Link\"},\"isIW\":true,\"dsr\":[30,47,2,2]}&#39;>MeatBall:Link&lt;/a> in it"}'><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>
!! end

!! test
T2648: 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-parsoid='{"optList":[{"ck":"caption","ak":"text with a [[MeatBall:Link|link]] in it"}]}' 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=&#39;{\"stx\":\"piped\",\"a\":{\"href\":\"http://www.usemod.com/cgi-bin/mb.pl?Link\"},\"sa\":{\"href\":\"MeatBall:Link\"},\"isIW\":true,\"dsr\":[30,52,16,2]}&#39;>link&lt;/a> in it"}'><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>
!! 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-parsoid='{"optList":[{"ck":"caption","ak":"&lt;nowiki>text with a [[MeatBall:Link|link]] in it&lt;/nowiki>"}]}' data-mw='{"caption":"&lt;span typeof=\"mw:Nowiki\" data-parsoid=&#39;{\"dsr\":[18,75,8,9]}&#39;>text with a [[MeatBall:Link|link]] in it&lt;/span>"}'><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>
!! 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-parsoid='{"optList":[{"ck":"caption","ak":"&amp; &lt; > \""}]}' data-mw='{"caption":"&amp;amp; &amp;lt; > \""}'><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>
!! end

!! test
Escape HTML special chars in image alt text with LanguageConverter
!! options
language=zh
!! 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-parsoid='{"optList":[{"ck":"caption","ak":"&amp; &lt; > \""}]}' data-mw='{"caption":"&amp;amp; &amp;lt; > \""}'><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>
!! end

!! test
Entities in file name and attributes
!! wikitext
[[File:7%25 solution.gif|manualthumb=7%25 solution.gif|link=7%25 solution|[[7%25 solution]]]]
!! html/php
<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=7%25_solution.gif" class="new" title="File:7% solution.gif">7% solution</a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:Image" data-parsoid='{"optList":[{"ck":"bogus","ak":"manualthumb=7%25 solution.gif"},{"ck":"link","ak":"link=7%25 solution"},{"ck":"caption","ak":"[[7%25 solution]]"}]}' data-mw='{"errors":[{"key":"missing-image","message":"This image does not exist."}],"caption":"&lt;a rel=\"mw:WikiLink\" href=\"./7%25_solution\" title=\"7% solution\" data-parsoid=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"./7%25_solution\"},\"sa\":{\"href\":\"7%25 solution\"},\"dsr\":[74,91,2,2]}&#39;>7% solution&lt;/a>"}'><a href="./7%25_solution" data-parsoid='{"a":{"href":"./7%25_solution"},"sa":{"href":"link=7%25 solution"}}'><img resource="./File:7%25_solution.gif" src="./Special:FilePath/7%25_solution.gif" height="220" width="220" data-parsoid='{"a":{"resource":"./File:7%25_solution.gif","height":"220","width":"220"},"sa":{"resource":"File:7%25 solution.gif"}}'/></a></span></p>
!! end

!! test
T2499: 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-parsoid='{"optList":[{"ck":"caption","ak":"&amp;#9792;"}]}' data-mw='{"caption":"&lt;span typeof=\"mw:Entity\" data-parsoid=&#39;{\"src\":\"&amp;amp;#9792;\",\"srcContent\":\"♀\",\"dsr\":[18,25,null,null]}&#39;>♀&lt;/span>"}'><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>
!! 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
T5090: 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
Localized image handling (3).
!! options
language=fa
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/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>
!! wikitext
[[File:Foobar.jpg|بندانگشتی]]
!! 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 (T64500)
!! 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" class="mw-redirect" 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-parsoid='{"optList":[{"ck":"caption","ak":"&lt;table>&lt;tr>&lt;td>a&lt;/td>&lt;td>b&lt;/td>&lt;/tr>&lt;tr>&lt;td>c&lt;/td>&lt;/tr>&lt;/table>"}]}' data-mw='{"caption":"&lt;table data-parsoid=&#39;{\"stx\":\"html\",\"dsr\":[18,81,7,8]}&#39;>&lt;tbody data-parsoid=&#39;{\"dsr\":[25,73,0,0]}&#39;>&lt;tr data-parsoid=&#39;{\"stx\":\"html\",\"dsr\":[25,54,4,5]}&#39;>&lt;td data-parsoid=&#39;{\"stx\":\"html\",\"dsr\":[29,39,4,5]}&#39;>a&lt;/td>&lt;td data-parsoid=&#39;{\"stx\":\"html\",\"dsr\":[39,49,4,5]}&#39;>b&lt;/td>&lt;/tr>&lt;tr data-parsoid=&#39;{\"stx\":\"html\",\"dsr\":[54,73,4,5]}&#39;>&lt;td data-parsoid=&#39;{\"stx\":\"html\",\"dsr\":[58,68,4,5]}&#39;>c&lt;/td>&lt;/tr>&lt;/tbody>&lt;/table>"}'><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>
!! 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="./Main_Page#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="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" 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=&#39;{\"dsr\":[64,78,5,6]}&#39; data-mw=&#39;{\"name\":\"ref\",\"body\":{\"id\":\"mw-reference-text-cite_note-1\"},\"attrs\":{}}&#39;>&lt;a href=\"./Main_Page#cite_note-1\" style=\"counter-reset: mw-Ref 1;\" data-parsoid=\"{}\">&lt;span class=\"mw-reflink-text\" data-parsoid=\"{}\">[1]&lt;/span>&lt;/a>&lt;/span>&lt;meta typeof=\"mw:Extension/ref/Marker\" about=\"#mwt2\" data-parsoid=&#39;{\"group\":\"\",\"name\":\"\",\"content\":\"foo\",\"hasRefInRef\":false,\"dsr\":[64,78,5,6]}&#39;/>"}'><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="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" 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=&#39;{\"dsr\":[64,96,null,null],\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"&amp;lt;ref>{{echo|foo}}&amp;lt;/ref>\"}},\"i\":0}}]}&#39;>&lt;a href=\"./Main_Page#cite_note-1\" style=\"counter-reset: mw-Ref 1;\" data-parsoid=\"{}\">&lt;span class=\"mw-reflink-text\" data-parsoid=\"{}\">[1]&lt;/span>&lt;/a>&lt;/span>&lt;meta typeof=\"mw:Transclusion mw:Extension/ref/Marker\" about=\"#mwt2\" data-parsoid=&#39;{\"group\":\"\",\"name\":\"\",\"content\":\"foo\",\"hasRefInRef\":false,\"dsr\":[64,96,null,null],\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"echo\",\"href\":\"./Template:Echo\"},\"params\":{\"1\":{\"wt\":\"&amp;lt;ref>{{echo|foo}}&amp;lt;/ref>\"}},\"i\":0}}]}&#39;/>"}'><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="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" 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 (T53090)
!! 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
T2561: {{/Subpage}}
!! options
subpage title=[[Page]]
!! wikitext
{{/Subpage}}
!! html
<p><a href="/index.php?title=Page/Subpage&amp;action=edit&amp;redlink=1" class="new" title="Page/Subpage (page does not exist)">Page/Subpage</a>
</p>
!! end

###
### 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/php
cat=MediaWiki_User's_Guide sort=
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide" data-parsoid='{"stx":"simple","a":{"href":"./Category:MediaWiki_User&#39;s_Guide"},"sa":{"href":"Category:MediaWiki User&#39;s Guide"}}'/>
!! end

!! test
PAGESINCATEGORY invalid title fatal (r33546 fix)
!! wikitext
{{PAGESINCATEGORY:<bogus>}}
!! html
<p>0
</p>
!! end

!! test
Category with different sort key
!! options
cat
!! wikitext
[[Category:MediaWiki User's Guide|Foo]]
!! html/php
cat=MediaWiki_User's_Guide sort=Foo
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide#Foo" data-parsoid='{"stx":"piped","a":{"href":"./Category:MediaWiki_User&#39;s_Guide"},"sa":{"href":"Category:MediaWiki User&#39;s Guide"}}'/>
!! end

!! test
Category with identical sort key
!! options
cat
!! wikitext
[[Category:MediaWiki User's Guide|MediaWiki User's Guide]]
!! html/php
cat=MediaWiki_User's_Guide sort=MediaWiki User's Guide
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide#MediaWiki%20User's%20Guide" data-parsoid='{"stx":"piped","a":{"href":"./Category:MediaWiki_User&#39;s_Guide"},"sa":{"href":"Category:MediaWiki User&#39;s Guide"}}'/>
!! end

!! test
Category with empty sort key
!! options
cat
pst
!! wikitext
[[Category:MediaWiki User's Guide|]]
!! html/php
[[Category:MediaWiki User's Guide|MediaWiki User's Guide]]
!! end

!! test
Category with empty sort key and parentheses
!! options
cat
pst
!! wikitext
[[Category:Foo (bar)|]]
!! html/php
[[Category:Foo (bar)|Foo]]
!! end

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

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

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

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

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
!! test
Category / paragraph interactions
!! options
parsoid=wt2html
!! wikitext
Foo [[Category:Baz]] Bar

Foo [[Category:Baz]]
Bar

Foo
[[Category:Baz]]
Bar

Foo
[[Category:Baz]] Bar

Foo
[[Category:Baz]]
 [[Category:Baz]]
[[Category:Baz]]
Bar

[[Category:Baz]]
 [[Category:Baz]]
[[Category:Baz]]

[[Category:Baz]]
 {{echo|[[Category:Baz]]}}
[[Category:Baz]]
!! html/php
<p>Foo Bar
</p><p>Foo
Bar
</p><p>Foo
Bar
</p><p>Foo Bar
</p><p>Foo
Bar
</p>
!! html/parsoid
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar</p>
<p>Foo <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> Bar <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz"/> <link rel="mw:PageProp/Category" href="./Category:Baz" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Category:Baz]]"}},"i":0}}]}'/></p>
<link rel="mw:PageProp/Category" href="./Category:Baz"/>
!! end

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
##
## The whitespace on the empty line is part of the test. Please do not delete
!! test
1. Categories and newlines: All preceding newlines should be suppressed (courtesy T2087)
!! options
parsoid=wt2html
!! wikitext
This
   
[[Category:Foo]] and this should be part of same paragraph (not an indent-pre)
   
{{echo|[[Category:Foo]] and so should this!}}
!! html/php
<p>This and this should be part of same paragraph (not an indent-pre) and so should this!
</p>
!! html/parsoid
<p>This
   
<link rel="mw:PageProp/Category" href="./Category:Foo"/> and this should be part of same paragraph (not an indent-pre)
   
<link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"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 T2087)
!! 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

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
!! test
6. Categories and newlines: migrateTrailingCategories dom pass should not migrate categories not preceded by newlines
!! options
parsoid=wt2html
!! wikitext
* a [[Category:Foo]]
!! html/parsoid
<ul><li>a <link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul>
!! end

# This test also demonstrates because of newline+category tunneling
# through the list hander, template wrapping doesn't expand to the
# containing list when the list item swallows the category.
!! test
7. Categories and newlines: migrateTrailingCategories dom pass should leave template content alone
!! wikitext
* {{echo|a
[[Category:Foo]]}}
!! html/parsoid
<ul><li> <span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a\n[[Category:Foo]]"}},"i":0}}]}'>a
</span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/></li></ul>
!! end

!! test
8. Categories and newlines: migrateTrailingCategories dom pass should not get tripped by intervening templates
!! wikitext
* a

{{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"}]]}' 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
Category links with multiple namespaces
!! wikitext
[[Category:Project:Foo]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Project:Foo" />
!! end

!! test
Parsoid: Serialize link to category page with colon escape
!! 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

# We used to, but no longer wt2wt this test since the default serializer
# will normalize all categories to serialize on their own line.
# This wikitext usage is going to be fairly uncommon in production and
# selser will take care of preventing whitespace insertion if this
# occurs in an article.
#
# html2html disabled for the same reason (whitespace insertion between
# x and y).
#
# html2wt disabled because it localizes the "Category" namespace.
!! test
Link prefix/suffixes aren't applied to category links
!! options
parsoid=wt2html
language=is
!! wikitext
x[[Category:Foo]]y
!! html/php
<p>xy
</p>
!! html/parsoid
<p>x<link rel="mw:PageProp/Category" href="./Flokkur:Foo" data-parsoid=""/>y</p>
!! end

!! test
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 (T72894)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Toxine_bactérienne"/>
!! wikitext
[[Category:Toxine bactérienne]]
!! end

!! test
Parsoid: Defaultsort
!! wikitext
{{DEFAULTSORT:Foo}}
!! html/parsoid
<meta property="mw:PageProp/categorydefaultsort" content="Foo"/>
!! end

!! test
Parsoid: Defaultsort (template-generated)
!! wikitext
{{{{echo|DEFAULTSORT}}:Foo}}
!! html/parsoid
<meta property="mw:PageProp/categorydefaultsort" content="Foo" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"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 (T26502)
!! options
ill
!! wikitext
[[es:1]]
[[es:2]]
[[fr:1]]
[[fr:2]]
!! html/php
es:1 fr:1
!! html/parsoid
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/1"/>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/2"/>
<link rel="mw:PageProp/Language" href="http://fr.wikipedia.org/wiki/1"/>
<link rel="mw:PageProp/Language" href="http://fr.wikipedia.org/wiki/2"/>
!! end

###
### Sections
###
!! test
Basic section headings
!! wikitext
== Headline 1 ==
Some text

==Headline 2==
More
===Smaller headline===
Blah blah
!! html
<h2><span class="mw-headline" id="Headline_1">Headline 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Headline 1">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>Some text
</p>
<h2><span class="mw-headline" id="Headline_2">Headline 2</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<p>More
</p>
<h3><span class="mw-headline" id="Smaller_headline">Smaller headline</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Smaller headline">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
<p>Blah blah
</p>
!! end

!! test
Section headings with TOC
!! wikitext
== Headline 1 ==
=== Subheadline 1 ===
===== Skipping a level =====
====== Skipping a level ======

== Headline 2 ==
Some text
===Another headline===
!! html
<div id="toc" class="toc"><div id="toctitle" class="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" class="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" class="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" class="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" class="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 (T8204)
!! options
wgMaxTocLevel=3
!! wikitext
== title 1 ==
=== title 1.1 ===
==== title 1.1.1 ====
=== title 1.2 ===
== title 2 ==
=== title 2.1 ===
!! html
<div id="toc" class="toc"><div id="toctitle" class="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 (T8204)
!! options
wgMaxTocLevel=3
!! wikitext
==Section 1==
===Section 1.1===
====Section 1.1.1====
====Section 1.1.1.1====
==Section 2==
!! html
<div id="toc" class="toc"><div id="toctitle" class="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 (T12721)
!! wikitext
== Foo bar ==
== Foo Bar ==
!! html
<h2><span class="mw-headline" id="Foo_bar">Foo bar</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="Foo_Bar_2">Foo Bar</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></h2>

!! end

!! article
Template:sections
!! text
===Section 1===
==Section 2==
!! endarticle

!! test
Template with sections, __NOTOC__
!! wikitext
__NOTOC__
==Section 0==
{{sections}}
==Section 4==
!! html
<h2><span class="mw-headline" id="Section_0">Section 0</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Section 0">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h3><span class="mw-headline" id="Section_1">Section 1</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Sections&amp;action=edit&amp;section=T-1" title="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" class="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
T3219 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 (T21910)
!! 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 (T27462)
!! wikitext
The tooltips shall not show entities to the user (ie. be double escaped)

== text > text ==
section 1

== text < text ==
section 2

== text & text ==
section 3

== text ' text ==
section 4

== text " text ==
section 5
!! html
<p>The tooltips shall not show entities to the user (ie. be double escaped)
</p>
<div id="toc" class="toc"><div id="toctitle" class="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" class="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" class="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 (T25393)
(__NOEDITSECTION__ for clearer output, doesn't matter here)
!! wikitext
<h1>Header 1</h1>
== Header 1.1 ==
== Header 1.2 ==

<h1>Header 2
</h1>
== Header 2.1 ==
== Header 2.2 ==
__NOEDITSECTION__
!! html
<div id="toc" class="toc"><div id="toctitle" class="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
T3219 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
T3186 news: in the middle of text
!! wikitext
http://en.wikinews.org/wiki/Wikinews:Workplace
!! html
<p><a rel="nofollow" class="external free" href="http://en.wikinews.org/wiki/Wikinews:Workplace">http://en.wikinews.org/wiki/Wikinews:Workplace</a>
</p>
!!end


!! test
Namespaced link must have a title
!! wikitext
[[Project:]]
!! html
<p>[[Project:]]
</p>
!!end

!! test
Namespaced link must have a title (bad fragment version)
!! wikitext
[[Project:#fragment]]
!! html
<p>[[Project:#fragment]]
</p>
!!end


###
### HTML tags and HTML attributes
###

!! test
div with no attributes
!! wikitext
<div>HTML rocks</div>
!! html
<div>HTML rocks</div>

!! end

!! test
div with double-quoted attribute
!! wikitext
<div id="rock">HTML rocks</div>
!! html
<div id="rock">HTML rocks</div>

!! end

!! test
div with single-quoted attribute
!! wikitext
<div id='rock'>HTML rocks</div>
!! html
<div id="rock">HTML rocks</div>

!! end

!! test
div with unquoted attribute
!! wikitext
<div id=rock>HTML rocks</div>
!! html
<div id="rock">HTML rocks</div>

!! end

!! test
div with illegal double attributes
!! wikitext
<div id="a" id="b">HTML rocks</div>
!! html
<div id="b">HTML rocks</div>

!!end

!! test
div with empty attribute value, space before equals
!! options
parsoid=wt2html,html2html
!! wikitext
<div class =>HTML rocks</div>
!! html/php
<div class="">HTML rocks</div>

!! html/parsoid
<div class="" data-parsoid='{"stx":"html"}'>HTML rocks</div>
!! end

!! test
div with multiple empty attribute values
!! options
parsoid=wt2html,html2html
!! wikitext
<div id= title=>HTML rocks</div>
!! html/php
<div id="title.3D">HTML rocks</div>

!! html/parsoid
<div id="title.3D" data-parsoid='{"stx":"html"}'>HTML rocks</div>
!! end

!! test
table with multiple empty attribute values
!! options
parsoid=wt2html,html2html
!! wikitext
{| title= id=
| hi
|}
!! html/php
<table title="id=">
<tr>
<td> hi
</td></tr></table>

!! html/parsoid
<table title="id=">
<tbody><tr><td> hi</td></tr>
</tbody></table>
!! end

!! test
div with braces in attribute value
!! wikitext
<div title="{}">Foo</div>
!! html/php
<div title="&#123;&#125;">Foo</div>

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

!! test
div with empty attribute value, no space before equals
!! options
parsoid=wt2html,html2html
!! wikitext
<div class=>HTML rocks</div>
!! html/php
<div class="">HTML rocks</div>

!! html/parsoid
<div class="">HTML rocks</div>
!! end

!! test
HTML multiple attributes correction
!! wikitext
<p class="error" class="awesome">Awesome!</p>
!! html
<p class="awesome">Awesome!</p>

!!end

!! test
Table multiple attributes correction
!! wikitext
{|
!+ class="error" class="awesome"| status
|}
!! html
<table>
<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 T43545, T52604, T53081)
###

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

# This was T43545 in the PHP parser.
# 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 T53081 in the PHP parser.
# Note that there are some other nestable tags (b, i, etc) which are
# not covered; see T53081 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 (T3702)
!! 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 (T3850 - 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 (T3850 - 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 (T3938)
!! wikitext
[[Main Page|this&that]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">this&amp;that</a>
</p>
!!end

!! article
אַ
!! text
Test for unicode normalization

The page's name is U+05d0 U+05b7, with non-canonical form U+FB2E
!! endarticle

!! test
(T21451) 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 (T4067)
!! wikitext
<font color="">foo</font>
!! html
<p><font color="">foo</font>
</p>
!! end

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

!! test
Attribute test: equals, then nothing
!! options
parsoid=wt2html,html2html
!! wikitext
<font color=>foo</font>
!! html/php
<p><font color="">foo</font>
</p>
!! html/parsoid
<p><font color="" data-parsoid='{"stx":"html"}'>foo</font></p>
!! end

!! test
Attribute test: unquoted value
!! options
parsoid=wt2html,html2html
!! wikitext
<font color=x>foo</font>
!! html/php
<p><font color="x">foo</font>
</p>
!! html/parsoid
<p><font color="x" data-parsoid='{"stx":"html"}'>foo</font></p>
!! end

!! test
Attribute test: unquoted but illegal value (hash)
!! wikitext
<font color=#x>foo</font>
!! html
<p><font color="#x">foo</font>
</p>
!! end

# Parsoid does not serialize to empty attribute syntax,
# so wt2wt and html2wt cases are skipped
!! test
Attribute test: no value (T54330)
!! options
parsoid=wt2html,html2html
!! wikitext
<font color>foo</font>
!! html/php
<p><font color="">foo</font>
</p>
!! html/parsoid
<p><font color="">foo</font></p>
!! end

!! test
T4095: link with three closing brackets
!! wikitext
[[Main Page]]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">Main Page</a>]
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a>]</p>
!! end

!! test
T4095: link with pipe and three closing brackets
!! wikitext
[[Main Page|link]]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">link</a>]
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">link</a>]</p>
!! end

!! test
T4095: link with pipe and three closing brackets, version 2
!! wikitext
[[Main Page|[http://example.com/]]]
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page">[http://example.com/]</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">[http://example.com/]</a></p>
!! end


###
### Safety
###

!! article
Template:Dangerous attribute
!! text
" onmouseover="alert(document.cookie)
!! endarticle

!! article
Template:Dangerous style attribute
!! text
border-size: expression(alert(document.cookie))
!! endarticle

!! article
Template:Div style
!! text
<div style="float: right; {{{1}}}">Magic div</div>
!! endarticle

!! test
T4304: HTML attribute safety (safe template; regression T4309)
!! wikitext
<div title="{{test}}"></div>
!! html/php
<div title="This is a test template"></div>

!! html/parsoid
<div title="This is a test template" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"title":"This is a test template"},"sa":{"title":"{{test}}"}}' data-mw='{"attribs":[[{"txt":"title"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[12,20,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"test\",\"href\":\"./Template:Test\"},\"params\":{},\"i\":0}}]}&#39;>This is a test template&lt;/span>"}]]}'></div>
!! end

# Parsoid has enough context to handle this case
!! test
T4304: HTML attribute safety (dangerous template; 2309)
!! wikitext
<div title="{{dangerous attribute}}"></div>
!! html/php
<div title=""></div>

!! html/parsoid
<div title='" onmouseover="alert(document.cookie)' about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"title":"\" onmouseover=\"alert(document.cookie)"},"sa":{"title":"{{dangerous attribute}}"}}' data-mw='{"attribs":[[{"txt":"title"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[12,35,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"dangerous attribute\",\"href\":\"./Template:Dangerous_attribute\"},\"params\":{},\"i\":0}}]}&#39;>\" onmouseover=\"alert(document.cookie)&lt;/span>"}]]}'></div>
!! end

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

!! html/parsoid
<div style="/* insecure input */" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"{{dangerous style attribute}}"}}' data-mw='{"attribs":[[{"txt":"style"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[12,41,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"dangerous style attribute\",\"href\":\"./Template:Dangerous_style_attribute\"},\"params\":{},\"i\":0}}]}&#39;>border-size: expression(alert(document.cookie))&lt;/span>"}]]}'></div>
!! end

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

!! html/parsoid
<div style="float: right; width: 200px" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","a":{"style":"float: right; width: 200px"},"sa":{"style":"float: right; {{{1}}}"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"div style","href":"./Template:Div_style"},"params":{"1":{"wt":"width: 200px"}},"i":0}}]}'>Magic div</div>
!! end

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

!! html/parsoid
<div style="/* insecure input */" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"float: right; {{{1}}}"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"div style","href":"./Template:Div_style"},"params":{"1":{"wt":"width: expression(alert(document.cookie))"}},"i":0}}]}'>Magic div</div>
!! end

## Parsoid output here differs; needs investigation.
!! test
T4304: HTML attribute safety (unsafe breakout parameter; 2309)
!! wikitext
{{div style|"><script>alert(document.cookie)</script>}}
!! html
<div style="float: right;">&lt;script&gt;alert(document.cookie)&lt;/script&gt;"&gt;Magic div</div>

!! end

## Parsoid output here differs; needs investigation.
!! test
T4304: HTML attribute safety (unsafe breakout parameter 2; 2309)
!! wikitext
{{div style|" ><script>alert(document.cookie)</script>}}
!! html
<div style="float: right;">&lt;script&gt;alert(document.cookie)&lt;/script&gt;"&gt;Magic div</div>

!! end

!! test
T4304: HTML attribute safety (link)
!! wikitext
<div title="[[Main Page]]"></div>
!! html
<div title="&#91;&#91;Main Page]]"></div>

!! end

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

!! end

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

!! end

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

!! end

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

!! end

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

!! end

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

!! end

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

!! end

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

!! html/parsoid
<div style="background:blue" data-parsoid='{"stx":"html","a":{"style":"background:blue"},"sa":{"style":"&lt;nowiki>background:blue&lt;/nowiki>"}}'></div>
!! end

!! test
T5244: HTML attribute safety (extension; unsafe)
!! wikitext
<div style="<nowiki>border-left:expression(alert(document.cookie))</nowiki>"></div>
!! html/php
<div style="/* insecure input */"></div>

!! html/parsoid
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"&lt;nowiki>border-left:expression(alert(document.cookie))&lt;/nowiki>"}}'></div>
!! end

# More MSIE fun discovered by Tom Gilder

!! test
MSIE CSS safety test: spurious slash
!! wikitext
<div style="background-image:u\rl(javascript:alert('boo'))">evil</div>
!! html/php
<div style="/* insecure input */">evil</div>

!! html/parsoid
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"background-image:u\\rl(javascript:alert(&#39;boo&#39;))"}}'>evil</div>
!! end

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

!! html/parsoid
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"background-image:u\\72l(javascript:alert(&#39;boo&#39;))"}}'>evil</div>
!! end

!! test
MSIE CSS safety test: comment in url
!! wikitext
<div style="background-image:u/**/rl(javascript:alert('boo'))">evil</div>
!! html/php
<div style="background-image:u rl(javascript:alert(&#39;boo&#39;))">evil</div>

!! html/parsoid
<div style="background-image:u rl(javascript:alert('boo'))" data-parsoid='{"stx":"html","a":{"style":"background-image:u rl(javascript:alert(&#39;boo&#39;))"},"sa":{"style":"background-image:u/**/rl(javascript:alert(&#39;boo&#39;))"}}'>evil</div>
!! end

!! test
MSIE CSS safety test: comment in expression
!! wikitext
<div style="background-image:expres/**/sion(alert('boo4'))">evil4</div>
!! html/php
<div style="background-image:expres sion(alert(&#39;boo4&#39;))">evil4</div>

!! html/parsoid
<div style="background-image:expres sion(alert('boo4'))" data-parsoid='{"stx":"html","a":{"style":"background-image:expres sion(alert(&#39;boo4&#39;))"},"sa":{"style":"background-image:expres/**/sion(alert(&#39;boo4&#39;))"}}'>evil4</div>
!! end

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

!! html/parsoid
<p style="/* invalid control char */" data-parsoid='{"stx":"html","a":{"style":"/* invalid control char */"},"sa":{"style":"font-size: 100px; background-image:url\\b(https://www.google.com/images/srpr/logo6w.png)"}}'>A</p>
!! end

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

!! html/parsoid
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: ｅｘｐｒｅｓｓｉｏｎ((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>A</p>
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"top:ＥＸＰＲＥＳＳＩＯＮ(alert())"}}'>B</div>
!! end

!! test
MSIE 6 CSS safety test: IPA extensions (T57332)
!! 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/php
<div style="/* insecure input */">A</div>
<p style="/* insecure input */">B</p>

!! html/parsoid
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"background-image:uʀʟ(javascript:alert())"}}'>A</div>
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expʀessɪoɴ((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>B</p>
!! end

!! test
MSIE 6 CSS safety test: sup/sub script (T57332)
!! 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/php
<div style="/* insecure input */">A</div>
<div style="/* insecure input */">B</div>
<p style="/* insecure input */">C</p>

!! html/parsoid
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"background-image:url⁽javascript:alert())"}}'>A</div>
<div style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"background-image:url₍javascript:alert())"}}'>B</div>
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expressioⁿ((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>C</p>
!! end

!! test
Opera -o-link CSS
!! options
parsoid=wt2html,html2html
!! wikitext
<div
title="&#100;&#97;&#116;&#97;&#58;&#116;&#101;&#120;&#116;&#47;&#104;&#116;&#109;&#108;&#44;&#60;&#105;&#109;&#103;&#32;&#115;&#114;&#99;&#61;&#49;&#32;&#111;&#110;&#101;&#114;&#114;&#111;&#114;&#61;&#97;&#108;&#101;&#114;&#116;&#40;&#49;&#41;&#62;"
style="-o-link:attr(title);-o-link-source:current">X</div>
!! html/php
<div title="data:text/html,&lt;img src=1 onerror=alert(1)&gt;" style="/* insecure input */">X</div>

!! html/parsoid
<div title="data:text/html,&lt;img src=1 onerror=alert(1)>" style="/* insecure input */" data-parsoid='{"stx":"html","a":{"title":"data:text/html,&lt;img src=1 onerror=alert(1)>","style":"/* insecure input */"},"sa":{"title":"&amp;#100;&amp;#97;&amp;#116;&amp;#97;&amp;#58;&amp;#116;&amp;#101;&amp;#120;&amp;#116;&amp;#47;&amp;#104;&amp;#116;&amp;#109;&amp;#108;&amp;#44;&amp;#60;&amp;#105;&amp;#109;&amp;#103;&amp;#32;&amp;#115;&amp;#114;&amp;#99;&amp;#61;&amp;#49;&amp;#32;&amp;#111;&amp;#110;&amp;#101;&amp;#114;&amp;#114;&amp;#111;&amp;#114;&amp;#61;&amp;#97;&amp;#108;&amp;#101;&amp;#114;&amp;#116;&amp;#40;&amp;#49;&amp;#41;&amp;#62;","style":"-o-link:attr(title);-o-link-source:current"}}'>X</div>
!! end

!! test
MSIE 6 CSS safety test: Repetition markers (T57332)
!! 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/php
<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>

!! html/parsoid
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expres〱ion((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>A</p>
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expresゝion((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>B</p>
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expresーion((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>C</p>
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expresヽion((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>D</p>
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expresﹽion((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>E</p>
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expresﹼion((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>F</p>
<p style="/* insecure input */" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"font-size: 100px; color: expresｰion((title=&#39;XSSed&#39;),&#39;red&#39;)"}}'>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 (T8255)
!! wikitext
<div style="background: {{identity|#00FF00}}">-</div>
!! html
<div style="background: #00FF00">-</div>

!! end

!! test
Expansion of multi-line templates in attribute values (T8255 sanity check)
!! wikitext
<div style="background:
#00FF00">-</div>
!! html/php
<div style="background: #00FF00">-</div>

!! html/parsoid
<div style="background:
#00FF00">-</div>
!! end

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

!! end

!! test
Tags which are hidden from Tidy cannot pass through the Sanitizer
!! wikitext
<mw:toc><script>alert();</script></mw:toc>
!! html+tidy
<p>&lt;mw:toc&gt;&lt;script&gt;alert();&lt;/script&gt;&lt;/mw:toc&gt;</p>
!! end

###
### Parser hooks (see tests/parser/parserTestsParserHook.php for the <tag> extension)
###

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

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

## Don't expect parsoid to rt this form.
!! test
Parser hook: empty input using terminated empty elements
!! options
parsoid=wt2html,html2html
!! wikitext
<tag/>
!! html/php
<pre>
NULL
array (
)
</pre>

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

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

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

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

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

## Don't expect parsoid to rt this form.
!! test
Parser hook: case insensitive
!! options
parsoid=wt2html,html2html
!! wikitext
<TAG>input</TAG>
!! html/php
<pre>
'input'
array (
)
</pre>

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

## Don't expect parsoid to rt this form.
!! test
Parser hook: case insensitive, redux
!! options
parsoid=wt2html,html2html
!! wikitext
<TaG>input</TAg>
!! html/php
<pre>
'input'
array (
)
</pre>

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

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

!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"&lt;tag>"}}' data-parsoid='{}' about="#mwt2"></pre>&lt;/tag>
!! 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>

!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: basic arguments, variations
!! options
parsoid=wt2html,html2html
!! wikitext
<tag width=200 height = "100" depth = '50' square></tag>
!! html/php
<pre>
''
array (
  'width' => '200',
  'height' => '100',
  'depth' => '50',
  'square' => '',
)
</pre>

!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
!! end

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

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

## Don't expect parsoid to rt this form.
!! test
Parser hook: empty input using terminated empty elements (T4374)
!! options
parsoid=wt2html,html2html
!! wikitext
<tag foo=bar/>text
!! html/php
<pre>
NULL
array (
  'foo' => 'bar',
)
</pre>text

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

## </tag> should be output literally since there is no matching tag that begins it
## Don't expect parsoid to rt this form.
!! test
Parser hook: basic arguments using terminated empty elements (T4374)
!! options
parsoid=wt2html
!! wikitext
<tag width=200 height = "100" depth = '50' square/>
other stuff
</tag>
!! html/php
<pre>
NULL
array (
  'width' => '200',
  'height' => '100',
  'depth' => '50',
  'square' => '',
)
</pre>
<p>other stuff
&lt;/tag&gt;
</p>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":null}' about="#mwt2"></pre><p>other stuff
&lt;/tag></p>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: Don't allow unclosed extension tags
!! options
parsoid=wt2html
!! wikitext
test <tag>123

this is a '''test'''
!! html/php
<p>test &lt;tag&gt;123
</p><p>this is a <b>test</b>
</p>
!! html/parsoid
<p>test &lt;tag>123</p>

<p>this is a <b>test</b></p>
!! end

###
### (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><br />
hello, world
</p>
!! html/parsoid
<p><span typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{},"body":{"extsrc":"hello, world"}}' data-parsoid='{}' about="#mwt2"></span></p>
<p typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{"action":"flush"},"body":null}' data-parsoid='{}' about="#mwt4">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>
!! html/parsoid
<!-- <statictag&#x3E;hello, world</statictag&#x3E; -->
<p typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{"action":"flush"},"body":null}' data-parsoid='{}' about="#mwt2"></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/php
<p><span id=".C3.A6:_v">byte</span><a href="#.C3.A6:_v">backlink</a>
</p>
!! html/parsoid
<p><span id=".C3.A6:_v" data-parsoid='{"stx":"html","a":{"id":".C3.A6:_v"},"sa":{"id":"æ: v"}}'>byte</span><a rel="mw:WikiLink" href="./Main_Page#.C3.A6:_v" data-parsoid='{"stx":"piped","a":{"href":"./Main_Page#.C3.A6:_v"},"sa":{"href":"#æ: v"}}'>backlink</a></p>
!! end

# In HTML5, the restrictions are that id must contain at least one character,
# and must not contain any space characters.
!! test
Sanitizer: Validating the contents of the id attribute (T6515)
!! options
disabled
!! wikitext
<br id="" /><br id="a space" />
!! html
Something ...
!! end

# In HTML5, id must be unique amongst all the ids in the element's home subtree.
!! test
Sanitizer: Validating id attribute uniqueness (T6515, T8301)
!! options
disabled
!! wikitext
<br id="foo" /><br id="foo" />
!! html
Something need to be done. foo-2 ? 
!! end

!! test
Sanitizer: Validating that <meta> and <link> work, but only for Microdata
!! wikitext
<div itemscope>
	<meta itemprop="hello" content="world">
	<meta http-equiv="refresh" content="5">
	<meta itemprop="hello" http-equiv="refresh" content="5">
	<link itemprop="hello" href="{{SERVER}}">
	<link rel="stylesheet" href="{{SERVER}}">
	<link rel="stylesheet" itemprop="hello" href="{{SERVER}}">
</div>
!! html
<div itemscope="">
<p>	<meta itemprop="hello" content="world" />
	&lt;meta http-equiv="refresh" content="5"&gt;
	<meta itemprop="hello" content="5" />
</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 (T7757)
!! options
language=zh
!! wikitext
this bit is safe: }-

but if we add a conversion instance: -{zh-cn:xxx;zh-tw:yyy}-

then we get cut off here: }-

all additional text is vanished
!! html
<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 (T7487)
!! 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 (T13874)
!! wikitext
<div style="width:50% !important">important</div>
!! html
<div style="width:50% !important">important</div>

!!end

!! test
Punctuation: CSS ! important (T13874; with space after)
!! wikitext
<div style="width:50% ! important">important</div>
!! html
<div style="width:50% ! important">important</div>

!!end

!! test
HTML bullet list, closed tags (T7497)
!! wikitext
<ul>
<li>One</li>
<li>Two</li>
</ul>
!! html/php
<ul>
<li>One</li>
<li>Two</li>
</ul>

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

!! end

!! test
HTML bullet list, unclosed tags (T7497)
!! wikitext
<ul>
<li>One
<li>Two
</ul>
!! html/php+tidy
<ul>
<li>One</li>
<li>Two</li>
</ul>
!! html/parsoid
<ul data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>One</li>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>Two</li>
</ul>

!! end

!! test
HTML ordered list, closed tags (T7497)
!! wikitext
<ol>
<li>One</li>
<li>Two</li>
</ol>
!! html/php
<ol>
<li>One</li>
<li>Two</li>
</ol>

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

!! end

!! test
HTML ordered list, unclosed tags (T7497)
!! options
!! wikitext
<ol>
<li>One
<li>Two
</ol>
!! html/php+tidy
<ol>
<li>One</li>
<li>Two</li>
</ol>
!! html/parsoid
<ol data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>One</li>
<li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>Two</li>
</ol>

!! end

!! test
HTML nested bullet list, closed tags (T7497)
!! wikitext
<ul>
<li>One</li>
<li>Two:
<ul>
<li>Sub-one</li>
<li>Sub-two</li>
</ul>
</li>
</ul>
!! html/php
<ul>
<li>One</li>
<li>Two:
<ul>
<li>Sub-one</li>
<li>Sub-two</li>
</ul>
</li>
</ul>

!! html/parsoid
<ul data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html"}'>One</li>
<li data-parsoid='{"stx":"html"}'>Two:
<ul data-parsoid='{"stx":"html"}'>
<li data-parsoid='{"stx":"html"}'>Sub-one</li>
<li data-parsoid='{"stx":"html"}'>Sub-two</li>
</ul>
</li>
</ul>
!! end

!! test
HTML nested bullet list, open tags (T7497)
!! wikitext
<ul>
<li>One
<li>Two:
<ul>
<li>Sub-one
<li>Sub-two
</ul>
</ul>
!! html/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 (T7497)
!! wikitext
<ol>
<li>One</li>
<li>Two:
<ol>
<li>Sub-one</li>
<li>Sub-two</li>
</ol>
</li>
</ol>
!! html
<ol>
<li>One</li>
<li>Two:
<ol>
<li>Sub-one</li>
<li>Sub-two</li>
</ol>
</li>
</ol>

!! end

!! test
HTML nested ordered list, open tags (T7497)
!! wikitext
<ol>
<li>One
<li>Two:
<ol>
<li>Sub-one
<li>Sub-two
</ol>
</ol>
!! html/php
<ol>
<li>One
<li>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 T55505
!!test
T7918: autonumbering
!! wikitext
[http://first/] [http://second] [ftp://ftp]

ftp://inlineftp

[mailto:enclosed@mail.tld With target]

[mailto:enclosed@mail.tld]

mailto:inline@mail.tld
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://first/">[1]</a> <a rel="nofollow" class="external autonumber" href="http://second">[2]</a> <a rel="nofollow" class="external autonumber" href="ftp://ftp">[3]</a>
</p><p><a rel="nofollow" class="external free" href="ftp://inlineftp">ftp://inlineftp</a>
</p><p><a rel="nofollow" class="external text" href="mailto:enclosed@mail.tld">With target</a>
</p><p><a rel="nofollow" class="external autonumber" href="mailto:enclosed@mail.tld">[4]</a>
</p><p><a rel="nofollow" class="external free" href="mailto:inline@mail.tld">mailto:inline@mail.tld</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://first/"></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" class="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" class="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
!! options
parsoid=wt2html,html2html
!! 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>
!! html/parsoid
<h2>a</h2>
<table style="__TOC__"></table>
!! end

# Known to produce bogus xml (extra </td>)
!! test
Fuzz testing: Parser16
!! 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
parsoid=wt2html
!! wikitext
{|
{{{|
<u CLASS=
| {{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--><noinclude>}}}} >
<br style="onmouseover='alert(document.cookie);' " />

MOVE YOUR MOUSE CURSOR OVER THIS TEXT
|
!! html/php
<table>
{{{|
<u class="&#124;">}}}} &gt;
<br style="onmouseover=&#39;alert(document.cookie);&#39;" />

MOVE YOUR MOUSE CURSOR OVER THIS TEXT
<tr>
<td></u>
</td>
</tr>
</table>

!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true}'>{{{|
<u class="|" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->&lt;noinclude>}}}}":null},"sa":{"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->&lt;noinclude>}}}}":""},"autoInsertedEnd":true}' data-mw='{"attribs":[[{"txt":"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->}}}}","html":"{&lt;span about=\"#mwt1\" typeof=\"mw:Param\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[21,79,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"templatearg\":{\"target\":{\"wt\":\"SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->&amp;lt;noinclude>\"},\"params\":{},\"i\":0}}]}&#39;>{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->}}}&lt;/span>}"},{"html":""}]]}'>
<br style="onmouseover='alert(document.cookie);' " data-parsoid='{"stx":"html","selfClose":true}'/></u></p><p data-parsoid='{"fostered":true,"autoInsertedEnd":true}'><u class="|" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->&lt;noinclude>}}}}":null},"sa":{"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->&lt;noinclude>}}}}":""},"autoInsertedEnd":true,"autoInsertedStart":true}' data-mw='{"attribs":[[{"txt":"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->}}}}","html":"{&lt;span about=\"#mwt1\" typeof=\"mw:Param\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[21,79,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"templatearg\":{\"target\":{\"wt\":\"SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->&amp;lt;noinclude>\"},\"params\":{},\"i\":0}}]}&#39;>{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx-->}}}&lt;/span>}"},{"html":""}]]}'>MOVE YOUR MOUSE CURSOR OVER THIS TEXT</u></p><table data-parsoid='{"autoInsertedEnd":true}'>



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

# Note: the current result listed for this is not what the original one was,
# but the original bug was JavaScript injection, which is fixed in any case.
# It's not clear that the original result listed was any more correct than the
# current one.  Original result:
# <p>{{{| 
# </p>
# <li class="&#124;&#124;">
# }}}blah" onmouseover="alert('hello world');" align="left"<b>MOVE MOUSE CURSOR OVER HERE</b>
!!test
Fuzz testing: Parser25 (T8055)
!! wikitext
{{{
| 
<LI CLASS=||
 >
}}}blah" onmouseover="alert('hello world');" align="left"'''MOVE MOUSE CURSOR OVER HERE
!! html/php
<p>&lt;LI CLASS=blah" onmouseover="alert('hello world');" align="left"<b>MOVE MOUSE CURSOR OVER HERE</b>
</p>
!! html/parsoid
<span about="#mwt1" typeof="mw:Param" data-parsoid='{"pi":[[{"k":"1"},{"k":"2"},{"k":"3"}]]}' data-mw='{"parts":[{"templatearg":{"target":{"wt":"\n"},"params":{"1":{"wt":" \n&lt;LI CLASS="},"2":{"wt":""},"3":{"wt":"\n >\n"}},"i":0}},"blah\" onmouseover=\"alert(&#39;hello world&#39;);\" align=\"left\"&#39;&#39;&#39;MOVE MOUSE CURSOR OVER HERE"]}'> 
</span><p about="#mwt1">&lt;LI CLASS=blah" onmouseover="alert('hello world');" align="left"<b>MOVE MOUSE CURSOR OVER HERE</b></p>
!! end

!!test
Fuzz testing: URL adjacent extension (with space, clean)
!! wikitext
http://example.com <nowiki>junk</nowiki>
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a> junk
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" 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 typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"junk"}}'>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= "}]}' 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":{}}'><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 (T8577)
!! wikitext
<pre dir="&#10;"></pre>
!! html/php
<pre dir="&#10;"></pre>

!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" dir="&amp;#10;" data-mw='{"name":"pre","attrs":{"dir":"&amp;#10;"},"body":{"extsrc":""}}'></pre>
!! end

!! test
Parsing optional HTML elements (T8171)
!! options
!! wikitext
<table>
  <tr>
    <td> Some tabular data</td>
    <td> More tabular data ...
    <td> And yet som tabular data</td>
  </tr>
</table>
!! html
<table>
  <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> (T8171)
!! options
!! wikitext
<table>
  <tr>
    <td> Some tabular data</td>
    <td> More tabular data ...</td>
    <td> And yet som tabular data</td>
  </tr>
</table>
!! html
<table>
  <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
<ul class="mw-prefixindex-list"><li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>

!! end

!! test
Special page transclusion twice (T7021)
!! options
!! wikitext
{{Special:Prefixindex/Xyzzyx}}
{{Special:Prefixindex/Xyzzyx}}
!! html
<ul class="mw-prefixindex-list"><li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>
<ul class="mw-prefixindex-list"><li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>

!! end

!! test
Transclusion of default MediaWiki message
!! wikitext
{{MediaWiki:Mainpage}}
!! html
<p>Main Page
</p>
!! end

!! test
Transclusion of nonexistent MediaWiki message
!! wikitext
{{MediaWiki:Mainpagexxx}}
!! html
<p><a href="/index.php?title=MediaWiki:Mainpagexxx&amp;action=edit&amp;redlink=1" class="new" title="MediaWiki:Mainpagexxx (page does not exist)">MediaWiki:Mainpagexxx</a>
</p>
!! end

!! test
Transclusion of MediaWiki message with underscore
!! wikitext
{{MediaWiki:history_short}}
!! html
<p>History
</p>
!! end

!! test
Transclusion of MediaWiki message with space
!! wikitext
{{MediaWiki:history short}}
!! html
<p>History
</p>
!! end

!! test
Invalid header with following text
!! wikitext
= x = y
!! html
<p>= x = y
</p>
!! end


!! test
Section extraction test (section 0)
!! options
section=0
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
!! end

!! test
Section extraction test (section 1)
!! options
section=1
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
==a==
===aa===
====aaa====
!! end

!! test
Section extraction test (section 2)
!! options
section=2
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===aa===
====aaa====
!! end

!! test
Section extraction test (section 3)
!! options
section=3
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
====aaa====
!! end

!! test
Section extraction test (section 4)
!! options
section=4
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
==b==
===ba===
===bb===
====bba====
===bc===
!! end

!! test
Section extraction test (section 5)
!! options
section=5
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===ba===
!! end

!! test
Section extraction test (section 6)
!! options
section=6
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===bb===
====bba====
!! end

!! test
Section extraction test (section 7)
!! options
section=7
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
====bba====
!! end

!! test
Section extraction test (section 8)
!! options
section=8
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===bc===
!! end

!! test
Section extraction test (section 9)
!! options
section=9
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
==c==
===ca===
!! end

!! test
Section extraction test (section 10)
!! options
section=10
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
===ca===
!! end

!! test
Section extraction test (nonexistent section 11)
!! options
section=11
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
!! end

!! test
Section extraction test with bogus heading (section 1)
!! options
section=1
!! wikitext
==a==
==bogus== not a legal section
==b==
!! html/php
==a==
==bogus== not a legal section
!! end

!! test
Section extraction test with bogus heading (section 2)
!! options
section=2
!! wikitext
==a==
==bogus== not a legal section
==b==
!! html/php
==b==
!! end

!! test
Section extraction test with comment after heading (section 1)
!! options
section=1
!! wikitext
==a==
==b== <!-- -->
==c==
!! html/php
==a==
!! end

!! test
Section extraction test with comment after heading (section 2)
!! options
section=2
!! wikitext
==a==
==b== <!-- -->
==c==
!! html/php
==b== <!-- -->
!! end

!! test
Section extraction test with bogus <nowiki> heading (section 1)
!! options
section=1
!! wikitext
==a==
==bogus== <nowiki>not a legal section</nowiki>
==b==
!! html/php
==a==
==bogus== <nowiki>not a legal section</nowiki>
!! end

!! test
Section extraction test with bogus <nowiki> heading (section 2)
!! options
section=2
!! wikitext
==a==
==bogus== <nowiki>not a legal section</nowiki>
==b==
!! html/php
==b==
!! end

# Formerly testing for T4587, now resolved by the use of unmarked sections
# instead of respecting commented sections
!! test
Section extraction prefixed by comment (section 1)
!! options
section=1
!! wikitext
<!-- -->==sec1==
==sec2==
!! html/php
==sec2==
!!end

!! test
Section extraction prefixed by comment (section 2)
!! options
section=2
!! wikitext
<!-- -->==sec1==
==sec2==
!! html/php

!!end

# Formerly testing for T4607, now resolved by the use of unmarked sections
# instead of respecting HTML-style headings
!! test
Section extraction, mixed wiki and html (section 1)
!! options
section=1
!! wikitext
<h2>unmarked</h2>
unmarked
==1==
one
==2==
two
!! html/php
==1==
one
!! end

!! test
Section extraction, mixed wiki and html (section 2)
!! options
section=2
!! wikitext
<h2>unmarked</h2>
unmarked
==1==
one
==2==
two
!! html/php
==2==
two
!! end


# Formerly testing for T5342
!! test
Section extraction, heading surrounded by <noinclude>
!! options
section=1
!! wikitext
<noinclude>==unmarked==</noinclude>
==marked==
!! html/php
==marked==
!!end

# Test behavior of T21910
!! test
Sectiion with all-equals
!! options
section=2
!! wikitext
=== 
The line above must have a trailing space
=== <!--
--> <!-- -->
But just in case it doesn't...
!! html/php
=== <!--
--> <!-- -->
But just in case it doesn't...
!! end

!! test
Section replacement test (section 0)
!! options
replace=0,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
xxx

==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 1)
!! options
replace=1,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
xxx

==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 2)
!! options
replace=2,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
xxx

==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 3)
!! options
replace=3,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
xxx

==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 4)
!! options
replace=4,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
xxx

==c==
===ca===
!! end

!! test
Section replacement test (section 5)
!! options
replace=5,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
xxx

===bb===
====bba====
===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 6)
!! options
replace=6,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
xxx

===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 7)
!! options
replace=7,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
xxx

===bc===
==c==
===ca===
!! end

!! test
Section replacement test (section 8)
!! options
replace=8,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
xxx

==c==
===ca===
!!end

!! test
Section replacement test (section 9)
!! options
replace=9,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
xxx
!! end

!! test
Section replacement test (section 10)
!! options
replace=10,"xxx"
!! wikitext
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
===ca===
!! html/php
start
==a==
===aa===
====aaa====
==b==
===ba===
===bb===
====bba====
===bc===
==c==
xxx
!! end

!! test
Section replacement test with initial whitespace (T15728)
!! options
replace=2,"xxx"
!! wikitext
 Preformatted initial line
==a==
===a===
!! html/php
 Preformatted initial line
==a==
xxx
!! end


!! test
Section extraction, heading followed by pre with 20 spaces (T8398)
!! options
section=1
!! wikitext
==a==
                    a
!! html/php
==a==
                    a
!! end

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


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

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

!! test
Section replacement, <pre> around bogus header (T12309)
!! options
replace=2,"xxx"
!! wikitext
== Section One ==
<pre>
=======
</pre>

== Section Two ==
stuff
!! html/php
== Section One ==
<pre>
=======
</pre>

xxx
!! end

!! test
Handling of &#x0A; in URLs
!! wikitext
** irc://&#x0A;a
!! html/php
<ul><li><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" data-parsoid='{"stx":"url","a":{"href":"irc://%0Aa"},"sa":{"href":"irc://&amp;#x0A;a"}}'>irc://%0Aa</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
| is not a magic word here but {{!}} is still a magic word here
!! html/php
<p>| is a magic word there and | is still a magic word here
| is not a magic word here but | is still a magic word here
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"!","href":"./Template:!"},"params":{},"i":0}}]}'>|</span> is a magic word there and <span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"!","href":"./Template:!"},"params":{},"i":0}}]}'>|</span> is still a magic word here
| is not a magic word here but <span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"!","href":"./Template:!"},"params":{},"i":0}}]}'>|</span> is still a magic word here</p>

!! end

!! test
Say the magic word
!! options
title=[[Parser test]]
!! wikitext
* {{PAGENAME}}
* {{PAGENAMEE}}
* {{FULLPAGENAME}}
* {{FULLPAGENAMEE}}
* {{BASEPAGENAME}}
* {{BASEPAGENAMEE}}
* {{SUBPAGENAME}}
* {{SUBPAGENAMEE}}
* {{ROOTPAGENAME}}
* {{ROOTPAGENAMEE}}
* {{TALKPAGENAME}}
* {{TALKPAGENAMEE}}
* {{SUBJECTPAGENAME}}
* {{SUBJECTPAGENAMEE}}
* {{NAMESPACEE}}
* {{NAMESPACE}}
* {{NAMESPACENUMBER}}
* {{TALKSPACE}}
* {{TALKSPACEE}}
* {{SUBJECTSPACE}}
* {{SUBJECTSPACEE}}
* {{Dynamic|{{NUMBEROFUSERS}}|{{NUMBEROFPAGES}}|{{CURRENTVERSION}}|{{CONTENTLANGUAGE}}|{{DIRECTIONMARK}}|{{CURRENTTIMESTAMP}}|{{NUMBEROFARTICLES}}}}
!! html
<ul><li> Parser test</li>
<li> Parser_test</li>
<li> Parser test</li>
<li> Parser_test</li>
<li> Parser test</li>
<li> Parser_test</li>
<li> Parser test</li>
<li> Parser_test</li>
<li> Parser test</li>
<li> Parser_test</li>
<li> Talk:Parser test</li>
<li> Talk:Parser_test</li>
<li> Parser test</li>
<li> Parser_test</li>
<li> </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 with valid attributes
!! wikitext
<gallery type="123" summary="345">
File:File:Foobar.jpg
</gallery>
!! html/php
<ul class="gallery mw-gallery-traditional" type="123">
		<li class="gallerybox" style="width: 155px"><div style="width: 155px">
			<div class="thumb" style="height: 150px;">File:Foobar.jpg</div>
			<div class="gallerytext">
			</div>
		</div></li>
</ul>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" type="123" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{"type":"123","summary":"345"},"body":{"extsrc":"\nFile:File:Foobar.jpg\n"}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:File:Foobar.jpg</span></div><div class="gallerytext"></div></li>
</ul>
!! end

## Parsoid thinks the "centre" here is a property, not a caption.
!! test
Gallery
!! options
parsoid={
  "modes": ["wt2html"],
  "nativeGallery": true
}
!! wikitext
<gallery>
image1.png |
image2.gif|||||

image3|
image4    |300px| centre
 image5.svg| http://///////
[[x|xx]]]]
* image6
</gallery>
!! html/php
<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">
			</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">
<pre>centre
</pre>
			</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>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">image1.png </span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">image2.gif</span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">image3</span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">image4    </span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;"> image5.svg</span></div><div class="gallerytext"> <a rel="mw:ExtLink" href="http://///////">http://///////</a></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">* image6</span></div><div class="gallerytext"></div></li>
</ul>
!! end

!! test
Gallery (with options, html)
!! options
parsoid={
  "modes": ["wt2html", "html2html"],
  "nativeGallery": true
}
!! 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/php
<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.
</p>
			</div>
		</div></li>
</ul>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" style="max-width: 226px; _width: 226px;" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{"widths":"70px","heights":"40px","perrow":"2"},"body":{}}'>
<li class="gallerycaption">Foo <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext">caption</div></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext">some <b>caption</b> <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></div></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img alt="This is a foo-bar." resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext">blabla.</div></li>
</ul>
!! end

!! test
Gallery (with options, extsrc)
!! options
parsoid={
  "nativeGallery": false
}
!! 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/php
<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.
</p>
			</div>
		</div></li>
</ul>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" style="max-width: 226px; _width: 226px;" typeof="mw:Extension/gallery" about="#mwt3" data-parsoid='{}' data-mw='{"name":"gallery","attrs":{"widths":"70px","heights":"40px","perrow":"2","caption":"Foo [[Main Page]]"},"body":{"extsrc":"\nFile:Nonexistent.jpg|caption\nFile:Nonexistent.jpg\nimage:foobar.jpg|some &#39;&#39;&#39;caption&#39;&#39;&#39; [[Main Page]]\nimage:foobar.jpg\nimage:foobar.jpg|Blabla|alt=This is a foo-bar.|blabla.\n"}}'>
<li class="gallerycaption">Foo <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext">caption</div></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext">some <b>caption</b> <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></div></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 105px;"><div class="thumb" style="width: 100px; height: 70px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img alt="This is a foo-bar." resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/70px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="8" width="70"/></a></span></div><div class="gallerytext">blabla.</div></li>
</ul>
!! end

!! test
Gallery with link that has fragment
!! options
parsoid={
  "modes": ["wt2html", "html2html"],
  "nativeGallery": true
}
!! 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/php
<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>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./Main_Page"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./Main_Page#section"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./Main_Page#section"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext">caption</div></li>
</ul>
!! end

## Whoops, Parsoid shouldn't be parsing templates in the attribute caption!
!! test
Gallery with template inside caption
!! options
parsoid={
  "nativeGallery": true
}
!! wikitext
<gallery caption="{{echo|hi}}">
File:Foobar.jpg|{{echo|ho}}
</gallery>
!! html/php
<ul class="gallery mw-gallery-traditional">
	<li class='gallerycaption'>{{echo|hi}}</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>ho
</p>
			</div>
		</div></li>
</ul>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt6" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerycaption"><span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"hi"}},"i":0}}]}'>hi</span></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><span about="#mwt5" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"ho"}},"i":0}}]}'>ho</span></div></li>
</ul>
!! end

!! test
Gallery with wikitext inside caption
!! options
parsoid={
  "nativeGallery": true
}
!! wikitext
<gallery>
File:Foobar.jpg|alt=galleryalt|[[File:Foobar.jpg|alt=inneralt|20x20px|desc]]
File:Foobar.jpg|alt=galleryalt|{{Test|unamedParam|alt=param}}
</gallery>
!! html/php
<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>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt6" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><span typeof="mw:Image" data-mw='{"caption":"desc"}'><a href="./File:Foobar.jpg"><img alt="inneralt" 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></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><span about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Test","href":"./Template:Test"},"params":{"1":{"wt":"unamedParam"},"alt":{"wt":"param"}},"i":0}}]}'>This is a test template</span></div></li>
</ul>
!! end

!! test
Gallery (with showfilename option)
!! options
parsoid={
  "nativeGallery": true
}
!! wikitext
<gallery showfilename="">
File:Nonexistent.jpg|caption
File:Nonexistent.jpg
File:Foobar.jpg|some '''caption''' [[Main Page]]
File:Foobar.jpg
</gallery>
!! html/php
<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" class="galleryfilename galleryfilename-truncate" title="File:Nonexistent.jpg">Nonexistent.jpg</a>
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" class="galleryfilename galleryfilename-truncate" title="File:Nonexistent.jpg">Nonexistent.jpg</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="" 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="galleryfilename galleryfilename-truncate" title="File:Foobar.jpg">Foobar.jpg</a>
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" class="galleryfilename galleryfilename-truncate" title="File:Foobar.jpg">Foobar.jpg</a>
</p>
			</div>
		</div></li>
</ul>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt3" data-mw='{"name":"gallery","attrs":{"showfilename":""},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"><a href="./File:Nonexistent.jpg" class="galleryfilename galleryfilename-truncate" title="File:Nonexistent.jpg">File:Nonexistent.jpg</a>caption</div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"><a href="./File:Nonexistent.jpg" class="galleryfilename galleryfilename-truncate" title="File:Nonexistent.jpg">File:Nonexistent.jpg</a></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><a href="./File:Foobar.jpg" class="galleryfilename galleryfilename-truncate" title="File:Foobar.jpg">File:Foobar.jpg</a>some <b>caption</b> <a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"><a href="./File:Foobar.jpg" class="galleryfilename galleryfilename-truncate" title="File:Foobar.jpg">File:Foobar.jpg</a></div></li>
</ul>
!! end

## Should Parsoid be preserving these variations?
!! test
Gallery (with namespace-less filenames)
!! options
parsoid={
  "modes": ["wt2html", "html2html"],
  "nativeGallery": true
}
!! wikitext
<gallery>
File:Nonexistent.jpg
Nonexistent.jpg
image:foobar.jpg
foobar.jpg
</gallery>
!! html/php
<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>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Nonexistent.jpg</span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">Nonexistent.jpg</span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
</ul>
!! end

!! test
Gallery override link with WikiLink (T36852)
!! options
parsoid={
  "nativeGallery": true
}
!! wikitext
<gallery>
File:Foobar.jpg|alt=galleryalt|link=InterWikiLink
</gallery>
!! html/php
<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">
			</div>
		</div></li>
</ul>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-parsoid='{"dsr":[0,70,2,2]}' data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./InterWikiLink"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
</ul>
!! end

!! test
Gallery override link with absolute external link (T36852)
!! options
parsoid={
  "nativeGallery": true
}
!! wikitext
<gallery>
File:Foobar.jpg|alt=galleryalt|link=http://www.example.org
</gallery>
!! html/php
<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">
			</div>
		</div></li>
</ul>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="http://www.example.org"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
</ul>
!! end

!! test
Gallery override link with absolute external link with LanguageConverter
!! options
language=zh
!! input
<gallery>
File:foobar.jpg|caption|alt=galleryalt|link=http://www.example.org
</gallery>
!! result
<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 (T36852)
!! options
parsoid={
  "modes": ["wt2html", "html2html"],
  "nativeGallery": true
}
!! wikitext
<gallery>
File:Foobar.jpg|alt=galleryalt|link=" onclick="alert('malicious javascript code!');
</gallery>
!! html/php
<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">
			</div>
		</div></li>
</ul>

!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./%22_onclick=%22alert('malicious_javascript_code!');"><img alt="galleryalt" resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
</ul>
!! end

!! test
Gallery with invalid title as link (T45964)
!! options
parsoid={
  "modes": ["wt2html", "html2html"],
  "nativeGallery": true
}
!! wikitext
<gallery>
File:Foobar.jpg|link=<
</gallery>
!! html/php
<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/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext">link=&lt;</div></li>
</ul>
!! end

!! test
Serialize gallery without attrs in data-mw
!! options
parsoid={
  "modes": ["html2wt"],
  "nativeGallery": true
}
!! html/parsoid
<ul class="gallery mw-gallery-traditional" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","body":{}}'>
<li class="gallerycaption">123</li>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span style="vertical-align: middle; display: inline-block;">File:Test.png</span></div><div class="gallerytext"></div></li>
</ul>
!! wikitext
<gallery caption="123">
File:Test.png
</gallery>
!! end

!! test
Gallery with class and style attributes
!! options
parsoid={
  "nativeGallery": true
}
!! wikitext
<gallery class="center" style="text-align: center;">
File:Foobar.jpg
</gallery>
!! html/php
<ul class="gallery mw-gallery-traditional center" style="text-align: center;">
		<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/parsoid
<ul class="gallery mw-gallery-traditional center" style="text-align: center;" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{"class":"center","style":"text-align: center;"},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px; height: 150px;"><span style="display: inline-block; height: 100%; vertical-align: middle;"></span><span typeof="mw:Image" style="vertical-align: middle; display: inline-block;"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></div></li>
</ul>
!! end

!! test
Gallery in slideshow mode
!! options
parsoid={
  "nativeGallery": true
}
!! wikitext
<gallery mode="slideshow" showthumbnails="">
File:Foobar.jpg
</gallery>
!! html/php
<ul class="gallery mw-gallery-slideshow" data-showthumbnails="1">
		<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/parsoid
<ul class="gallery mw-gallery-slideshow" data-showthumbnails="1" typeof="mw:Extension/gallery" about="#mwt2" data-mw='{"name":"gallery","attrs":{"mode":"slideshow","showthumbnails":""},"body":{}}'>
<li class="gallerybox" style="width: 155px;"><div class="thumb" style="width: 150px;"><span typeof="mw:Image"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//example.com/images/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="14" width="120"/></a></span></div><div class="gallerytext"></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 (T28437 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: https://www.w3.org/TR/html5/syntax.html#character-references
# Note that U+000C (form feed) is not a valid XML character, so
# it is banned even though allowed in HTML5.
!! 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
T24905: <abbr> followed by ISBN followed by </a>
!! wikitext
<abbr>(fr)</abbr> ISBN 2753300917 [http://www.example.com example.com]
!! html/php
<p><abbr>(fr)</abbr> <a href="/wiki/Special:BookSources/2753300917" class="internal mw-magiclink-isbn">ISBN 2753300917</a> <a rel="nofollow" class="external text" href="http://www.example.com">example.com</a>
</p>
!! html/parsoid
<p><abbr data-parsoid='{"stx":"html"}'>(fr)</abbr> <a href="./Special:BookSources/2753300917" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 2753300917</a> <a rel="mw:ExtLink" href="http://www.example.com">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=%7Cleft%7C&amp;param2=%7Cx" data-parsoid='{"a":{"href":"http://test/?param1=%7Cleft%7C&amp;param2=%7Cx"},"sa":{"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

# This is wt2html only in Parsoid because we add <nowiki>
# because of {{..}} and we don't expect to fix that to
# eliminate the nowikis selective for {{..}} markup.
!! test
Non-transclusion because of too many up levels
!! options
subpage title=[[Subpage test/L1/L2/L3]]
parsoid=wt2html
!! wikitext
{{../../../../More than parent}}
!! html/php
<p>{{../../../../More than parent}}
</p>
!! html/parsoid
<p>{{../../../../More than parent}}</p>
!! end

!! test
Definition list code coverage
!! 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" class="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 (T9110)
!! 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: (T20431)
!! 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
T8200: blockquotes and paragraph formatting
!! wikitext
<blockquote>
foo
</blockquote>

bar

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

!! test
T10293: Use of center tag ruins paragraph formatting
!! wikitext
<center>
foo
</center>

bar

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

!!test
Parsing of overlapping (improperly nested) inline html tags
!! wikitext
<span><s>x</span></s>
!! html/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 <a class="mw-selflink selflink">Dunav</a> and <a class="mw-selflink selflink">Дунав</a> 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 <a class="mw-selflink selflink">Duna</a> and <a class="mw-selflink selflink">Dуна</a> 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><a class="mw-selflink selflink">Dуна</a> is a self-link while <a href="/wiki/%D0%94%D1%83%D0%BD%D0%B0" title="Дуна">Dunа#Foo</a> and <a href="/wiki/%D0%94%D1%83%D0%BD%D0%B0" title="Дуна">Dуна#Foo</a> are not self-links.
</p>
!! 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/php
cat=МедиаWики_Усер'с_Гуиде sort=
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Категорија:МедиаWики_Усер'с_Гуиде" data-parsoid='{"stx":"simple","a":{"href":"./Категорија:МедиаWики_Усер&#39;с_Гуиде"},"sa":{"href":"Category:МедиаWики Усер&#39;с Гуиде"}}'/>
!! end

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

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

## We used to, but no longer wt2wt this test since the default serializer
## will normalize all categories to serialize on their own line.
## This wikitext usage is going to be fairly uncommon in production and
## selser will take care of preserving formatting in those scenarios.
!! test
Don't convert blue categorylinks to another variant (T35210)
!! options
cat
language=zh
parsoid=wt2html
!! wikitext
[[A]][[Category:分类]]
!! html/php
cat=分类 sort=
!! html/parsoid
<p><a rel="mw:WikiLink" href="./A" title="A">A</a></p>
<link rel="mw:PageProp/Category" href="./Category:分类"/>
!! end

!! test
Stripping -{}- tags (language variants)
!! options
language=sr
!! wikitext
Latin proverb: -{Ne nuntium necare}-
!! html
<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
T26072: more test on conversion rule for title
!! options
language=zh variant=zh-tw showtitle
!! wikitext
This should be stripped-{T|zh:China;zh-tw:Taiwan}-!
This won't take interferes with the title rule-{H|zh:Beijing;zh-tw:Taipei}-.
!! html
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
HTML markups with conversion syntax in attribs, nested in other conversion blocks
!! options
language=zh variant=zh-cn
!! wikitext
-{zh;zh-hans;zh-hant|<span title="-{X}-">A</span>}-
!! html
<p><span title="X">A</span>
</p>
!! end

!! test
HTML markups with conversion syntax in attribs, nested in other conversion blocks (not working yet)
!! options
language=zh variant=zh-cn disabled
!! wikitext
-{<span title="-{X}-">A</span>}-
!! html
<p><span title="X">A</span>
</p>
!! end

# Since Parsoid is starting to emit canonical wikitext for links,
# [http://example.com http://example.com] will not RT back to that
# form anymore.
!! test
Proper conversion of text in external links
!! options
language=sr variant=sr-ec
parsoid=wt2html
!! wikitext
http://www.google.com
gopher://www.google.com
[http://www.google.com http://www.google.com]
[gopher://www.google.com gopher://www.google.com]
[https://www.google.com irc://www.google.com]
[ftp://www.google.com www.google.com/ftp://dir]
[//www.google.com www.google.com]
!! html/php
<p><a rel="nofollow" class="external free" href="http://www.google.com">http://www.google.com</a>
<a rel="nofollow" class="external free" href="gopher://www.google.com">gopher://www.google.com</a>
<a rel="nofollow" class="external 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>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://www.google.com">http://www.google.com</a>
<a rel="mw:ExtLink" href="gopher://www.google.com">gopher://www.google.com</a>
<a rel="mw:ExtLink" href="http://www.google.com">http://www.google.com</a>
<a rel="mw:ExtLink" href="gopher://www.google.com">gopher://www.google.com</a>
<a rel="mw:ExtLink" href="https://www.google.com">irc://www.google.com</a>
<a rel="mw:ExtLink" href="ftp://www.google.com">www.гоогле.цом/фтп://дир</a>
<a rel="mw:ExtLink" 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 T153761
!! test
T146304: Don't break template parsing if language converter markup is in the parameter.
!! options
language=sr variant=sr-ec
disabled
!! wikitext
{{echo|-{R|foo}-}}
!! html/php
<p>foo
</p>
!! end

!! test
T146305: Don't break image parsing if language converter markup is in the caption.
!! options
language=sr
!! wikitext
[[File:Foobar.jpg|thumb|-{R|caption:}-]]
!! html/php
<div class="thumb tright"><div class="thumbinner" style="width:182px;"><a href="/wiki/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0: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/%D0%94%D0%B0%D1%82%D0%BE%D1%82%D0%B5%D0%BA%D0%B0:Foobar.jpg" class="internal" title="Повећај"></a></div>caption:</div></div></div>

!! html/parsoid
<figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./Датотека:Foobar.jpg"><img resource="./Датотека: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><span typeof="mw:LanguageVariant" data-mw='{"disabled":true,"show":true,"text":"caption:"}'></span></figcaption></figure>
!! end

!! test
T146305: Don't break image parsing if nested language converter markup is in the caption.
!! options
language=zh variant=zh-cn
!! wikitext
[[File:Foobar.jpg|thumb|-{zh-cn:blog (hk: -{zh-hans|WEBJOURNAL}-, tw: -{zh-hans|WEBLOG}-)}-]]
!! 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="放大"></a></div>blog (hk: WEBJOURNAL, tw: WEBLOG)</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><span typeof="mw:LanguageVariant" data-mw='{"bidir":[{"l":"zh-cn","t":"blog (hk: &lt;span typeof=\"mw:LanguageVariant\" data-parsoid=&#39;{\"fl\":[\"zh-hans\"],\"dsr\":[42,64,null,2]}&#39; data-mw=&#39;{\"filter\":[\"zh-hans\"],\"text\":\"WEBJOURNAL\"}&#39;>&lt;/span>, tw: &lt;span typeof=\"mw:LanguageVariant\" data-parsoid=&#39;{\"fl\":[\"zh-hans\"],\"dsr\":[70,88,null,2]}&#39; data-mw=&#39;{\"filter\":[\"zh-hans\"],\"text\":\"WEBLOG\"}&#39;>&lt;/span>)"}],"show":true}'></span></figcaption></figure>
!! end

!! test
Don't break gallery if language converter markup is inside.
!! options
language=zh
!! wikitext
<gallery>
File:foobar.jpg|[[File:foobar.jpg|20px|desc|alt=-{R|foo}-|-{R|bar}-]]|alt=-{R|bat}-
File:foobar.jpg|{{Test|unamedParam|alt=-{R|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="bat" 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="bar"><img alt="foo" 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
T153135: Don't break list handling if language converter markup is in the item.
!! options
language=zh variant=zh-cn
!! wikitext
;-{zh-cn:AAA;zh-tw:BBB}-
;-{R|foo:bar}-
!! html/php
<dl><dt>AAA</dt>
<dt>foo:bar</dt></dl>

!! html/parsoid
<dl>
<dt><span typeof="mw:LanguageVariant" data-mw='{"bidir":[{"l":"zh-cn","t":"AAA"},{"l":"zh-tw","t":"BBB"}],"show":true}'></span></dt>
<dt><span typeof="mw:LanguageVariant" data-mw='{"disabled":true,"show":true,"text":"foo:bar"}'></span></dt>
</dl>
!! end

// Note that parsoid does not protect colons unless language converter
// markup is properly nested, because it is a backtracking parser.
!! test
T153135: Unclosed markup in definition list (code coverage)
!! options
language=zh variant=zh-cn
!! wikitext
;<b>foo:bar
;-{zh-cn:AAA
!! html/php
<dl><dt><b>foo:bar</dt>
<dt>-{zh-cn:AAA</b></dt></dl>

!! html/parsoid
<dl>
<dt><b>foo:bar</b></dt>
<b>
<dt>-{zh-cn</dt>
<dd>AAA</dd>
</b></dl>
!! end

!! test
T153135: Nested language converter markup in definition list (code coverage)
!! options
language=zh variant=zh-cn
!! wikitext
;-{zh-cn:AAA -{zh-hans|foo:bar}- -{R|bat:baz}-}-:def
!! html/php
<dl><dt>AAA foo:bar bat:baz</dt>
<dd>def</dd></dl>

!! html/parsoid
<dl>
<dt><span typeof="mw:LanguageVariant" data-mw='{"bidir":[{"l":"zh-cn","t":"AAA &lt;span typeof=\"mw:LanguageVariant\" data-parsoid=&#39;{\"fl\":[\"zh-hans\"],\"dsr\":[13,32,null,2]}&#39; data-mw=&#39;{\"filter\":[\"zh-hans\"],\"text\":\"bar\"}&#39;>&lt;/span> &lt;span typeof=\"mw:LanguageVariant\" data-parsoid=&#39;{\"fl\":[\"R\"],\"dsr\":[33,46,null,2]}&#39; data-mw=&#39;{\"disabled\":true,\"show\":true,\"text\":\"bat:baz\"}&#39;>&lt;/span>"}],"show":true}'></span></dt>
<dd>def</dd>
</dl>
!! end

!! test
T153140: 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> B
</td></tr></table>

!! html/parsoid
<table>

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

!! end

!! test
T2529: 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
T2529: 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
T2529: 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
T2529: Uncovered bullet in parser function result
!! wikitext
* Foo {{lc:{{bullet}} }}
!! html
<ul><li> Foo </li>
<li> bar</li></ul>

!! end

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

!! test
T7678: Double-parsed template invocation
!! wikitext
{{lc:{{paramtest {{!}} param = hello }} }}
!! html
<p>{{paramtest | param = hello }}
</p>
!! end

!! test
Case insensitivity of parser functions for non-ASCII characters (T10143)
!! options
language=cs
title=[[Main Page]]
!! wikitext
{{PRVNÍVELKÉ:ěščř}}
{{prvnívelké:ěščř}}
{{PRVNÍMALÉ:ěščř}}
{{prvnímalé:ěščř}}
{{MALÁ:ěščř}}
{{malá:ěščř}}
{{VELKÁ:ěščř}}
{{velká:ěščř}}
!! html
<p>Ěščř
Ěščř
ěščř
ěščř
ěščř
ěščř
ĚŠČŘ
ĚŠČŘ
</p>
!! end

!! test
Morwen/13: Unclosed link followed by heading
!! wikitext
[[link
==heading==
!! html
<p>[[link
</p>
<h2><span class="mw-headline" id="heading">heading</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: heading">edit</a><span class="mw-editsection-bracket">]</span></span></h2>

!! end

!! test
HHP2.1: Heuristics for headings in preprocessor parenthetical structures
!! wikitext
{{foo|
=heading=
!! html
<p>{{foo|
</p>
<h1><span class="mw-headline" id="heading">heading</span></h1>

!! end

!! test
HHP2.2: Heuristics for headings in preprocessor parenthetical structures
!! wikitext
{{foo|
==heading==
!! html
<p>{{foo|
</p>
<h2><span class="mw-headline" id="heading">heading</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: heading">edit</a><span class="mw-editsection-bracket">]</span></span></h2>

!! end

!! test
Tildes in comments
!! options
pst
!! wikitext
<!-- ~~~~ -->
!! html/php
<!-- ~~~~ -->
!! end

!! test
Paragraphs inside divs (no extra line breaks)
!! wikitext
<div>Line one

Line two</div>
!! html
<div>Line one
Line two</div>

!! end

!! test
Paragraphs inside divs (extra line break on open)
!! wikitext
<div>
Line one

Line two</div>
!! html
<div>
<p>Line one
</p>
Line two</div>

!! end

!! test
Paragraphs inside divs (extra line break on close)
!! wikitext
<div>Line one

Line two
</div>
!! html
<div>Line one
<p>Line two
</p>
</div>

!! end

!! test
Paragraphs inside divs (extra line break on open and close)
!! wikitext
<div>
Line one

Line two
</div>
!! html
<div>
<p>Line one
</p><p>Line two
</p>
</div>

!! end

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

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

Line two</blockquote>
!! html
<blockquote>Line one
Line two</blockquote>

!! html+tidy
<blockquote>
<p>Line one Line two</p>
</blockquote>
!! end

!! test
T8200: paragraphs inside blockquotes (extra line break on open)
!! wikitext
<blockquote>
Line one

Line two</blockquote>
!! html
<blockquote>
<p>Line one
</p>
Line two</blockquote>

!! html+tidy
<blockquote>
<p>Line one</p>
Line two</blockquote>
!! end

!! test
T8200: 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
T8200: paragraphs inside blockquotes (extra line break on open and close)
!! wikitext
<blockquote>
Line one

Line two
</blockquote>
!! html
<blockquote>
<p>Line one
</p><p>Line two
</p>
</blockquote>

!! 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
T17196: localised external link numbers
!! options
language=fa
!! wikitext
[http://en.wikipedia.org/]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://en.wikipedia.org/">[۱]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://en.wikipedia.org/"></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/php
I like the <a href="/wiki/Main_Page" title="Main Page">Main Page</a> a lot
!!end

!! test
Edit comment with link and link text
!! options
comment
!! wikitext
I like the [[Main Page|best pages]] a lot
!! html/php
I like the <a href="/wiki/Main_Page" title="Main Page">best pages</a> a lot
!!end

!! test
Edit comment with link and link text with suffix
!! options
comment
!! wikitext
I like the [[Main Page|best page]]s a lot
!! html/php
I like the <a href="/wiki/Main_Page" title="Main Page">best pages</a> a lot
!!end

!! test
Edit comment with section link (non-local, eg in history list)
!! options
comment title=[[Main Page]]
!! wikitext
/* External links */ removed bogus entries
!! html/php
<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/php
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/php
<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 (T16080)
!! options
comment
subpage
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage]] here...
!! html/php
Poked at a <a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">/subpage</a> here...
!!end

!! test
Edit comment with subpage link and link text (T16080)
!! options
comment
subpage
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage|neat little page]] here...
!! html/php
Poked at a <a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">neat little page</a> here...
!!end

!! test
Edit comment with bogus subpage link in non-subpage NS (T16080)
!! options
comment
title=[[Subpage test]]
!! wikitext
Poked at a [[/subpage]] here...
!! html/php
Poked at a <a href="/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> here...
!!end

!! test
Edit comment with bare anchor link (local, as on diff)
!! options
comment
local
title=[[Main Page]]
!! wikitext
[[#section]]
!! html/php
<a href="#section">#section</a>
!! end

!! test
Edit comment with bare anchor link (non-local, as on history)
!! options
comment
title=[[Main Page]]
!! wikitext
[[#section]]
!! html/php
<a href="/wiki/Main_Page#section" title="Main Page">#section</a>
!! end

!! test
Anchor starting with underscore
!! options
title=[[Foo]]
!! wikitext
[[#_ref|One]]
!! html/php
<p><a href="#_ref">One</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo#_ref" data-parsoid='{"stx":"piped","a":{"href":"./Foo#_ref"},"sa":{"href":"#_ref"}}'>One</a></p>
!! end

!! test
Id starting with underscore
!! wikitext
<div id="_ref"></div>
!! html/*
<div id="_ref"></div>

!! end

!! test
Edit comment with link with more than one pipe (T99346)
!! options
comment
!! wikitext
[[Main Page|Many|pipes]]
!! html/php
<a href="/wiki/Main_Page" title="Main Page">Many|pipes</a>
!! end

!! test
Complex edit comment with link with more than one pipe (T99346)
!! options
comment
!! wikitext
Created page with "<noinclude>[[Category:Requests for permissions/Bot|{{subst:#titleparts:{{subst:PAGENAME}}|1|3}}]]</noinclude> === [[User:MineoBot|]] 8=== {{Request for permissions/links|Mineo..."
!! html/php
Created page with &quot;&lt;noinclude&gt;<a href="/index.php?title=Category:Requests_for_permissions/Bot&amp;action=edit&amp;redlink=1" class="new" title="Category:Requests for permissions/Bot (page does not exist)">{{subst:#titleparts:{{subst:PAGENAME}}|1|3}}</a>&lt;/noinclude&gt; === <a href="/index.php?title=User:MineoBot&amp;action=edit&amp;redlink=1" class="new" title="User:MineoBot (page does not exist)">User:MineoBot</a> 8=== {{Request for permissions/links|Mineo...&quot;
!! end

!! test
Space normalisation on autocomment (T24784)
!! options
comment
title=[[Main Page]]
!! wikitext
/* __hello__world__ */
!! html/php
<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 (T28410)
!! options
comment
!! wikitext
[[ABC%33D% ++]] [[ABC%33D% ++|+%20]]
!! html/php
<a href="/index.php?title=ABC3D%25_%2B%2B&amp;action=edit&amp;redlink=1" class="new" title="ABC3D% ++ (page does not exist)">ABC3D% ++</a> <a href="/index.php?title=ABC3D%25_%2B%2B&amp;action=edit&amp;redlink=1" class="new" title="ABC3D% ++ (page does not exist)">+%20</a>
!! end

# Parsoid doesn't support this yet: see T75581
# but it *should* omit the 'src' attribute if the image is bad.
# PHP side of tests was disabled in
# mediawiki/core:6bd31e7d95161a6e88fa86df60871051da997c3c
# because of issues in the PHP parserTests infrastructure
# (but the output below is indeed what the PHP side emits)
!! test
Bad images - basic functionality
!! wikitext
[[File:Bad.jpg]]
!! 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 - T18039: 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 (T24501) 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 (T24501) 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 (T24501) 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 (T24501) 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 (T24501) 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 (T24501) 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 (T28547) - 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 (T28547) - 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/php
<p><span class="error"><strong>Error:</strong> Page status indicators' <code>name</code> attribute must not be empty.</span>
<span class="error"><strong>Error:</strong> Page status indicators' <code>name</code> attribute must not be empty.</span>
</p>
!! end

!! test
Page status indicators: Weird syntaxes that are okay
!! options
showindicators
!! wikitext
<indicator name="empty" />
<indicator name="name"></indicator>
!! html/php
empty=
name=
<p><br />
</p>
!! end

!! test
Page status indicators: Torture test
!! options
showindicators
!! wikitext
<indicator name="01">hello world</indicator>
<indicator name="02">[[Main Page]]</indicator>
<indicator name="03">[[File:Foobar.jpg|25px|link=]]</indicator>
<indicator name="04">[[File:Foobar.jpg|25px]]</indicator>
<indicator name="05">* foo
* bar</indicator>
<indicator name="06"><nowiki>foo</nowiki></indicator>
<indicator name="07"> Preformatted</indicator>
<indicator name="08"><div>Broken tag</indicator>
<indicator name="09">{| class=wikitable
| cell
|}</indicator>
<indicator name="10">Two

paragraphs</indicator>
!! html/php
01=hello world
02=<a href="/wiki/Main_Page" title="Main Page">Main Page</a>
03=<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 T5158
!! wikitext
<div style="width:50% !important">&nbsp;</div>
<div style="width:50%&nbsp;!important">&nbsp;</div>
<div style="width:50%&#160;!important">&nbsp;</div>
<div style="border : solid;">&nbsp;</div>
!! html/php
<div style="width:50% !important">&#160;</div>
<div style="width:50% !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/php
<p><span data-foo="bar">Baz</span>
</p>
<p data-abc-def_hij="">Quuz</p>

!! html/parsoid
<p><span data-foo="bar" data-parsoid='{"stx":"html"}'>Baz</span></p>
<p data-abc-def_hij="" data-parsoid='{"stx":"html"}'>Quuz</p>
!! end

!! test
Strip reserved data attributes
!! wikitext
<div data-mw="foo" data-parsoid="bar" data-mw-someext="baz" data-ok="fred" data-ooui="xyzzy" data-bad:ns="ns">d</div>
!! html/php
<div data-ok="fred">d</div>

!! html/parsoid
<div data-x-data-mw="foo" data-x-data-parsoid="bar" data-x-data-mw-someext="baz" data-ok="fred" data-parsoid='{"stx":"html","a":{"data-ooui":null,"data-bad:ns":null},"sa":{"data-ooui":"xyzzy","data-bad:ns":"ns"}}'>d</div>
!! end

!! test
percent-encoding and + signs in internal links (T28410)
!! 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:+%" data-parsoid='{"stx":"simple","a":{"href":"./User:+%25"},"sa":{"href":"User:+%"}}'>User:+%</a> <a rel="mw:WikiLink" href="./Page+title%25" title="Page+title%" data-parsoid='{"stx":"simple","a":{"href":"./Page+title%25"},"sa":{"href":"Page+title%"}}'>Page+title%</a>
<a rel="mw:WikiLink" href="./%25+" title="%+" data-parsoid='{"stx":"simple","a":{"href":"./%25+"},"sa":{"href":"%+"}}'>%+</a> <a rel="mw:WikiLink" href="./%25+" title="%+" data-parsoid='{"stx":"piped","a":{"href":"./%25+"},"sa":{"href":"%+"}}'>%20</a> <a rel="mw:WikiLink" href="./%25+" title="%+" data-parsoid='{"stx":"simple","a":{"href":"./%25+"},"sa":{"href":"%+ "}}'>%+ </a> <a rel="mw:WikiLink" href="./%25+r" title="%+r" data-parsoid='{"stx":"simple","a":{"href":"./%25+r"},"sa":{"href":"%+r"}}'>%+r</a>
<a rel="mw:WikiLink" href="./%25" title="%" data-parsoid='{"stx":"simple","a":{"href":"./%25"},"sa":{"href":"%"}}'>%</a> <a rel="mw:WikiLink" href="./+" title="+" data-parsoid='{"stx":"simple","a":{"href":"./+"},"sa":{"href":"+"}}'>+</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=&#39;{\"stx\":\"simple\",\"a\":{\"href\":\"./Bar\"},\"sa\":{\"href\":\"bar\"},\"dsr\":[94,101,2,2]}&#39;>bar&lt;/a>"}'><a href="./File:%25+abc9" data-parsoid='{"a":{"href":"./File:%25+abc9"},"sa":{}}'><img resource="./File:%25+abc9" src="./Special:FilePath/%25+abc9" height="220" width="220" data-parsoid='{"a":{"resource":"./File:%25+abc9","height":"220","width":"220"},"sa":{"resource":"File:%+abc%39"}}'/></a></span>
<a rel="mw:WikiLink" href="./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 (T29679)
!! 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
T21052 U+3000 IDEOGRAPHIC SPACE should terminate free external links
!! wikitext
http://www.example.org/　<-- U+3000 (vim: ^Vu3000)
!! html
<p><a rel="nofollow" class="external free" href="http://www.example.org/">http://www.example.org/</a>　&lt;-- U+3000 (vim: ^Vu3000)
</p>
!! end

!! test
T21052 U+3000 IDEOGRAPHIC SPACE should terminate bracketed external links
!! wikitext
[http://www.example.org/　ideograms]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.org/">ideograms</a>
</p>
!! end

!! test
T21052 U+3000 IDEOGRAPHIC SPACE should terminate external images links
!! wikitext
http://www.example.org/pic.png　<-- U+3000 (vim: ^Vu3000)
!! html
<p><img src="http://www.example.org/pic.png" alt="pic.png"/>　&lt;-- U+3000 (vim: ^Vu3000)
</p>
!! end

!! article
Mediawiki:loop1
!! text
{{Identical|A}}
!! endarticle

!! article
Mediawiki:loop2
!! text
{{Identical|B}}
!! endarticle

!! article
Template:Identical
!! text
{{int:loop1}}
{{int:loop2}}
!! endarticle

!! test
T33098 Template which includes system messages which includes the template
!! wikitext
{{Identical}}
!! html
<p><span class="error">Template loop detected: <a href="/wiki/Template:Identical" title="Template:Identical">Template:Identical</a></span>
<span class="error">Template loop detected: <a href="/wiki/Template:Identical" title="Template:Identical">Template:Identical</a></span>
</p>
!! end

!! test
T33490 Turkish: ucfirst 'blah'
!! options
language=tr
!! wikitext
{{ucfirst:blah}}
!! html
<p>Blah
</p>
!! end

!! test
T33490 Turkish: ucfirst 'ix'
!! options
language=tr
!! wikitext
{{ucfirst:ix}}
!! html
<p>İx
</p>
!! end

!! test
T33490 Turkish: lcfirst 'BLAH'
!! options
language=tr
!! wikitext
{{lcfirst:BLAH}}
!! html
<p>bLAH
</p>
!! end

!! test
T33490 Turkish: ucfırst (with a dotless i)
!! options
language=tr
!! wikitext
{{ucfırst:blah}}
!! html
<p><a href="/index.php?title=%C5%9Eablon:Ucf%C4%B1rst:blah&amp;action=edit&amp;redlink=1" class="new" title="Şablon:Ucfırst:blah (sayfa mevcut değil)">Şablon:Ucfırst:blah</a>
</p>
!! end

!! test
T33490 ucfırst (with a dotless i) with English language
!! options
language=en
!! wikitext
{{ucfırst:blah}}
!! html
<p><a href="/index.php?title=Template:Ucf%C4%B1rst:blah&amp;action=edit&amp;redlink=1" class="new" title="Template:Ucfırst:blah (page does not exist)">Template:Ucfırst:blah</a>
</p>
!! end

!! test
T28375: TOC with italics
!! options
title=[[Main Page]]
!! wikitext
__TOC__
== ''Lost'' episodes ==
!! html
<div id="toc" class="toc"><div id="toctitle" class="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
T28375: TOC with bold
!! options
title=[[Main Page]]
!! wikitext
__TOC__
== '''should be bold''' then normal text ==
!! html
<div id="toc" class="toc"><div id="toctitle" class="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
T35845: 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" class="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
T35845 (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" class="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" class="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" class="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" class="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" class="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" class="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" class="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
T74884: bdi element in ToC
!! wikitext
__TOC__
== <bdi>test</bdi> ==
!! html
<div id="toc" class="toc"><div id="toctitle" class="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

!! test
T35715: s/strike element in ToC
!! wikitext
__TOC__
== <s>test</s> test <strike>test</strike> ==
!! html
<div id="toc" class="toc"><div id="toctitle" class="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#test_test_test"><span class="tocnumber">1</span> <span class="toctext"><s>test</s> test <strike>test</strike></span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id="test_test_test"><s>test</s> test <strike>test</strike></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: test test test">edit</a><span class="mw-editsection-bracket">]</span></span></h2>

!! 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" class="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" class="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:T34057
!! text
== {{int:headline_sample}} ==
!! endarticle

!! test
T34057: Title needed when expanding <h> nodes.
!! options
title=[[Main Page]]
!! wikitext
{{int:T34057}}
!! 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/php
<p>xy
xy
xy
xy
</p>
!! end

!! test
Strip marker in lc
!! wikitext
{{lc:x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
Strip marker in uc
!! wikitext
{{uc:x<nowiki/>y}}
!! html
<p>XY
</p>
!! end

!! test
Strip marker in formatNum
!! wikitext
{{formatnum:1<nowiki/>2}}
{{formatnum:1<nowiki/>2|R}}
!! html
<p>12
12
</p>
!! end

!! test
Check noCommafy in formatNum
!! options
language=be-tarask
!! wikitext
{{formatnum:123456.78}}
{{formatnum:123456.78|NOSEP}}
!! html
<p>123 456,78
123456.78
</p>
!! end

!! test
Wrong option for formatNum (T58199)
!! wikitext
{{formatnum:1,234.56|Random}}
{{formatnum:1,234.56|EVERYTHING}}
{{formatnum:1234.56|any argument that has the string 'NOSEP'}}
!! html
<p>1,234.56
1,234.56
1,234.56
</p>
!! end

!! test
Strip marker in grammar
!! options
language=fi
!! wikitext
{{grammar:elative|foo<nowiki/>bar}}
!! html
<p>foobarista
</p>
!! end

!! test
Strip marker in padleft
!! wikitext
{{padleft:|2|x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
Strip marker in padright
!! wikitext
{{padright:|2|x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
Strip marker in anchorencode
!! wikitext
{{anchorencode:x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
nowiki inside link inside heading (T20295)
!! wikitext
==[[foo|x<nowiki>y</nowiki>z]]==
!! html
<h2><span class="mw-headline" id="xyz"><a href="/wiki/Foo" title="Foo">xyz</a></span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: xyz">edit</a><span class="mw-editsection-bracket">]</span></span></h2>

!! end

!! test
new support for bdi element (T33817)
!! wikitext
<p dir="rtl" lang="he">ולדימיר לנין (ברוסית: <bdi lang="ru">Владимир Ленин</bdi>, 24 באפריל 1870–22 בינואר 1924) הוא מנהיג פוליטי קומוניסטי רוסי.</p>
!! html
<p dir="rtl" lang="he">ולדימיר לנין (ברוסית: <bdi lang="ru">Владимир Ленин</bdi>, 24 באפריל 1870–22 בינואר 1924) הוא מנהיג פוליטי קומוניסטי רוסי.</p>

!!end

!! test
Ignore pipe between table row attributes
!! wikitext
{|
| quux
|- id=foo | style='color: red'
| bar
|}
!! html
<table>
<tr>
<td> quux
</td></tr>
<tr id="foo" style="color: red">
<td> bar
</td></tr></table>

!! 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
T36939 - Case insensitive link parsing ([HttP://])
!! wikitext
[HttP://MediaWiki.Org/]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="HttP://MediaWiki.Org/">[1]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="HttP://MediaWiki.Org/"></a></p>
!! end

!!test
T36939 - Case insensitive link parsing ([HttP:// title])
!! wikitext
[HttP://MediaWiki.Org/ MediaWiki]
!! html
<p><a rel="nofollow" class="external text" href="HttP://MediaWiki.Org/">MediaWiki</a>
</p>
!! end

!!test
T36939 - Case insensitive link parsing (HttP://)
!! wikitext
HttP://MediaWiki.Org/
!! html/php
<p><a rel="nofollow" class="external free" href="HttP://MediaWiki.Org/">HttP://MediaWiki.Org/</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="HttP://MediaWiki.Org/">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
#### -----------------------------------------------------------------

# T65642/T68749: 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 LST
#### Not implemented yet, see
#### https://www.mediawiki.org/wiki/Parsoid/HTML_based_LST
#### ----------------------------------------------------------------

## We still need to support serializing the older format while content is stored.
!! test
LST Sections: Backwards compatibility
!! options
parsoid={
  "suppressErrors": true,
  "modes": ["html2wt"]
}
!! wikitext
<section begin="2011-05-16" />
<section end="2014-04-10 (MW 1.23wmf22)" />
!! html/parsoid
<p><meta typeof="mw:Extension/LabeledSectionTransclusion/begin" content="2011-05-16"/>
<meta typeof="mw:Extension/LabeledSectionTransclusion/end" content="2014-04-10 (MW 1.23wmf22)"/></p>
!! end

## The unconventional output is the result of `usePHPPreProcessor` being
## disabled in parserTests.js.  This test is mainly just to show <section> is
## recognized as an extension tag w/o a native handler.
!! test
LST Sections: Newfangled approach
!! wikitext
<section begin="2011-05-16" />
<section end="2014-04-10 (MW 1.23wmf22)" />
!! html/parsoid
<p><span typeof="mw:Error mw:Extension/section" about="#mwt1" data-mw='{"name":"section","attrs":{"begin":"2011-05-16"},"body":null,"errors":[{"key":"mw-api-extexpand-error","message":"Could not expand extension source."}]}'>&lt;section begin="2011-05-16" /></span>
<span typeof="mw:Error mw:Extension/section" about="#mwt2" data-mw='{"name":"section","attrs":{"end":"2014-04-10 (MW 1.23wmf22)"},"body":null,"errors":[{"key":"mw-api-extexpand-error","message":"Could not expand extension source."}]}'>&lt;section end="2014-04-10 (MW 1.23wmf22)" /></span></p>
!! end

#--------- Test stripping of empty nodes in template content ----------
!!test
Empty LI and TR nodes should be stripped from template content
!!wikitext
{{EmptyLITest}}
{{EmptyTRTest}}
!!html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"EmptyLITest","href":"./Template:EmptyLITest"},"params":{},"i":0}}]}'>
<li>a</li>
<li>b</li>
</ul>
<table about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"EmptyTRTest","href":"./Template:EmptyTRTest"},"params":{},"i":0}}]}'>
<tbody>
<tr>
<td>foo</td>
</tr>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!!end

!!test
Empty LI and TR nodes should not be stripped from top-level content
!!wikitext
* a
*
* b
{|
|-
|-
|foo
|}
!!html/parsoid
<ul>
<li> a</li>
<li></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'''foo= =
!!end

!! test
Headings: 4a. No escaping needed (testing just h1 and h2)
!! options
parsoid=html2wt
!! html/parsoid
<h1>=foo</h1>
<h1>foo=</h1>
<h1> =foo= </h1>
<h1>=foo= bar</h1>
<h2>=foo</h2>
<h2>foo=</h2>
<h1>=</h1>
<h1><i>=</i>foo=</h1>
!! wikitext
= =foo =

= foo= =

= =foo= =

= =foo= bar =

== =foo ==

== foo= ==

= = =

= ''=''foo= =
!!end

!! test
Headings: 4b. No escaping needed (inside p-tags)
!! options
parsoid=html2wt
!! html/parsoid
<p>===
=foo= x
=foo= <s></s>
</p>
!! wikitext
===
=foo= x
=foo= <s></s>
!!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

## Making these next 3 tests Parsoid-only since they are html2wt tests
## to test wikitext escaping, and insignificant whitespace diffs
## cause PHP parser tests to barf
!! test
Lists: 1. Nested inside html (No unnecessary escapes)
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>*foo</li>
<li>#foo</li>
<li>:foo</li>
<li>;foo</li>
<li data-parsoid='{}'>*foo</li>
<li data-parsoid='{}'>#foo</li>
<li data-parsoid='{}'>:foo</li>
<li data-parsoid='{}'>;foo</li>
</ul>

<ol>
<li>*foo</li>
<li>#foo</li>
<li>:foo</li>
<li>;foo</li>
<li data-parsoid='{}'>*foo</li>
<li data-parsoid='{}'>#foo</li>
<li data-parsoid='{}'>:foo</li>
<li data-parsoid='{}'>;foo</li>
</ol>
!! wikitext
* *foo
* #foo
* :foo
* ;foo
*<nowiki>*foo</nowiki>
*<nowiki>#foo</nowiki>
*<nowiki>:foo</nowiki>
*<nowiki>;foo</nowiki>

# *foo
# #foo
# :foo
# ;foo
#<nowiki>*foo</nowiki>
#<nowiki>#foo</nowiki>
#<nowiki>:foo</nowiki>
#<nowiki>;foo</nowiki>
!!end

!! test
Lists: 2. Inside definition lists
!! options
parsoid=html2wt
!! html/parsoid
<dl><dt>;foo</dt></dl>
<dl><dt>:foo</dt></dl>
<dl><dt>:foo</dt>
<dd>bar</dd></dl>
<dl><dd>:foo</dd></dl>
!! wikitext
; ;foo

; <nowiki>:foo</nowiki>

; <nowiki>:foo</nowiki>
: bar

: :foo
!!end

!! test
Lists: 3. Only bullets at start of text in wikitext-generated HTML should be escaped
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>*foo*bar</li>
<li data-parsoid='{}'>*foo<i>it</i>*bar</li>
</ul>
!! wikitext
* *foo*bar
*<nowiki>*foo</nowiki>''it''*bar
!!end

!! test
Lists: 4. No escapes needed
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>foo*bar
</li>
</ul>
<ul>
<li><i>foo</i>*bar
</li>
</ul>
<ul>
<li><a rel="mw:WikiLink" href="Foo" title="Foo">Foo</a>: bar
</li>
</ul>
<ul>
<li><a rel="mw:WikiLink" href="Foo" title="Foo">Foo</a>*bar
</li>
</ul>
!! wikitext
*foo*bar

*''foo''*bar

*[[Foo]]: bar

*[[Foo]]*bar
!!end

!! test
Lists: 5. No unnecessary escapes
!! options
parsoid=html2wt
!! html/parsoid
<ul><li> bar <span>[[foo]]</span></li></ul>
<ul><li> =bar <span>[[foo]]</span></li></ul>
<ul><li> [[bar <span>[[foo]]</span></li></ul>
<ul><li> ]]bar <span>[[foo]]</span></li></ul>
<ul><li> =bar <span>foo]]</span>=</li></ul>
<ul><li> <s></s>: a</li></ul>
<ul><li> <i>* foo</i></li></ul>

!! wikitext
* bar <span><nowiki>[[foo]]</nowiki></span>

* =bar <span><nowiki>[[foo]]</nowiki></span>

* [[bar <span><nowiki>[[foo]]</nowiki></span>

* ]]bar <span><nowiki>[[foo]]</nowiki></span>

* =bar <span>foo]]</span>=

* <s></s>: a

* ''* foo''
!!end

!! test
Lists: 6. Escape bullets in SOL position
!! options
parsoid=html2wt
!! html/parsoid
<p><!--cmt-->*foo</p>
!! wikitext
<!--cmt--><nowiki>*</nowiki>foo
!!end

!! test
Lists: 7. Escape bullets in a multi-line context
!! options
parsoid=html2wt
!! html/parsoid
<p>a
*b
</p>
!! wikitext
a
<nowiki>*</nowiki>b
!!end

!! test
Lists: 8. Escape colons only if not present in tags
!! options
parsoid=html2wt
!! html/parsoid
<dl><dt>a:b<i>c:d</i></dt></dl>
!! wikitext
; <nowiki>a:b</nowiki>''c:d''
!! end

#### --------------- HRs ---------------
#### 1. Single line
#### -----------------------------------

!! test
HRs: 1. Single line
!! options
parsoid=html2wt
!! html/parsoid
<hr />----
<hr />=foo=
<hr />*foo
!! wikitext
----<nowiki>----</nowiki>
----=foo=
----*foo
!! end

#### --------------- Tables ---------------
#### 1a. Simple example
#### 1b. No escaping needed (!foo)
#### 1c. No escaping needed (|foo)
#### 1d. No escaping needed (|}foo)
####
#### 2a. Nested in td (<td>foo|bar</td>)
#### 2b. Nested in td (<td>foo||bar</td>)
#### 2c. Nested in td -- no escaping needed(<td>foo!!bar</td>)
####
#### 3a. Nested in th (<th>foo!bar</th>)
#### 3b. Nested in th (<th>foo!!bar</th>)
#### 3c. Nested in th -- no escaping needed(<th>foo||bar</th>)
####
#### 4a. Escape -
#### 4b. Escape +
#### 4c. No escaping needed
#### --------------------------------------

!! test
Tables: 1a. Simple example
!! options
parsoid=html2wt
!! html/parsoid
<p>{|
|}
</p>
!! wikitext
<nowiki>{|</nowiki>
|}
!! end

!! test
Tables: 1b. No escaping needed
!! options
parsoid=html2wt
!! html/parsoid
<p>!foo
</p>
!! wikitext
!foo
!! end

!! test
Tables: 1c. No escaping needed
!! options
parsoid=html2wt
!! html/parsoid
<p>|foo
</p>
!! wikitext
|foo
!! end

!! test
Tables: 1d. No escaping needed
!! options
parsoid=html2wt
!! html/parsoid
<p>|}foo
</p>
!! wikitext
|}foo
!! end

!! test
Tables: 2a. Nested in td
!! options
parsoid=html2wt
!! html/parsoid
<table><tbody><tr>
<td>foo|bar</td></tr>
<tr><td>x<div>a|b</div></td>
</tbody></table>
!! wikitext
{|
|<nowiki>foo|bar</nowiki>
|-
|x<div><nowiki>a|b</nowiki></div>
|}
!! html/php+tidy
<table>
<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>
<a rel="mw:ExtLink" href="http://google.com">goog] le</a></p>
<p>[http://google.com]</p>
<p>[http://google.com google]</p>
<p>[<a rel="mw:ExtLink" href="http://google.com">http://google.com</a>]</p>
<p>[<a rel="mw:ExtLink" href="http://google.com" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"http://google.com"}},"i":0}}]}'>http://google.com</a>]</p>
!! wikitext
[http://google.com <nowiki>[google]</nowiki>]
[http://google.com <nowiki>google]</nowiki>]
[http://google.com <nowiki>goog] le</nowiki>]

<nowiki>[http://google.com]</nowiki>

<nowiki>[http://google.com google]</nowiki>

[http://google.com<nowiki>]</nowiki>

[{{echo|http://google.com}}<nowiki>]</nowiki>
!! html/php
<p><a rel="nofollow" class="external text" href="http://google.com">[google]</a>
<a rel="nofollow" class="external text" href="http://google.com">google]</a>
<a rel="nofollow" class="external text" href="http://google.com">goog] le</a>
</p><p>[http://google.com]
</p><p>[http://google.com google]
</p><p>[<a rel="nofollow" class="external free" href="http://google.com">http://google.com</a>]
</p><p>[<a rel="nofollow" class="external free" href="http://google.com">http://google.com</a>]
</p>
!! end

!! test
Links 5. ExtLinks: No escapes needed
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://google.com">[google</a></p>
<p>[<a ref="mw:ExtLink" href="http://google.com"></a>]</p>
!! wikitext
[http://google.com [google]

[[http://google.com]]
!! html/php
<p><a rel="nofollow" class="external text" href="http://google.com">[google</a>
</p><p>[<a rel="nofollow" class="external autonumber" href="http://google.com">[1]</a>]
</p>
!! end

!! test
Links 6. Add <nowiki/>s between text-nodes and url-links when required (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p>x<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>y
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>?x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>&amp;x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>'x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>,x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>.x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>;x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>:x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>;x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>!x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>=x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>(x)
<a rel="mw:ExtLink" href="http://example.com(x" data-parsoid='{"stx":"url"}'>http://example.com(x</a>)
</p>
!! wikitext
x<nowiki/>http://example.com<nowiki/>y
http://example.com<nowiki/>?x
http://example.com<nowiki/>&x
http://example.com<nowiki/>'x
http://example.com<nowiki/>,x
http://example.com<nowiki/>.x
http://example.com<nowiki/>;x
http://example.com<nowiki/>:x
http://example.com<nowiki/>;x
http://example.com<nowiki/>!x
http://example.com<nowiki/>=x
http://example.com<nowiki/>(x)
http://example.com(x<nowiki/>)
!! end

!! test
Links 7a. Don't add spurious <nowiki/>s between text-nodes and url-links (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p>x
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>
y
"<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>"
(<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>)
(<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>) foo
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>,
<a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>, foo
</p>
!! wikitext
x
http://example.com
y
"http://example.com"
(http://example.com)
(http://example.com) foo
http://example.com,
http://example.com, foo
!! html/php
<p>x
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>
y
"<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>"
(<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>)
(<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>) foo
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>,
<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>, foo
</p>
!! end

!! test
Links 7b. Don't add spurious <nowiki/>s between text-nodes and url-links (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" data-parsoid='{"stx":"url"}'>http://example.com</a>.,;:!?\
-<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>:</p>
!! wikitext
http://example.com.,;:!?\
-http://example.com:
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>.,;:!?\
-<a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>:
</p>
!! end

!! test
Links 8. Add <nowiki/>s between text-nodes and RFC-links when required (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="//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 (T66300)
!! 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 (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>4
<a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>y
X<a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>y
!! wikitext
PMID 123<nowiki/>4
PMID 123<nowiki/>y
X<nowiki/>PMID 123<nowiki/>y
!! end

!! test
Links 11. Don't add spurious <nowiki/>s between text-nodes and PMID-links (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>?foo
<a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>&foo
-<a href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract" rel="mw:ExtLink" data-parsoid='{"stx":"magiclink"}'>PMID 123</a>-
</p>
!! wikitext
PMID 123?foo
PMID 123&foo
-PMID 123-
!! html/php
<p><a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract">PMID 123</a>?foo
<a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract">PMID 123</a>&amp;foo
-<a class="external mw-magiclink-pmid" rel="nofollow" href="//www.ncbi.nlm.nih.gov/pubmed/123?dopt=Abstract">PMID 123</a>-
</p>
!! end

!! test
Links 12. Add <nowiki/>s between text-nodes and ISBN-links when required (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>1
<a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>x
a<a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>b
</p>
!! wikitext
ISBN 1234567890<nowiki/>1
ISBN 1234567890<nowiki/>x
a<nowiki/>ISBN 1234567890<nowiki/>b
!! end

!! test
Links 13. Don't add spurious <nowiki/>s between text-nodes and ISBN-links (T66300)
!! options
parsoid=html2wt
!! html/parsoid
<p>-<a href="./Special:BookSources/1234567890" rel="mw:WikiLink" data-parsoid='{"stx":"magiclink"}'>ISBN 1234567890</a>'s
!! wikitext
-ISBN 1234567890's
!! html/php
<p>-<a href="/wiki/Special:BookSources/1234567890" class="internal mw-magiclink-isbn">ISBN 1234567890</a>'s
</p>
!! end

!! test
Links 14. Protect link-like plain text. (Parsoid bug T78425)
!! options
parsoid=html2wt
!! html/*
<p>this is not a link: http://example.com
</p>
!! wikitext
this is not a link: <nowiki>http://example.com</nowiki>
!! end

!! test
Links 15. Link trails can't become link prefixes.
!! options
language=is
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:WikiLink" href="Söfnuður" title="Söfnuður" data-parsoid='{"stx":"simple","tail":"-"}'>Söfnuður-</a><a rel="mw:WikiLink" href="00" title="00">00</a></p>
!! wikitext
[[Söfnuður]]-[[00]]
!! html/php
<p><a href="/wiki/S%C3%B6fnu%C3%B0ur" title="Söfnuður">Söfnuður-</a><a href="/wiki/00" title="00">00</a>
</p>
!! end

#### --------------- 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="./Main_Page#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
'<i>foo</i> <div title="name">test</div>
'<i>foo</i> and <br data-parsoid='{"stx":"html","noClose":true}'/> bar
<ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
<li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="./Main_Page#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">test</span></li>
</ol>
!! wikitext
'''a'' foo ''[[bar]]''
''a''' foo ''[[bar]]''
''a''' foo '''{{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
parsoid=html2wt
!! html/parsoid
<p>'<span><i>bar</i></span>'
'<span><b>bar</b></span>'
'a:b'foo
</p>
!! wikitext
'<span>''bar''</span>'
'<span>'''bar'''</span>'
'a:b'foo
!! end

#### ----------- Paragraphs ---------------
#### 1. No unnecessary escapes
#### --------------------------------------

!! test
1. No unnecessary escapes
!! options
parsoid=html2wt
!! html/parsoid
<p>bar <span>[[foo]]</span>
</p><p>=bar <span>[[foo]]</span>
</p><p>[[bar <span>[[foo]]</span>
</p><p>]]bar <span>[[foo]]</span>
</p><p>=bar <span>foo]]</span>=
</p>
!! wikitext
bar <span><nowiki>[[foo]]</nowiki></span>

=bar <span><nowiki>[[foo]]</nowiki></span>

[[bar <span><nowiki>[[foo]]</nowiki></span>

]]bar <span><nowiki>[[foo]]</nowiki></span>

=bar <span>foo]]</span><nowiki>=</nowiki>
!!end

#### ----------------------- PRE --------------------------
#### 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=html2wt
!! 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="./Main_Page#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="./Main_Page#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text"><i>a</i>
 b</span></li>
</ol>
!! wikitext
foo <ref>''a''
 b</ref>
<references />
!! end

!! test
3. Leading whitespace in indent-pre suppressing contexts should not be escaped
!! options
parsoid=html2wt
!! html/parsoid
<blockquote>
<p>
 a
 <span>b</span>
 c</p>
</blockquote>
!! wikitext
<blockquote>
 a
 <span>b</span>
 c
</blockquote>
!! end

!! test
4. Leading whitespace in indent-pre suppressing contexts should not be escaped
!! options
parsoid=html2wt
!! html/parsoid
 <figure class="mw-default-size" typeof="mw:Image/Thumb"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="//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
(T54035) Nowiki-escaping should not get tripped by " :" in text
!! options
parsoid=html2wt
!! html/parsoid
<p>foo's bar :</p>
!! wikitext
foo's bar :
!! end

#----------- End of wikitext escaping tests --------------

!! test

Tag-like HTML structures are passed through as text
!! wikitext
<x y>

<x.y>

<x-y>

1>2

x<y

a>b

1<d e>f
!! html
<p>&lt;x y&gt;
</p><p>&lt;x.y&gt;
</p><p>&lt;x-y&gt;
</p><p>1&gt;2
</p><p>x&lt;y
</p><p>a&gt;b
</p><p>1&lt;d e&gt;f
</p>
!! end

!! test
HTML tag with necessary entities in attributes
!! wikitext
<span title="&amp;amp;">foo</span>
!! html
<p><span title="&amp;amp;">foo</span>
</p>
!! end

!! test
HTML tag with 'unnecessary' entity encoding in attributes
!! wikitext
<span title="&amp;">foo</span>
!! html
<p><span title="&amp;">foo</span>
</p>
!! end

!! test
HTML tag with broken attribute value quoting
!! options
parsoid=wt2html,html2html
!! wikitext
<span title="Hello world>Foo</span>
!! html/php
<p><span title="Hello world">Foo</span>
</p>
!! html/parsoid
<p><span title="Hello world">Foo</span></p>
!! end

!! test
Self-closed tag with broken attribute value quoting
!! options
parsoid=wt2html,html2html
!! wikitext
<div title="Hello world />Foo
!! html/php+tidy
<div title="Hello world"></div>
<p>Foo</p>
!! html/parsoid
<div title="Hello world " data-parsoid='{"stx":"html","selfClose":true}'></div><p>Foo</p>
!! end

!! test
Table with broken attribute value quoting
!! options
parsoid=wt2html,html2html
!! 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
!! options
parsoid=wt2html,html2html
!! 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
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/php
<table>

</table>

!! html/parsoid
<table>
<tbody><tr data-parsoid='{"startTagSrc":"|-","a":{"[[foo]]":null},"sa":{"[[foo]]":""},"autoInsertedEnd":true}'></tr>
</tbody></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>

{| typeof="mw:placeholder stuff" data-mw="whoo" data-parsoid="weird" data-parsoid-other="no" about="time" rel="mw:true"
| ok
|}
!! html/parsoid
<div data-x-typeof="mw:placeholder stuff" data-x-data-mw="whoo" data-x-data-parsoid="weird" data-x-data-parsoid-other="no" data-x-about="time" data-x-rel="mw:true">foo</div>

<table data-x-typeof="mw:placeholder stuff" data-x-data-mw="whoo" data-x-data-parsoid="weird" data-x-data-parsoid-other="no" data-x-about="time" data-x-rel="mw:true">
<tbody><tr><td data-parsoid='{"autoInsertedEnd":true}'> ok</td></tr>
</tbody></table>
!!end

## Currently the p-wrapper is fragile in how it adds / removes transformations.
## Having nested or stray pre tags results in the attempt to add duplicates,
## causing an assertion fail. This test tries to prevent that situation.
!!test
Ensure ParagraphWrapper can deal with stray closing pre tags
!!options
parsoid=wt2html
!! wikitext
plain text</pre>
!! html/parsoid
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"}]]}'>hi</p><table about="#mwt2" data-parsoid='{"stx":"html"}'></table><p about="#mwt2">hello</p>
!!end

!!test
Table in fosterable position
!!options
parsoid=wt2html
!! wikitext
{{OpenTable}}
<div>
{|
|}
</div>
|}
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"OpenTable","href":"./Template:OpenTable"},"params":{},"i":0}},"\n&lt;div>\n"]}' data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[]]}'></div><span about="#mwt1">
</span>
<table about="#mwt1" data-parsoid='{"autoInsertedEnd":true}'></table>

<table>
</table>
!!end

# Parsoid only for T66747
!! test
Properly encapsulate empty-content transclusions in fosterable positions
!! wikitext
<table>
{{#if:|
<td>foo</td>
}}
</table>
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["&lt;table>\n",{"template":{"target":{"wt":"#if:","function":"#if"},"params":{"1":{"wt":"\n&lt;td>foo&lt;/td>\n"}},"i":0}},"\n&lt;/table>"]}' data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}'>

</table>
!! end

!! test
Always encapsulate foster box when template range is expanded to table
!! options
parsoid=wt2wt
!! wikitext
{|
hello
{{OpenTable}}
|}
!! html/parsoid

!! end

!! test
T115289: Unclosed table
!! wikitext
{{echo|<table>}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Two" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:Two"},"sa":{"href":"Category:Two"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;table>"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'/><table about="#mwt1" data-parsoid='{"stx":"html","autoInsertedEnd":true}'><!--c--></table>
!! end

!! test
T115289: Don't migrate newlines out of tables with fostered content
!! wikitext
<table><td></td>{{echo|<tr>[[Category:One]]}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:One" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:One"},"sa":{"href":"Category:One"},"fostered":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;td>&lt;/td>",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;tr>[[Category:One]]"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'/><link rel="mw:PageProp/Category" href="./Category:Two" about="#mwt2"/><table about="#mwt2" data-parsoid='{"stx":"html","autoInsertedEnd":true}'><tbody><tr><td></td></tr><tr><!--c--></tr></tbody></table>
!! end

!! test
T73074: More fostering fun
!! wikitext
<table><td></td>{{echo|<tr>}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Two" data-parsoid='{"stx":"simple","a":{"href":"./Category:Two"},"sa":{"href":"Category:Two"},"fostered":true}'/><table data-parsoid='{"stx":"html","autoInsertedEnd":true}'><tbody><tr data-parsoid='{"autoInsertedEnd":true,"autoInsertedStart":true}'><td data-parsoid='{"stx":"html"}'></td></tr><tr about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;tr>"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'><!--c--></tr></tbody></table>
!! end

!!test
Support <object> element with .data attribute
!!options
parsoid=html2wt
!! html/parsoid
<object data="test.swf"></object>
!! wikitext
<object data="test.swf"></object>
!!end

!! test
Don't block XML namespace declaration
!! wikitext
<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">MediaWiki</span>
!! html/php
<p><span xmlns:dct="http&#58;//purl.org/dc/terms/" property="dct:title">MediaWiki</span>
</p>
!! html/parsoid
<p><span xmlns:dct="http://purl.org/dc/terms/" data-x-property="dct:title" data-parsoid='{"stx":"html"}'>MediaWiki</span></p>
!! end

# -----------------------------------------------------------------
# The following section of tests are primarily to spec requirements
# around Parsoid's serialization (old, new, edited content)
#
# All these tests are marked Parsoid html2wt and html2html only
# ----------------------------------------------------------------

!! test
Ignore rel attribute in a-tags during serialization to url-links
!! options
parsoid=html2wt
!! html/parsoid
<a href='http://en.wikipedia.org/wiki/Foobar'>http://en.wikipedia.org/wiki/Foobar</a>
<a href='http://en.wikipedia.org/wiki/Foobar' rel='mw:ExtLink'>http://en.wikipedia.org/wiki/Foobar</a>
<a href='http://en.wikipedia.org/wiki/Foobar' rel='mw:WikiLink'>http://en.wikipedia.org/wiki/Foobar</a>
!! wikitext
http://en.wikipedia.org/wiki/Foobar
http://en.wikipedia.org/wiki/Foobar
http://en.wikipedia.org/wiki/Foobar
!! end

# 'mi' is a localinterwiki prefix as well as a language
!! test
Serialize interwiki links pointing to the current wiki as plain wiki links (T67869)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://mi.wikipedia.org/wiki/Foo">Foo</a></p>
!! wikitext
[[Foo]]
!! end

# See T93839
!! test
New wikilinks should be serialized properly
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{}'>Foo</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a>
<a href="//en.wikipedia.org/wiki/Foo">//en.wikipedia.org/wiki/Foo</a>
<a href="http://en.wikipedia.org/wiki/Foo">http://en.wikipedia.org/wiki/Foo</a>
<a href="//en.wikipedia.org/wiki/Foo_bar">//en.wikipedia.org/wiki/Foo bar</a>
!! wikitext
[[Foo]]
[[Foo]]
[[:en:Foo|//en.wikipedia.org/wiki/Foo]]
http://en.wikipedia.org/wiki/Foo
[[:en:Foo_bar|//en.wikipedia.org/wiki/Foo bar]]
!! end

!! test
New wiki links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="Foo bar">Foo_bar</a>
<a rel="mw:WikiLink" href="./Toxine_bact%C3%A9rienne">Toxine bactérienne</a>
!! wikitext
[[Foo_bar]]
[[Foo_bar]]
[[Foo_bar]]
[[Toxine bactérienne]]
!! end

!! test
New wiki links (content string variations)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="./Foo_bar">Foo bar</a>
<a rel="mw:WikiLink" href="./Foo_bar">./Foo_bar</a>
!! wikitext
[[Foo_bar]]
[[Foo bar]]
[[Foo_bar|./Foo_bar]]
!! end

!! test
New category links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Toxine_bactérienne" />
<link rel="mw:PageProp/Category" href="./Category:Toxine_bact%C3%A9rienne" />
<link rel="mw:PageProp/Category" href="Category:Toxine_bact%C3%A9rienne" />
!! wikitext
[[Category:Toxine bactérienne]]
[[Category:Toxine bactérienne]]
[[Category:Toxine bactérienne]]
!! end

!! test
New sol transparent links don't need indent-pre nowiki protection
!! options
parsoid=html2wt
language=de
!! html/parsoid
         <link rel="mw:PageProp/redirect" href="./Main_Page">
<!-- this is good  -->    <link rel="mw:PageProp/Category" href="./Category:Good" />
<!-- this is great -->    <link rel="mw:PageProp/Category" href="./Kategorie:Great" />
!! wikitext
         #WEITERLEITUNG [[Main Page]]
<!-- this is good  -->    [[Category:Good]]
<!-- this is great -->    [[Kategorie:Great]]
!! end

!! test
New interlanguage links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine bactérienne" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine_bactérienne" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine_bact%C3%A9rienne" />
!! wikitext
[[es:Toxine bactérienne]]
[[es:Toxine_bactérienne]]
[[es:Toxine_bactérienne]]
!! end

!! 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 (T50665)
!! 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 (T64805)
!! 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 (T51221)
!! 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 (T58400)
!! 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 (T50924)
!! 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 (T53852)
!! 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
Image: Invalid title as link
!! wikitext
[[File:Foobar.jpg|link=<]]
!! html/php
<p><a href="/wiki/File:Foobar.jpg" class="image" title="link=&lt;"><img alt="link=&lt;" 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-parsoid='{"optList":[{"ck":"link","ak":"link=&lt;"}]}' data-mw='{"caption":"link=&amp;lt;"}'><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>
!! end

!! test
Lists: Serialize correctly even when list content is wrapped in p-tags (like VE does)
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li><p>foo</p></li>
</ul>
!! wikitext
* foo
!! end

!! test
Lists: Serialize correctly even when list tags has unneeded whitespace between tags
!! options
parsoid=html2wt
!! html/parsoid
<ul> <li>foo</li></ul>
!! wikitext
* foo
!! end

!! test
Don't strip leading whitespace when handling indent-pre suppressing tags
!! options
parsoid=html2wt
!! html/parsoid
<table>
  <tr><td> indented row</td></tr>
</table>
<blockquote><p>
 <b>This is very bold of you!</b>
</p>
<table><tr><td>
 indented cell (no pre-wrapping!)
</td></tr></table>
</blockquote>
<p>foo</p>
 <div>bar</div>
!! wikitext
{|
  | indented row
|}
<blockquote>
 '''This is very bold of you!'''

{|
|
 indented cell (no pre-wrapping!)
|}
</blockquote>
foo
 <div>bar</div>
!! end

!! test
Nowiki-wrap leading whitespace when handling indent-pre inducing tags
!! options
parsoid=html2wt
!! html/parsoid
<p>foo</p>
 <span>bar</span>

<span>foo2
 </span>bar2

<div>foo</div>
 <span>bar</span>

<div>
 <span>foo</span>
</div>
!! wikitext
foo
 
<span>bar</span>

<span>foo2
<nowiki> </nowiki></span>bar2

<div>foo</div>
<nowiki> </nowiki><span>bar</span>

<div>
<nowiki> </nowiki><span>foo</span>
</div>
!! end

!! test
Lists: Dont insert newlines in a serialized list item.
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>a<br>b</li><li>c</li></ul>
!! wikitext
* a<br>b
* c
!! end

!! test
1. Headings: Force sol-transparent links and behavior switches to serialize before/after
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! html/parsoid
<h2>hello there<link href="./Category:A1" rel="mw:PageProp/Category" /></h2>
<h2><link href="./Category:A2" rel="mw:PageProp/Category" />hi pal</h2>

<h2><!--foo-->  <link href="./Category:A3" rel="mw:PageProp/Category" />   how goes it</h2>
<h2>it goes well   <link href="./Category:A4" rel="mw:PageProp/Category" />  <!--bar--></h2>

<h2 data-parsoid='{}'>howdy<link href="./Category:A5" rel="mw:PageProp/Category" /></h2>

<h2><meta property="mw:PageProp/toc" /> ok</h2>
!! wikitext
== hello there [[Category:A1]] ==

== [[Category:A2]] hi pal ==

== <!--foo-->  [[Category:A3]]    how goes it ==

== it goes well    [[Category:A4]]  <!--bar--> ==

==howdy [[Category:A5]]==

==  __TOC__  ok ==
!! end

!! test
2. Headings: Force sol-transparent links and behavior switches to serialize before/after
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2>hello there<link href="./Category:A1" rel="mw:PageProp/Category" /></h2>
<h2><link href="./Category:A2" rel="mw:PageProp/Category" />hi pal</h2>

<h2><!--foo-->  <link href="./Category:A3" rel="mw:PageProp/Category" />   how goes it</h2>
<h2>it goes well   <link href="./Category:A4" rel="mw:PageProp/Category" />  <!--bar--></h2>

<h2><meta property="mw:PageProp/toc" /> ok</h2>
!! wikitext
== hello there ==
[[Category:A1]]
[[Category:A2]]

== hi pal ==

<!--foo-->  [[Category:A3]]

== how goes it ==

== it goes well ==
[[Category:A4]]  <!--bar-->

__TOC__

== ok ==
!! end

!! test
Headings: Don't hoist metas that come from templates
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2><span about="#mwt1" typeof="mw:Transclusion" data-parsoid="{}" data-mw='{"parts":[{"template":{"target":{"wt":"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="./Main_Page#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> </h2>

<ol class="references" typeof="mw:Extension/references" about="#mwt3" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="./Main_Page#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">bar <link rel="mw:PageProp/Category" href="./Category:Baz" /> </span></li></ol>
!! wikitext
== foo <ref>bar 
[[Category:Baz]] </ref> ==

<references />
!! end

!! test
Parsoid: Serialize positional parameters with = in them as named parameter
!! options
parsoid=html2wt
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"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"},{"k":"2"}]]}' 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="./Main_Page#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> </h2>

<ol class="references" typeof="mw:Extension/references" about="#mwt3" data-mw='{"name":"references","attrs":{}}'><li about="#cite_note-1" id="cite_note-1"><span rel="mw:referencedBy"><a href="./Main_Page#cite_ref-1">↑</a></span> <span id="mw-reference-text-cite_note-1" class="mw-reference-text" data-parsoid="{}">hello
there</span></li></ol>

<ul><li>asd
sdf</li></ul>

<ul><li>foo
bar
baz</li>
<li>foo <b>bar</b>
baz</li></ul>

<dl><dt>hi
ho </dt><dd data-parsoid='{"stx":"row"}'> hi
ho</dd></dl>

<dl><dd> <table>
<tbody><tr><td> ha
ha
ha</td></tr>
</tbody></table></dd></dl>
!! wikitext
== testing 123 ==

== hi {{bogus|there
you}} ==

== foo <ref>hello
there</ref> ==

<references />

* asd sdf

* foo bar baz
* foo '''bar''' baz

; hi ho : hi ho

: {|
| ha
ha
ha
|}
!! end

!! 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
T56262: New entities
!! options
parsoid=html2wt
!! html/parsoid
<span typeof="mw:Entity">&nbsp;</span>
!! wikitext
&nbsp;
!! end

## Note that there is no wikitext output for 'unknownproperty' ##
## Unknown magic words are silently dropped ##

!! test
Magic words
!! options
parsoid=html2wt
!! html/parsoid
<meta property='mw:PageProp/toc' />
<meta property='mw:PageProp/notoc' />
<meta property='mw:PageProp/forcetoc' />
<meta property='mw:PageProp/index' />
<meta property='mw:PageProp/noindex' />
<meta property='mw:PageProp/nogallery' />
<meta property='mw:PageProp/noeditsection' />
<meta property='mw:PageProp/notitleconvert' />
<meta property='mw:PageProp/nocontentconvert' />
<meta property='mw:PageProp/unknownproperty' />
!! wikitext
__TOC__
__NOTOC__
__FORCETOC__
__INDEX__
__NOINDEX__
__NOGALLERY__
__NOEDITSECTION__
__NOTITLECONVERT__
__NOCONTENTCONVERT__
!! end

!! test
Consecutive <pre>s should not get merged
!! options
parsoid=html2wt,html2html
!! html/parsoid
<pre>a</pre><pre>b</pre>

<pre>c
</pre><pre>
d</pre>

<pre>e

</pre><pre>

f</pre>
!! wikitext
 a

 b

 c

 d

 e
 

 
 f
!! end

!! test
Edited ISBN links not serializable as ISBN links should serialize as wikilinks
!! options
parsoid=html2wt
!! html/parsoid
<a href="./Special:BookSources/1234567890" rel="mw:ExtLink">ISBN 1234567895</a>
!! wikitext
[[Special:BookSources/1234567890|ISBN 1234567895]]
!! end

!! test
Edited RFC links not serializable as RFC links should serialize as extlinks
!! options
parsoid=html2wt
!! html/parsoid
<a href="//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'''foo'''

http://cscott.net<b>foo</b>

'''http://cscott.net'''

'''http://cscott.net '''

'''http://cscott.net<nowiki/>x'''

http://cscott.net<nowiki/>x
!! end

!! test
WTS of autolinks with nowikis (round-trip)
!! wikitext
x<nowiki/>http://cscott.net<nowiki/>x
!! html/parsoid
<p>x<a rel="mw:ExtLink" href="http://cscott.net">http://cscott.net</a>x</p>
!! end

# this is the "easy" test because it leaves in place all the
# data-parsoid information indicating this is an autolink
!! test
WTS of autolinks with escapes (editing)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "span", "remove" ]
  ]
}
!! wikitext
x<nowiki/>http://cscott.net<nowiki/>x
!! wikitext/edited
x<nowiki/>http://cscott.net<nowiki/>x
!! end

!! test
WTS of edited autolink-like text (T103364)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "span[typeof]", "removeAttr", "typeof" ]
  ]
}
!! wikitext
Not a link: <nowiki>http://example.com</nowiki>.
!! wikitext/edited
Not a link: <span><nowiki>http://example.com</nowiki></span>.
!! end

!! test
WTS of newly-authored autolink-like text (T103364)
!! options
parsoid=html2wt
!! html/parsoid
<p>http://example.com is not a link.</p>
!! wikitext
<nowiki>http://example.com</nowiki> is not a link.
!! end

!! test
WTS of autolink-like text after an autolink (T108563)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a> http://example.com is not a link.</p>
!! wikitext
http://example.com <nowiki>http://example.com</nowiki> is not a link.
!! end

!! test
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={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<div typeOf="mw:Extension/foo"></div>
!! wikitext
<foo />
!! end

# Note that the <p> wrapping isn't present in PHP parser output
# The important thing for this test is that P-wrapping doesn't
# interfere with the <nowiki> protection for leading - in <td>
# (which isn't necessary for <th>).
!! test
T88318: p-wrapped dash in table.
!! options
parsoid=html2wt,wt2wt
!! html/parsoid
<table><tbody>
<tr><th><p>-</p></th><th><p>- </p></th></tr>
<tr><td><p>-</p></td><td><p>- </p></td></tr>
<tr><td><small>-</small></td><td><br/><p>-</p></td><td><br/>-</td></tr>
</tbody></table>
!! wikitext
{|
!-
!- 
|-
|<nowiki>-</nowiki>
|<nowiki>- </nowiki>
|-
|<small>-</small>
|<br>
-
|<br>
-
|}
!! html/php+tidy
<table>
<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
T149209: WTS: Handle newlines in table cells properly
!! options
parsoid=html2wt
!! html/parsoid
<table>
<tbody>
<tr><td>a
b
</td><td data-parsoid='{"stx_v":"row"}'>c</td></tr>
<tr><td><p>x</p>
</td><td data-parsoid='{"stx_v":"row", "startTagSrc": "{{!}}{{!}}"}'>y</td></tr>
</tbody></table>
<table>
<tbody>
<tr><th>a
b
</th><th data-parsoid='{"stx_v":"row"}'>c</th></tr>
<tr><th><p>x</h>
</th><th data-parsoid='{"stx_v":"row"}'>y</th></tr>
</tbody></table>
!! wikitext
{|
|a
b
|c
|-
|x
{{!}}y
|}
{|
!a
b
!c
|-
!x
!y
|}
!! end

!! test
T149209: Selser: Handle newlines in table cells properly
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#h1", "html", "a\nb\n" ],
    [ "#h2", "html", "a\nb\n" ],
    [ "#c1", "html", "a\nb\n" ],
    [ "#c2", "html", "<p>a</p>" ],
    [ "#c3", "html", "<p>a</p>" ],
    [ "#c4", "html", "edit-me<p>a</p>" ]
  ]
}
!! wikitext
{|
! id="h1" |edit-me!!1
|-
! id="h2" |edit-me||2
|-
| id="c1" |edit-me||3
|-
| id="c2" |edit-me||4
|-
| id="c3" |edit-me||p||q||r
|-
| id="c4" |edit-me||p||q||r
|}
!! wikitext/edited
{|
! id="h1" |a
b
!1
|-
! id="h2" |a
b
!2
|-
| id="c1" |a
b
|3
|-
| id="c2" |a
|4
|-
| id="c3" |a
|p||q||r
|-
| id="c4" |edit-me
a
|p||q||r
|}
!! end

!! test
HTML id attribute with Parsoid-like element ids should not be serialized to wikitext
!! options
parsoid=html2wt
!! html/parsoid
<table id='mwAb'>
<td id='mwAc'>foo</td>
<td id='serialize-this'>bar</td>
</table>
!! wikitext
{|
|foo
| id="serialize-this" |bar
|}
!! end

!! test
Parsoid-like element ids should not be serialized to wikitext unless shadowed
!! options
parsoid=html2wt
!! html/parsoid
<div id="mwAQ" data-parsoid='{"stx":"html","a":{"id":"mwAQ"},"sa":{"id":"hello"}}'>ok</div>
!! wikitext
<div id="hello">ok</div>
!! end

!! test
WTS change modes
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "#xyz", "before", "<b>before</b> stuff " ],
    [ "#xyz", "after", " stuff <i>after</i>" ],
    [ "#xyz", "html", "x <b>y</b> z" ]
  ]
}
!! wikitext
<span id="xyz">hello</span>
!! wikitext/edited
'''before''' stuff <span id="xyz">x '''y''' z</span> stuff ''after''
!! end

!! test
Never serialize a-tag as html, regardless of what data-parsoid has to say
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"html"}'>Foo</a>
!! wikitext
[[Foo]]
!! end

## SSS FIXME: This is broken output nevertheless.
## What might be a reasonable non-broken output for this?
## This is an edge case unlikely to be seen in production
## that I am not wasting more time on this right now.
!! test
Never serialize a-tag as html, no matter what attributes it has
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a bad='true' href='http://boo.org'><img src='http://boohoo.org' /></a>
!! wikitext
[http://boo.org http://boohoo.org]
!! end

# Misnested is an indication that selser can reuse the source but these have
# shown to sneak through on occasion. See T101768.
# The original wikitext here is: [http://test.com [[one]] two three]
!! test
Strip span tags added to mark misnested links
!! options
parsoid=html2wt
!! html/parsoid
<p data-parsoid='{}'><a rel="mw:ExtLink" href="http://test.com" data-parsoid='{"targetOff":17,"contentOffsets":[17,34]}'></a><a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"simple","a":{"href":"./One"},"sa":{"href":"one"},"misnested":true}'>one</a><span data-parsoid='{"misnested":true}'> two three</span></p>
!! wikitext
[http://test.com][[one]] two three
!! end

!! test
Use data-parsoid.firstWikitextNode to compute newline constraints for template content
!! options
parsoid=html2wt
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span><table about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"a":{"{{echo|c\n{{!}}d\n}}":null},"sa":{"{{echo|c\n{{!}}d\n}}":""},"firstWikitextNode":"table","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"c\n{{!}}d\n"}},"i":0}},"\n|}"]}'>
<tbody><tr><td>d
</td></tr>
</tbody></table>
!! wikitext
{{echo|a}}
{|{{echo|c
{{!}}d
}}
|}
!! end

## This test verifies the presence and computation of this attribute indirectly
## by making an edit and ensuring that the serialization is correct (which it would be
## only if firstWikitextNode is properly set).
!! test
data-parsoid.firstWikitextNode should be computed properly in the presence of fostered content
!! options
parsoid= {
  "modes": ["wt2wt"],
  "changes": [
    [ "div#x", "remove" ],
    [ "div", "before", "<div>new</div>" ]
  ]
}
!! wikitext
<div id="x">foo</div>
{|
{{echo|<div>boo</div>
{{!}}b}}
|c
|}
!! wikitext/edited

<div>new</div>
{|
{{echo|<div>boo</div>
{{!}}b}}
|c
|}
!! end

# --------------------------------------------
# Tests spec'ing wikitext serialization norms |
# --------------------------------------------

!! test
Serialize multi-line indent-pre starting with wikitext syntax
!! options
parsoid=html2wt
!! html/parsoid
<pre>* 1
** 2
* 3</pre>
!! wikitext
 * 1
 ** 2
 * 3
!! end

!! test
1. Categories should always be serialized on their own line
!! options
parsoid=html2wt
!! html/parsoid
foo<link rel="mw:PageProp/Category" href="./Category:Foo">bar
!! wikitext
foo
[[Category:Foo]]
bar
!! end

!! test
2. Categories that are part of templates should not introduce a line break
!! wikitext
foo {{echo|<span>bar</span> [[Category:baz]]}} bar
!! html/parsoid
<p>foo <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;span>bar&lt;/span> [[Category:baz]]"}},"i":0}}]}'>bar</span><span about="#mwt1"> </span><link rel="mw:PageProp/Category" href="./Category:Baz" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:baz"}}'/> bar</p>
!! end

# Careful while editing these next 2 tests. There are \u200f characters
# before and after the <link> tags in the HTML and following some
# of the categories in wikitext
# Do not remove these characters in edits.
#
# As part of the serialization, these bidi characters will get stripped.
!! test
RTL (\u200f) and LTR (\u200e) markers around category tags should be stripped
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<p>‏<link rel="mw:PageProp/Category" href="./קטגוריה:טקסים" />‏
‏<link rel="mw:PageProp/Category" href="./קטגוריה:_שיטות_משפט" />‏</p>
!! wikitext
[[קטגוריה:טקסים]]
[[קטגוריה: שיטות משפט]]
!! end

!! test
RTL (\u200f) and LTR (\u200e) markers should not be stripped if followed by a text node
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<p>‏<link rel="mw:PageProp/Category" href="./קטגוריה:טקסים" />‏y</p>
!! wikitext
[[קטגוריה:טקסים]]
‏y
!! end

!! test
Lists: Add space after bullets
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>foo</li>
<li> bar</li>
<li><span> baz</span></li>
</ul>
!! wikitext
* foo
* bar
* <span> baz</span>
!! end

!! test
1. Headings: Add space before/after == (T53744)
!! options
parsoid=html2wt
!! html/parsoid
<h2>foo</h2>
<h2> bar</h2>
<h2>baz </h2>
<h2><span> baz</span></h2>
!! wikitext
== foo ==

== bar ==

== baz ==

== <span> baz</span> ==
!! end

!! test
2. Headings: Add space before/after == even after hoisted content
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2> <link href="./Category:A2" rel="mw:PageProp/Category" />ok</h2>
!! wikitext
 [[Category:A2]]

== ok ==
!! end

!! test
1. Headings: suppress newly created empty headings
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2></h2>
!! wikitext
!! end

!! test
2. Headings: don't suppress empty headings if scrubWikitext is false
!! options
parsoid=html2wt
!! html/parsoid
<h2></h2>
!! wikitext
==<nowiki/>==
!! end

!! test
3. Headings: suppress empty headings on edits
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
==<span id="x">foo</span>==
!! wikitext/edited
!! end

!! test
Headings: Replace <br/> with a single whitespace char (when scrubWikitext = true)
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<h2>foo<br/>bar</h2>
<h2>foo <span><br/>bar</span> baz</h2>
!! wikitext
== foo bar ==

== foo <span> bar</span> baz ==
!! end

!! test
Headings: Replace <br/> with a single whitespace char (when scrubWikitext = false)
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! html/parsoid
<h2>foo<br/>bar</h2>
!! wikitext
== foo<br> bar ==
!! end

!! test
1. WT Quote Tags: suppress newly created empty style tags
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<i></i><b></b>
!! wikitext
!! end

!! test
2. WT Quote Tags: don't suppress empty style tags if scrubWikitext is false
!! options
parsoid=html2wt
!! html/parsoid
<i></i><b></b>
!! wikitext
''<nowiki/>'''''<nowiki/>'''
!! end

!! test
3. WT Quote Tags: suppress empty style tags on edits
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
'''<span id="x">foo</span>'''
!! wikitext/edited
!! end

!! test
1. Anchors: suppress newly created empty anchors
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Test" title="Test"></a>
!! wikitext
!! end

!! test
2. Anchors: don't suppress empty anchors if scrubWikitext is false
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Test" title="Test"></a>
!! wikitext
[[Test|<nowiki/>]]
!! end

!! test
3. Anchors: suppress empty anchors on edits
!! options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
[[Test|<span id="x">foo</span>]]
!! wikitext/edited
!! end

!! test
3a. Anchors: do not suppress numbered extlinks
!! options
parsoid={
  "modes": ["wt2wt"],
  "scrubWikitext": true
}
!! wikitext
[http://foo.com]
!! html/parsoid
<a rel="mw:ExtLink" href="http://foo.com"></a>
!! end

!! test
3b. Anchors: do not suppress numbered extlinks
!! options
parsoid={
  "modes": ["wt2wt"],
  "scrubWikitext": true,
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
[http://foo.com <span id="x">foo</span>]
!! wikitext/edited
[http://foo.com]
!! end

!!test
Normalizations should be restricted to edited content
!!options
parsoid={
  "modes": ["selser"],
  "scrubWikitext": true,
  "changes": [
    [ "h1", "before", "<i></i>"]
  ]
}
!!wikitext
a
= =
b
!!wikitext/edited
a
= =
b
!!end

!! test
1. Multiple normalizations (html2wt)
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html
<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

## T111151 Remove font elements without attributes
!! test
5a. font tags without attributes should be dropped in scrubWikitext mode
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": true
}
!! html
<font>foo</font>
<font><font>bar</font></font>
<font class="x">boo</font>
!! wikitext
foo
bar
<font class="x">boo</font>
!! end

!! test
5b. font tags should not be dropped without scrubWikitext being enabled
!! options
parsoid={
  "modes": ["html2wt"],
  "scrubWikitext": false
}
!! html
<font>foo</font>
!! wikitext
<font>foo</font>
!! end

!! test
Escape nowiki DOM elements
!! options
parsoid=html2wt
!! html/parsoid
<nowiki><i>foo</i></nowiki>
!! wikitext
&lt;nowiki&gt;''foo''&lt;/nowiki&gt;
!! end

# This is meant to be an interim fix while we go about figuring out
# how to not introduce these trailing <nowiki/>s in the first place.
!! test
T115717: Strip trailing <nowiki/>s (without affecting valid uses)
!! options
parsoid=html2wt
!! html/parsoid
<p>x<meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/>
y</p>
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n"," "," ",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;nowiki/>"}},"i":0}}]}'></span></p>
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n"," "," ","\n"]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;nowiki/>"}},"i":0}}]}'></span></p>
!! wikitext
x
y

{{echo|
1 = <nowiki/>}}

{{echo|
1 = <nowiki/>
}}
!! end

# ---------------------------------------------------
# End of tests spec'ing wikitext serialization norms |
# ---------------------------------------------------

# T104032
!! test
Bare inline nodes not wrapped inside p-tags should be treated as p-wrapped
!! options
parsoid=html2wt
!! html/parsoid
a<p>b</p>
<b>c</b><p>d</p>
<table><tr>
<td>a<p>b</p></td>
<td><b>c</b><p>d</p></td>
</tr></table>
!! wikitext
a

b

'''c'''

d
{|
|a
b
|'''c'''
d
|}
!! end

!! test
Anchor without href scenarios
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a class="bc"></a>
<a class="no">dice</a>
<a name="foo"></a>
!! wikitext

dice
<span name="foo"></span>
!! end

# -----------------------------------------------------------------
# End of section for Parsoid-only html2wt tests for serialization
# of new content
# -----------------------------------------------------------------

# -----------------------------------------------------------------
# The following section of tests are primarily to spec behavior of
# the selective serializer. All these tests have manual selser
# changes. The automated selser changes for all tests handle the
# wide variation of changes, but these tests here capture specs
# deterministically.
# ----------------------------------------------------------------

## T90517
!! test
Selser: New comments should not be lost
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#a", "after", "<!--c1-->" ],
    [ "#b", "before", "<!--c2-->" ]
  ]
}
!! wikitext
<span id="a">a</span>

<span id="b">b</span>
!! wikitext/edited
<span id="a">a</span><!--c1-->

<!--c2--><span id="b">b</span>
!! end

## T89383
!! test
Selser: Check for validity of DSR before using it
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#a", "before", "<meta property='mw:PageProp/displaytitle' content='foo'>" ]
  ]
}
!! wikitext
<span id="a">a</span>
!! wikitext/edited
{{DISPLAYTITLE:foo}}
<span id="a">a</span>
!! end

!! test
1. DOMDiff: Changes to <ref> content should be looked up using id
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["#X", "after", "bar"],
    ["#Y", "after", "baz"]
  ]
}
!! wikitext
X <ref><span id="X">foo</span></ref>
Y <ref name="a" />
<references>
<ref name="a"><span id="Y">foo</span></ref>
</references>
!! wikitext/edited
X <ref><span id="X">foo</span>bar</ref>
Y <ref name="a" />
<references>
<ref name="a"><span id="Y">foo</span>baz</ref>
</references>
!! end

!! test
2. DOMDiff: Changes to <ref> content should be looked up using id
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["#Z", "after", "bar"]
  ]
}
!! wikitext
A <ref>foo bar for a</ref>
B <ref group="X" name="b" />

<references />

<references group="X">
<ref name="b"><span id="Z">foo</span></ref>
</references>
!! wikitext/edited
A <ref>foo bar for a</ref>
B <ref group="X" name="b" />

<references />

<references group="X">
<ref name="b"><span id="Z">foo</span>bar</ref>
</references>
!! end

!! test
DOMDiff: Edits to content nested in elements with templated attributes should not be lost (T139388)
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "div:first-child", "text", "bar" ]
  ]
}
!! wikitext
<div style="{{1x|color:red;}}%">foo</div>
!! wikitext/edited
<div style="{{1x|color:red;}}%">bar</div>
!! end

!! test
Empty LI (T49673)
!! wikitext
* a
* 
*
* b
!! html/php+tidy
<ul>
<li>a</li>
<li class="mw-empty-elt"></li>
<li class="mw-empty-elt"></li>
<li>b</li>
</ul>
!! end

!! test
Thumbnail output
!! wikitext
[[File:Thumb.png|thumb]]
!! html/php+tidy
<div class="thumb tright">
<div class="thumbinner" style="width:137px;"><a href="/wiki/File:Thumb.png" class="image"><img alt="Thumb.png" 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:Thumb.png" class="internal" title="Enlarge"></a></div>
</div>
</div>
</div>
!! end

!! test
unclosed internal link XSS (T137264)
!! wikitext
[[#%3Cscript%3Ealert(1)%3C/script%3E|
!! html/php
<p>[[#&lt;script&gt;alert(1)&lt;/script&gt;|
</p>
!! html/parsoid
<p>[[#%3Cscript%3Ealert(1)%3C/script%3E|</p>
!! end
