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

# 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 modes:
#
#  (default)  generate HTML output
#  pst        apply pre-save transform
#  msg        apply message transform
#  comment    run through MediaWiki\CommentFormatter\CommentFormatter::format() instead of main parser
#
# Options for adding metadata to the metadata section:
# (Previously, these options pre- or post- pended to the html section)
#
# cat           add category links
# extlinks      add external link metadata
# ill           add inter-language links
# iwl           add inter-wiki links
# links         add local wiki links
# special       add links to special pages
# templates     add template information
# property=XXX  add the value of the page property with the given name.
#               This can also be a comma-separated list.
# extension=XXX add the JSON-encoded value of the given extension data.
#               This can also be a comma-separated list.
# showtitle     add the rendered title
# showflags     add the set parser output flags
# showtocdata   add table of contents data
# showindicators add the page status indicators
# showmedia     add the titles of the rendered media
#
# Parser parameters:
#
# subpage       enable subpages (disabled by default)
# title=[[XXX]] run test using article title XXX
# language=XXX  set content language to XXX for this test
# wtVariantLanguage=XXX set the wikitext (input) variant of language for this
#               test using a BCP-47 code (eg zh-Hant-TW)
# htmlVariantLanguage=XXX   set the html (output) variant of language for this
#               test using a BCP-47 code (eg zh-Hant-TW)
# userLanguage=XXX  set user language to XXX for this test
# notoc         disable table of contents
# thumbsize=NNN set the default thumb size to NNNpx for this test
# wrap          include the normal wrapper <div class="mw-parser-output"> (since 1.30)
# local         format section links in edit comment text as local links
#
# Configuration globals:
#
#  wgEnableUploads, wgAllowExternalImages, wgMaxTocLevel,
#  wgLinkHolderBatchSize, wgRawHtml, wgInterwikiMagic,
#  wgEnableMagicLinks, wgLocaltimezone
#
# Test execution options:
#
# 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)
#
# For testing purposes, temporary articles can created:
# !!article / NAMESPACE:TITLE / !!text / ARTICLE TEXT / !!endarticle
# where '/' denotes a newline.

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

!!article
Foo
!!text
FOO
!!endarticle

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

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

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

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

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

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

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

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

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

!! article
Template:table_attribs_3
!! text
<noinclude>
|</noinclude>style{{=}}"background:&#35;f9f9f9;"|Foo
!! endarticle

!! article
Template:table_attribs_6
!! text
style="background: <nowiki>


red;</nowiki>" |
!! endarticle

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

!! article
File:Redirect to foobar.jpg
!! text
#REDIRECT[[File:Foobar.jpg]]
!! endarticle

# Use an entity in the name
!! article
Template:Foo–bar
!! text
foo
!! endarticle

###
### Basic tests
###

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

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

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

b (+2 nls)


c (+3 nls)



d (+4 nls)




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

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

b
----
a

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


b
----
a


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

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

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

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

   <!--boo-->

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

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


*b


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

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




=b=
!!html/php
<table>
<tbody><tr>
<td>x
</td></tr></tbody></table>
<p><br />
</p><p><br />
</p>
<div class="mw-heading mw-heading1"><h1 id="b">b</h1><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></div>
!!html/parsoid
<table>
<tbody>
<tr>
<td>x</td>
</tr>
</tbody>
</table>
<p><br/></p>
<p><br/></p>
<h1 id="b">b</h1>
!!end

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

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


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

## The attribute on the font tag is so Parsoid won't normalize it away
!! test
Non-html5 tags should be accepted
!! wikitext
<center>''foo''</center>
<big>''foo''</big>
<font style="123">''foo''</font>
<strike>''foo''</strike>
<tt>''foo''</tt>
!! html
<center><i>foo</i></center>
<p><big><i>foo</i></big>
<font style="123"><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
</p><p>&lt;b→&gt; doesn't terminate &lt;/b→&gt;
</p><p>&lt;bä&gt; doesn't terminate &lt;/bä&gt;
</p><p>&lt;boo&gt; doesn't terminate &lt;/boo&gt;
</p><p>&lt;s.foo&gt; doesn't terminate &lt;/s.foo&gt;
</p><p>&lt;sub-ID#1&gt;
</p>
!! end

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

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

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

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

###
### Special characters
###

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

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

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

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

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

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

sed abit.
  sed nullum.

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

sed abit.
  sed nullum.

:and a colon

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

sed abit.
  sed nullum.

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

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

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

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

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

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

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

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

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

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

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

!! test
T71950: 1. Put nowiki as close to cause as possible, even with non-quote escapable chars
!! options
parsoid=html2wt
!! html/parsoid
<p>This text: L'<a rel="mw:WikiLink" href="./Foo">Foo</a>
This text: L''<a rel="mw:WikiLink" href="./Foo">Foo</a>
This text: L'''<a rel="mw:WikiLink" href="./Foo">Foo</a>''</p>
!! wikitext
This text: L'[[Foo]]
This text: L<nowiki>''</nowiki>[[Foo]]
This text: L<nowiki>'''</nowiki>[[Foo]]<nowiki>''</nowiki>
!! end

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

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

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

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

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

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

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

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

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

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

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

!! test
French spacing and spans
!! wikitext
[[Test]] : <span>123</span>
« Test »<span>123</span>
!! html/php
<p><a href="/wiki/Test" title="Test">Test</a>&#160;: <span>123</span>
«&#160;Test&#160;»<span>123</span>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Test" title="Test" data-parsoid='{"stx":"simple","a":{"href":"./Test"},"sa":{"href":"Test"}}'>Test</a><span typeof="mw:DisplaySpace"> </span>: <span data-parsoid='{"stx":"html"}'>123</span>
«<span typeof="mw:DisplaySpace"> </span>Test<span typeof="mw:DisplaySpace"> </span>»<span data-parsoid='{"stx":"html"}'>123</span></p>
!! end

!! test
post-expand include size being exceeded
!! options
maxincludesize=30
!! wikitext
{{3x_on_newline|1234567890}}
!! html/php
<p><a href="/wiki/Template:3x_on_newline" title="Template:3x on newline">Template:3x on newline</a><!-- WARNING: template omitted, post-expand include size too large -->
</p>
!! html/parsoid+integrated
<p><a rel="mw:WikiLink" href="./Template:3x_on_newline" title="Template:3x on newline" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Template:3x_on_newline"},"sa":{"href":":Template:3x on newline"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"3x_on_newline","href":"./Template:3x_on_newline"},"params":{"1":{"wt":"1234567890"}},"i":0}}]}'>Template:3x on newline</a><span about="#mwt1"><!-- WARNING: template omitted, post&#x2D;expand include size too large --></span></p>
!! end

!! test
max template depth being reached
!! options
maxtemplatedepth=1
!! wikitext
{{1x with depth|too deep!}}
!! html/php
<p><span class="error">Template recursion depth limit exceeded (1)</span>
</p>
!! html/parsoid+integrated
<p><span class="error" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x with depth","href":"./Template:1x_with_depth"},"params":{"1":{"wt":"too deep!"}},"i":0}}]}'>Template recursion depth limit exceeded (1)</span></p>
!! end

!! test
multiple templates that are redirects
!! options
templates
!! wikitext
{{redirect to foo}}
{{redirect to foo}}
!! metadata
template=Template:Redirect_to_foo
template=Template:Foo
!! html/php
<p>FOO
FOO
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"redirect to foo","href":"./Template:Redirect_to_foo"},"params":{},"i":0}}]}'>FOO</span>
<span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"redirect to foo","href":"./Template:Redirect_to_foo"},"params":{},"i":0}}]}'>FOO</span></p>
!! end

!! test
Transclusion with a (stripped) fragment
!! options
templates
!! wikitext
{{Foo#bar}}
!! metadata
template=Template:Foo
!! html/php
<p>FOO
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Foo#bar","href":"./Template:Foo#bar"},"params":{},"i":0}}]}'>FOO</span></p>
!! 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

!! test
T17491: <ins>/<del> in blockquote (2)
!! 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

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



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



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



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

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

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

{{1x| 1 =
 c }}

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

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

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

{{1x| c 
}}

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

{{1x|
 e}}

{{1x|
*f}}

{{1x|
 }}g
!! html
<p>a 
</p><p>b 
</p>
<pre>c 
</pre>
<p><br />
</p>
<pre>d
</pre>
<p><br />
</p>
<pre>e
</pre>
<p><br />
</p>
<ul><li>f</li></ul>
<p><br />
</p>
<pre>g
</pre>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a "}},"i":0}}]}'>a</span></p>
<p><span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{1x|b}} "}},"i":0}}]}'>b </span></p>

<pre about="#mwt4" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":" c \n"}},"i":0}}]}'>c </pre><span about="#mwt4">
</span>

<pre about="#mwt5" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":" {{1x|d}}\n"}},"i":0}}]}'>d</pre><span about="#mwt5">
</span>

<span about="#mwt7" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n e"}},"i":0}}]}'>
</span><pre about="#mwt7">e</pre>

<ul about="#mwt8" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n*f"}},"i":0}}]}'><li>f</li></ul>

<span about="#mwt9" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n "}},"i":0}},"g"]}'>
</span><pre about="#mwt9">g</pre>
!! end

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

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

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

## wt2html only, since the bare {{ will get escaped when serializing
!! test
Templates: Target with an extension tag
!! options
parsoid=wt2html
!! wikitext
{{{{1x|1x}}<nowiki>hi</nowiki>|ho}}
!! html/php
<p>{{1xhi|ho}}
</p>
!! html/parsoid
<p>{{<span about="#mwt5" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"1x"}},"i":0}}]}'>1x</span><span typeof="mw:Nowiki">hi</span>|ho}}</p>
!! end

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

!! test
Parsoid: Pipes in external links in template parameter
!! wikitext
{{1x|[{{1x|http://example.com}} link]}}
!! html/php
<p><a rel="nofollow" class="external text" href="http://example.com">link</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" about="#mwt31" typeof="mw:Transclusion" class="external text" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[{{1x|http://example.com}} link]"}},"i":0}}]}'>link</a></p>
!! end

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

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

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

!! test
Templates: Don't escape already nowiki-escaped text in template parameters
!! options
parsoid=html2wt,wt2wt
!! wikitext
{{1x|foo<nowiki>|</nowiki>bar}}
{{1x|<nowiki>&lt;div&gt;</nowiki>}}
{{1x|<nowiki></nowiki>}}
!! html/php
<p>foo|bar
&lt;div&gt;

</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo<nowiki>|</nowiki>bar"}},"i":0}}]}'>foo</span><span typeof="mw:Nowiki" about="#mwt1">|</span><span about="#mwt1">bar</span>
<span typeof="mw:Transclusion mw:Nowiki" about="#mwt2" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"<nowiki>&amp;lt;div&amp;gt;</nowiki>"}},"i":0}}]}'><span typeof="mw:Entity">&lt;</span>div<span typeof="mw:Entity">&gt;</span></span>
<span typeof="mw:Transclusion mw:Nowiki" about="#mwt3" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"<nowiki></nowiki>"}},"i":0}}]}'></span>
</p>
!! end

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

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

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

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

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

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

[[Foo

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

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

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

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

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

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

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

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

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

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

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

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

!! test
Don't break on | in extension attribute in template
!! wikitext
{{1x|<tag name="hi|ho">ha</tag>}}
!! html/parsoid
<pre typeof="mw:Extension/tag mw:Transclusion" data-mw='{"name":"tag","attrs":{"name":"hi|ho"},"body":{"extsrc":"ha"},"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tag name=\"hi|ho\">ha&lt;/tag>"}},"i":0}}]}'>'ha'
array (
  'name' => 'hi|ho',
)</pre>
!! 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|&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">&#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"><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span></a> - empty non breaking space</p>
!! end

## Separate from the above because Parsoid normalizes the empty link away
!! test
Piped link with empty link text - 2
!! options
parsoid=wt2html
!! wikitext
[[Main Page| ]] - empty space
!! html/php
<p><a href="/wiki/Main_Page" title="Main Page"> </a> - empty space
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page" title="Main Page"> </a> - empty space</p>
!! end

!! test
Broken link
!! wikitext
[[Zigzagzogzagzig]]
!! html/php
<p><a href="/index.php?title=Zigzagzogzagzig&amp;action=edit&amp;redlink=1" class="new" title="Zigzagzogzagzig (page does not exist)">Zigzagzogzagzig</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Zigzagzogzagzig?action=edit&amp;redlink=1" title="Zigzagzogzagzig" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Zigzagzogzagzig"},"sa":{"href":"Zigzagzogzagzig"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Zigzagzogzagzig"]}}'>Zigzagzogzagzig</a></p>
!! end

# The PHP parser strips the hash fragment for non-existent pages, but
# Parsoid does not. (T227693)
!! test
Broken link with fragment
!! options
links
!! wikitext
[[Zigzagzogzagzig#zug]]
!! metadata
link=Zigzagzogzagzig
!! html/php
<p><a href="/index.php?title=Zigzagzogzagzig&amp;action=edit&amp;redlink=1" class="new" title="Zigzagzogzagzig (page does not exist)">Zigzagzogzagzig#zug</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Zigzagzogzagzig?action=edit&amp;redlink=1#zug" title="Zigzagzogzagzig" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Zigzagzogzagzig#zug"},"sa":{"href":"Zigzagzogzagzig#zug"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Zigzagzogzagzig"]}}'>Zigzagzogzagzig#zug</a></p>
!! end

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

# Parsoid does not strip fragment from red links: T227693
!! test
Nonexistent special page link with fragment
!! wikitext
[[Special:ThisNameWillHopefullyNeverBeUsed#anchor]]
!! html/php
<p><a href="/wiki/Special:ThisNameWillHopefullyNeverBeUsed" class="new" title="Special:ThisNameWillHopefullyNeverBeUsed (page does not exist)">Special:ThisNameWillHopefullyNeverBeUsed#anchor</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Special:ThisNameWillHopefullyNeverBeUsed?action=edit&amp;redlink=1#anchor" title="Special:ThisNameWillHopefullyNeverBeUsed" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Special:ThisNameWillHopefullyNeverBeUsed#anchor"},"sa":{"href":"Special:ThisNameWillHopefullyNeverBeUsed#anchor"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Special:ThisNameWillHopefullyNeverBeUsed"]}}'>Special:ThisNameWillHopefullyNeverBeUsed#anchor</a></p>
!! end

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

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

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

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

[[prefixed article|prefixed articlesaoeu]]

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


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

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

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

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

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

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

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

!! article
Talk:Parser testing
!! text
Dummy article to suppress redlinks in tests
!! end

!! article
Meta:Disclaimers
!! text
Dummy article to suppress redlinks in tests
!! end

!! test
Link to namespaces
!! wikitext
[[Talk:Parser testing]], [[Meta:Disclaimers]]
!! html/php
<p><a href="/wiki/Talk:Parser_testing" title="Talk:Parser testing">Talk:Parser testing</a>, <a href="/wiki/Meta:Disclaimers" title="Meta:Disclaimers">Meta:Disclaimers</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Talk:Parser_testing" title="Talk:Parser testing" data-parsoid='{"stx":"simple","a":{"href":"./Talk:Parser_testing"},"sa":{"href":"Talk:Parser testing"}}'>Talk:Parser testing</a>, <a rel="mw:WikiLink" href="./Meta:Disclaimers" title="Meta:Disclaimers" data-parsoid='{"stx":"simple","a":{"href":"./Meta:Disclaimers"},"sa":{"href":"Meta:Disclaimers"}}'>Meta:Disclaimers</a></p>
!! end

!! article
User talk:Foo bar
!! text
Dummy article to suppress redlinks in tests
!! end

!! test
Link with space in namespace
!! wikitext
[[User talk:Foo bar]]
!! html/php
<p><a href="/wiki/User_talk:Foo_bar" title="User talk:Foo bar">User talk:Foo bar</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./User_talk:Foo_bar" title="User talk:Foo bar" data-parsoid='{"stx":"simple","a":{"href":"./User_talk:Foo_bar"},"sa":{"href":"User talk:Foo bar"}}'>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/php
<p><a href="/wiki/Meta:Disclaimers" title="Meta:Disclaimers">The disclaimers</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Meta:Disclaimers" title="Meta:Disclaimers" data-parsoid='{"stx":"piped","a":{"href":"./Meta:Disclaimers"},"sa":{"href":"Meta:Disclaimers"}}'>The disclaimers</a></p>
!! end

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

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

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

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

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

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

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

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

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

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

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

[[Foo &amp; bar]]

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

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

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

!! article
Lista d''e paise d''o munno
!! text
Dummy article to suppress redlinks in tests
!! end

!! test
Link containing double-single-quotes '' (T6598)
!! wikitext
[[Lista d''e paise d''o munno]]
!! html/php
<p><a href="/wiki/Lista_d%27%27e_paise_d%27%27o_munno" title="Lista d&#39;&#39;e paise d&#39;&#39;o munno">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" data-parsoid='{"stx":"simple","a":{"href":"./Lista_d&apos;&apos;e_paise_d&apos;&apos;o_munno"},"sa":{"href":"Lista d&apos;&apos;e paise d&apos;&apos;o munno"}}'>Lista d''e paise d''o munno</a></p>
!! end

!! article
Cool "Gator"
!! text
Dummy article to suppress redlinks in tests
!! end

!! test
Link containing double quotes and spaces
!! wikitext
[[Cool "Gator"]]
!! html/php
<p><a href="/wiki/Cool_%22Gator%22" title="Cool &quot;Gator&quot;">Cool "Gator"</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href='./Cool_"Gator"' title='Cool "Gator"' data-parsoid='{"stx":"simple","a":{"href":"./Cool_\"Gator\""},"sa":{"href":"Cool \"Gator\""}}'>Cool "Gator"</a></p>
!! end

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

!! test
Link containing double-single-quotes '' in text (T6598 check)
!! wikitext
Some [[Link|pretty ''italics'' and stuff]]!
!! html/php
<p>Some <a href="/wiki/Link" title="Link">pretty <i>italics</i> and stuff</a>!
</p>
!! html/parsoid
<p>Some <a rel="mw:WikiLink" href="./Link" title="Link" data-parsoid='{"stx":"piped","a":{"href":"./Link"},"sa":{"href":"Link"}}'>pretty <i>italics</i> and stuff</a>!</p>
!! end

!! test
Link containing double-single-quotes '' in text embedded in italics (T6598 check)
!! wikitext
''Some [[Link|pretty ''italics'' and stuff]]!''
!! html/php
<p><i>Some <a href="/wiki/Link" title="Link">pretty <i>italics</i> and stuff</a>!</i>
</p>
!! html/parsoid
<p><i>Some <a rel="mw:WikiLink" href="./Link" title="Link" data-parsoid='{"stx":"piped","a":{"href":"./Link"},"sa":{"href":"Link"}}'>pretty <i>italics</i> and stuff</a>!</i></p>
!! end

!! article
''Pentecoste''
!! text
Dummy article to suppress redlinks in tests
!! end

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

[[''Pentecoste'']]

[[''Pentecoste''|Pentecoste]]

[[''Pentecoste''|''Pentecoste'']]
!! html/php
<p><span class="mw-default-size" typeof="mw:Error mw:File"><a href="/index.php?title=Special:Upload&amp;wpDestFile=Denys_Savchenko_%27%27Pentecoste%27%27.jpg" class="new" title="File:Denys Savchenko &#39;&#39;Pentecoste&#39;&#39;.jpg"><span class="mw-file-element mw-broken-media">File:Denys Savchenko <i>Pentecoste</i>.jpg</span></a></span>
</p><p><a href="/wiki/%27%27Pentecoste%27%27" title="&#39;&#39;Pentecoste&#39;&#39;">''Pentecoste''</a>
</p><p><a href="/wiki/%27%27Pentecoste%27%27" title="&#39;&#39;Pentecoste&#39;&#39;">Pentecoste</a>
</p><p><a href="/wiki/%27%27Pentecoste%27%27" title="&#39;&#39;Pentecoste&#39;&#39;"><i>Pentecoste</i></a>
</p>
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:Error mw:File" data-parsoid='{"optList":[]}' data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/Denys_Savchenko_''Pentecoste''.jpg"><span class="mw-file-element mw-broken-media" resource="./File:Denys_Savchenko_''Pentecoste''.jpg" data-parsoid='{"a":{"resource":"./File:Denys_Savchenko_&apos;&apos;Pentecoste&apos;&apos;.jpg"},"sa":{"resource":"File:Denys_Savchenko_&apos;&apos;Pentecoste&apos;&apos;.jpg"}}'>File:Denys Savchenko ''Pentecoste''.jpg</span></a></span></p>

<p><a rel="mw:WikiLink" href="./''Pentecoste''" title="''Pentecoste''" data-parsoid='{"stx":"simple","a":{"href":"./&apos;&apos;Pentecoste&apos;&apos;"},"sa":{"href":"&apos;&apos;Pentecoste&apos;&apos;"}}'>''Pentecoste''</a></p>

<p><a rel="mw:WikiLink" href="./''Pentecoste''" title="''Pentecoste''" data-parsoid='{"stx":"piped","a":{"href":"./&apos;&apos;Pentecoste&apos;&apos;"},"sa":{"href":"&apos;&apos;Pentecoste&apos;&apos;"}}'>Pentecoste</a></p>

<p><a rel="mw:WikiLink" href="./''Pentecoste''" title="''Pentecoste''" data-parsoid='{"stx":"piped","a":{"href":"./&apos;&apos;Pentecoste&apos;&apos;"},"sa":{"href":"&apos;&apos;Pentecoste&apos;&apos;"}}'><i>Pentecoste</i></a></p>
!! end

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

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

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

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

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

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

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

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

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

!! test
Nested wikilink syntax in wikilink syntax that parses as wikilink in extlink
!! options
parsoid=wt2html
!! wikitext
[[http://example.com|[[Example]]]]
!! html/php
<p>[<a rel="nofollow" class="external text" href="http://example.com%7C"></a><a href="/wiki/Example" title="Example">Example</a>]
</p>
!! html/parsoid
<p>[<a rel="mw:ExtLink nofollow" href="http://example.com%7C" class="external autonumber" data-parsoid='{"a":{"href":"http://example.com%7C"},"sa":{"href":"http://example.com|"}}'></a><a rel="mw:WikiLink" href="./Example" title="Example" data-parsoid='{"stx":"simple","a":{"href":"./Example"},"sa":{"href":"Example"},"misnested":true}'>Example</a>]</p>
!! end

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

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

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

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

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

<p>{{1x|[<a rel="mw:ExtLink" href="http://www.example.com" class="external text">|123</a>}}</p>

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

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

!! 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/parsoid
<p><a rel="mw:WikiLink" href="./Bug462" class="mw-selflink selflink" data-parsoid='{"stx":"simple","a":{"href":"./Bug462"},"sa":{"href":"Bu&amp;#103;462"}}'>Bug462</a> <a rel="mw:WikiLink" href="./Bug462" class="mw-selflink selflink" data-parsoid='{"stx":"simple","a":{"href":"./Bug462"},"sa":{"href":"Bug462"}}'>Bug462</a></p>
!! end

!! test
Self-link to section should not be bold
!! options
title=[[Main Page]]
!! wikitext
[[Main Page#section]]
!! html/php
<p><a class="mw-selflink-fragment" href="#section">Main Page#section</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page#section" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#section"},"sa":{"href":"Main Page#section"}}'>Main Page#section</a></p>
!! end


!! test
Self-link hash fragment should be escaped
!! options
title=[[Main Page]]
!! wikitext
[[Main Page#section with spaces]]
!! html/php
<p><a class="mw-selflink-fragment" href="#section_with_spaces">Main Page#section with spaces</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Main_Page#section_with_spaces" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Main_Page#section_with_spaces"},"sa":{"href":"Main Page#section with spaces"}}'>Main Page#section with spaces</a></p>
!! end

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

!!test
Self-link to numeric title
!!options
title=[[0]]
!! wikitext
[[0]]
!! html/php
<p><a class="mw-selflink selflink">0</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./0" class="mw-selflink selflink" data-parsoid='{"stx":"simple","a":{"href":"./0"},"sa":{"href":"0"}}'>0</a></p>
!!end

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

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

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

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

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

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

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

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

!! test
Internal link with en linktrail: no apostrophes (T29473)
!! options
language=en
!! wikitext
[[Something]]'nice
!! html/php
<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>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Something?action=edit&amp;redlink=1" title="Something" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Something"},"sa":{"href":"Something"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Something"]}}'>Something</a>'nice</p>
!! end

!! test
Internal link with ca linktrail with apostrophes (T29473)
!! options
language=ca
!! wikitext
[[Something]]'nice
!! html/php
<p><a href="/index.php?title=Something&amp;action=edit&amp;redlink=1" class="new" title="Something (encara no existeix)">Something'nice</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Something?action=edit&amp;redlink=1" title="Something" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Something"},"sa":{"href":"Something"},"tail":"&apos;nice"}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Something"]}}'>Something'nice</a></p>
!! end

!! test
Internal link with kaa linktrail with apostrophes (T29473)
!! options
language=kaa
!! wikitext
[[Something]]'nice
!! html/php
<p><a href="/index.php?title=Something&amp;action=edit&amp;redlink=1" class="new" title="Something (bet ele jaratılmaǵan)">Something'nice</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Something?action=edit&amp;redlink=1" title="Something" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Something"},"sa":{"href":"Something"},"tail":"&apos;nice"}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Something"]}}'>Something'nice</a></p>
!! end

!! article
User:Foo/Test/63636:Bar
!! text
Dummy article to suppress redlinks in tests
!! end

!! test
Link with multiple ":" in a subpage-supporting namespace (T65636)
!! wikitext
[[User:Foo/Test/63636:Bar|Test]]
!! html/php
<p><a href="/wiki/User:Foo/Test/63636:Bar" title="User:Foo/Test/63636:Bar">Test</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./User:Foo/Test/63636:Bar" title="User:Foo/Test/63636:Bar" data-parsoid='{"stx":"piped","a":{"href":"./User:Foo/Test/63636:Bar"},"sa":{"href":"User:Foo/Test/63636:Bar"}}'>Test</a></p>
!! end

## Mainly a 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" class="mw-selflink-fragment" data-parsoid='{"stx":"piped","a":{"href":"./User:Test/123#a"},"sa":{"href":"#a"}}'>b</a></p>
!! end

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

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

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

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

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

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

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

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

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

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

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

!! test
2. Interaction of linktrail and template encapsulation
!! wikitext
{{1x|Some [[Fool]]}}s
!! html/php
<p>Some <a href="/wiki/Fool" title="Fool">Fools</a>
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Some [[Fool]]"}},"i":0}},"s"]}'>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
!! wikitext
{{1x|Some [[Fool]]s are '''bold and foolish'''}}
!! html/php
<p>Some <a href="/wiki/Fool" title="Fool">Fools</a> are <b>bold and foolish</b>
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Some [[Fool]]s are &apos;&apos;&apos;bold and foolish&apos;&apos;&apos;"}},"i":0}}]}'>Some </span><a rel="mw:WikiLink" href="./Fool" title="Fool" about="#mwt1">Fools</a><span about="#mwt1"> are </span><b about="#mwt1">bold and foolish</b></p>
!! end

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

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

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

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

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

!! test
Parsoid link prefix escaping
!! options
language=is
parsoid=html2wt,html2html
!! html/parsoid
<p>Aðrir mótmælenda<a rel="mw:WikiLink" href="./Söfnuður" title="Söfnuður">söfnuður</a></p>
!! wikitext
Aðrir mótmælenda<nowiki/>[[söfnuður]]
!! end

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

[<nowiki/>[[Test]]]

[[[[Test]]]]

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

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

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

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

[[Foo|  ''bar'']]

[http://wp.org   foo]

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

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

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

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

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

!! test
Wikilink in wikilink
!! wikitext
[[Hi|[[Ho]]]]
!! html/php
<p>[[Hi|<a href="/wiki/Ho" title="Ho">Ho</a>]]
</p>
!! html/parsoid
<p>[[Hi|<a rel="mw:WikiLink" href="./Ho" title="Ho" data-parsoid='{"stx":"simple","a":{"href":"./Ho"},"sa":{"href":"Ho"}}'>Ho</a>]]</p>
!! end


!! test
Parsoid-specific test: Wikilinks with &nbsp; should RT properly
!! options
language=ln
!! wikitext
[[WW&nbsp;II]]
!! html/php
<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>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./WW_II?action=edit&amp;redlink=1" title="WW II" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./WW_II"},"sa":{"href":"WW&amp;nbsp;II"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["WW II"]}}'>WW 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

!! article
16:30
!! text
Dummy article to suppress redlinks in tests
!! end

!! test
Wikilinks with : should roundtrip correctly, with and without redlinks
!! wikitext
[[16:30]]
[[18:30]]
!! html/parsoid
<p><a rel="mw:WikiLink" href="./16:30" title="16:30" data-parsoid='{"stx":"simple","a":{"href":"./16:30"},"sa":{"href":"16:30"}}'>16:30</a>
<a rel="mw:WikiLink" href="./18:30?action=edit&amp;redlink=1" title="18:30" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./18:30"},"sa":{"href":"18:30"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["18:30"]}}'>18:30</a></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?action=edit&amp;redlink=1" title="Constructor" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Constructor"},"sa":{"href":"constructor"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Constructor"]}}'>constructor</a></p>

<p><a rel="mw:WikiLink" href="./Constructor:foo?action=edit&amp;redlink=1" title="Constructor:foo" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Constructor:foo"},"sa":{"href":"constructor:foo"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Constructor:foo"]}}'>constructor:foo</a></p>
!! end

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

##
## XHTML tidiness
###

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

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

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

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

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

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

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

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

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

<div class= / "123">ha</div>
!! html/php
<div>ha</div>
<div class="123">ha</div>
<div class="/">ha</div>
!! html/parsoid
<div data-parsoid='{"stx":"html","a":{"cla":null,"ss":null},"sa":{"cla":"","ss":"123"}}'>ha</div>

<div class="123" data-parsoid='{"stx":"html"}'>ha</div>

<div class="/" data-parsoid='{"stx":"html","a":{"\"123\"":null},"sa":{"\"123\"":""}}'>ha</div>
!! end

!! test
Handling html with a br self-closing tag
!! wikitext
<br title />
<br title/>
<br title/ >
<br title=bar />
<br title=bar/>
<br title=bar/ >
!! html/php
<p><br title="" />
<br title="" />
<br title="" />
<br title="bar" />
<br title="bar" />
<br title="bar/" />
</p>
!! html/parsoid
<p><br title="" />
<br title="" />
<br title="" />
<br title="bar" />
<br title="bar" />
<br title="bar/" />
</p>
!! end

!! test
Quoted attributes without spaces
!! options
parsoid=wt2html
!! wikitext
<div class="foo"style="color:red">red</div>
!! html/php
<div class="foo" style="color:red">red</div>
!! html/parsoid
<div class="foo" style="color:red">red</div>
!! end

!! test
Horizontal ruler (should it add that extra space?)
!! wikitext
<hr>
<hr >
foo <hr
> bar
!! html/php
<hr />
<hr /><p>
foo </p><hr /><p> bar</p>
!! html/parsoid
<hr data-parsoid='{"stx":"html","noClose":true}'/>
<hr data-parsoid='{"stx":"html","noClose":true}'/><p>
foo </p><hr data-parsoid='{"stx":"html","noClose":true}'/><p> bar</p>
!! end

!! test
Horizontal ruler -- 4+ dashes render hr
!! wikitext
----
!! html
<hr />
!! end

!! test
Horizontal ruler -- eats additional dashes on the same line
!! wikitext
---------
!! html
<hr />
!! end

!! test
Horizontal ruler -- does not collapse dashes on consecutive lines
!! wikitext
----
----
!! html
<hr />
<hr />
!! end

!! test
Horizontal ruler -- <4 dashes render as plain text
!! wikitext
---
!! html
<p>---
</p>
!! end

!! test
Horizontal ruler -- Supports content following dashes on same line
!! wikitext
---- Foo
!! html/php
<hr /><p> Foo</p>
!! html/parsoid
<hr data-parsoid='{"lineContent":true}'/><p> Foo</p>
!! end

###
### Block-level elements
###
!! test
Common list
!! wikitext
*Common list
*item 2
*item 3
!! html
<ul><li>Common list</li>
<li>item 2</li>
<li>item 3</li></ul>
!! end

!! test
Numbered list
!! wikitext
#Numbered list
#item 2
#item 3
!! html
<ol><li>Numbered list</li>
<li>item 2</li>
<li>item 3</li></ol>
!! end

# the switch from level 3 to ordered should not introduce a newline between
!! test
Mixed list
!! wikitext
*Mixed list
*#with numbers
**and bullets
*#and numbers
*bullets again
**bullet level 2
***bullet level 3
***#Number on level 4
**bullet level 2
**#Number on level 3
**#Number on level 3
*#number level 2
*Level 1
***Level 3
#**Level 3, but ordered
!! html
<ul><li>Mixed list
<ol><li>with numbers</li></ol>
<ul><li>and bullets</li></ul>
<ol><li>and numbers</li></ol></li>
<li>bullets again
<ul><li>bullet level 2
<ul><li>bullet level 3
<ol><li>Number on level 4</li></ol></li></ul></li>
<li>bullet level 2
<ol><li>Number on level 3</li>
<li>Number on level 3</li></ol></li></ul>
<ol><li>number level 2</li></ol></li>
<li>Level 1
<ul><li><ul><li>Level 3</li></ul></li></ul></li></ul>
<ol><li><ul><li><ul><li>Level 3, but ordered</li></ul></li></ul></li></ol>
!! end

!! test
1. Nested mixed wikitext and html list
!! wikitext
*hi
*<ul><li>ho</li></ul>
*hi
**ho
!! html/php
<ul><li>hi</li>
<li><ul><li>ho</li></ul></li>
<li>hi
<ul><li>ho</li></ul></li></ul>
!! html/parsoid
<ul><li>hi</li>
<li><ul data-parsoid='{"stx":"html"}'><li data-parsoid='{"stx":"html"}'>ho</li></ul></li>
<li>hi
<ul><li>ho</li></ul></li></ul>
!! end

!! test
2. Nested mixed wikitext and html list (incompatible)
!! wikitext
;hi
:{{1x|<li>ho</li>}}
!! html/php
<dl><dt>hi</dt>
<dd><li>ho</li></dd></dl>
!! html/parsoid
<dl><dt>hi</dt>
<dd><li about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>ho&lt;/li>"}},"i":0}}]}'>ho</li></dd></dl>
!! end

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

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

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

!! test
Nested lists 4 (first element empty)
!! wikitext
**
*bar
!! html
<ul><li><ul><li class="mw-empty-elt"></li></ul></li>
<li>bar</li></ul>
!! end

!! test
Nested lists 5 (both elements empty)
!! wikitext
**
*
!! html
<ul><li><ul><li class="mw-empty-elt"></li></ul></li>
<li class="mw-empty-elt"></li></ul>
!! end

!! test
Nested lists 6 (both elements empty)
!! wikitext
*
**
!! html
<ul><li>
<ul><li class="mw-empty-elt"></li></ul></li></ul>
!! end

!! test
Nested lists 7 (skip initial nesting levels)
!! wikitext
***foo
!! html
<ul><li><ul><li><ul><li>foo</li></ul></li></ul></li></ul>
!! end

!! test
Nested lists 8 (multiple nesting transitions)
!! wikitext
*foo
***bar
**baz
*boo
!! html
<ul><li>foo
<ul><li><ul><li>bar</li></ul></li>
<li>baz</li></ul></li>
<li>boo</li></ul>
!! end

!! test
Nested lists 9 (extension interaction)
!! wikitext
*<tag />
!! html/php
<ul><li><pre></pre></li></ul>
<p>NULL
array (
)
</p>
!! html/parsoid
<ul><li data-parsoid='{}'><pre typeof="mw:Extension/tag" about="#mwt2" data-parsoid='{"dsr":[1,8,7,0]}' data-mw='{"name":"tag","attrs":{}}'>NULL
array (
)
</pre></li></ul>
!! end

!! test
Nested lists 10 (list and span siblings: wt2wt regression)
!! wikitext
*a <span>x</span>
**b <span>y</span>
!! html/parsoid
<ul><li>a <span>x</span>
<ul><li>b <span>y</span></li></ul></li></ul>
!! end

!! test
Nested lists 11 (T262409: trailing whitespace & selser)
!! options
parsoid={
  "modes": ["wt2html","selser"],
  "changes": [
    [ "ul > li > ul > li > ul > li", "after", "<li>b-new</li>" ]
  ]
}
!! wikitext
**a
***b  
!! html/parsoid
<ul><li><ul><li>a
<ul><li>b</li></ul></li></ul></li></ul>
!! wikitext/edited
**a
***b  
*** b-new
!! end

!! test
1. Lists and block-element interaction
!! options
parsoid=wt2html,selser
!! wikitext
*<div>a
*b
</div>ಕ
!! html/php
<ul><li><div>a</div></li>
<li>b</li></ul>
<p>ಕ</p>
!! html/parsoid
<ul><li><div data-parsoid='{"stx":"html","autoInsertedEnd":true}'>a</div></li>
<li>b</li></ul>
<p>ಕ</p>
!! end

!! test
2. Lists and block-element interaction
!! options
parsoid=wt2html,selser
!! wikitext
*{{1x|<div>a
*b
}}</div>ಕ
!! html/php
<ul><li><div>a</div></li>
<li>b</li></ul>
<p>ಕ</p>
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"firstWikitextNode":"UL","pi":[[{"k":"1"}]]}' data-mw='{"parts":["*",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>a\n*b\n"}},"i":0}}]}'><li><div>a</div></li>
<li>b</li></ul><span about="#mwt1">
</span><p>ಕ</p>
!! end

!! test
1. Lists with start-of-line-transparent tokens before bullets: Comments
!! wikitext
*foo
*<!--cmt-->bar
<!--cmt-->*baz
!! html
<ul><li>foo</li>
<li>bar</li>
<li>baz</li></ul>
!! html/parsoid
<ul><li>foo</li>
<li><!--cmt-->bar</li>
<!--cmt--><li>baz</li></ul>
!! end

# Parsoid handles this case differently from the legacy parser, as a side
# effect of handling SOL state in the tokenizer.
!! test
2. Lists with start-of-line-transparent tokens before bullets: Template close
!! wikitext
*foo {{1x|bar
}}*baz
!! html/php
<ul><li>foo bar</li>
<li>baz</li></ul>
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"firstWikitextNode":"UL","pi":[[{"k":"1"}]]}' data-mw='{"parts":["*foo ",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"bar\n"}},"i":0}}]}'><li>foo bar</li><li about="#mwt1">
baz</li></ul>
!! end

!! test
List items are not parsed correctly following a <pre> block (T2785)
!! wikitext
*<pre>foo</pre>
*<pre>bar</pre>
*zar
!! html/php
<ul><li><pre>foo</pre></li>
<li><pre>bar</pre></li>
<li>zar</li></ul>
!! html/parsoid
<ul><li><pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"foo"}}'>foo</pre></li>
<li><pre typeof="mw:Extension/pre" about="#mwt4" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"bar"}}'>bar</pre></li>
<li>zar</li></ul>
!! end

!! test
List items from template
!! wikitext

{{inner list}}
*item 2

*item 0
{{inner list}}
*item 2

*item 0
*notSOL{{inner list}}
*item 2
!! html/php
<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>
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"inner list","href":"./Template:Inner_list"},"params":{},"i":0}},"\n*item 2"]}'><li>item 1</li>
<li>item 2</li></ul>

<ul><li>item 0</li>
<li about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"inner list","href":"./Template:Inner_list"},"params":{},"i":0}}]}'>item 1</li>
<li>item 2</li></ul>

<ul><li>item 0</li>
<li>notSOL</li><span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"inner list","href":"./Template:Inner_list"},"params":{},"i":0}}]}'>
</span><li about="#mwt3">item 1</li>
<li>item 2</li></ul>
!! end

!! test
List interrupted by empty line or heading
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
*foo

**bar
==A heading==
*Another list item
!! html
<ul><li>foo</li></ul>
<ul><li><ul><li>bar</li></ul></li></ul>
<div class="mw-heading mw-heading2"><h2 id="A_heading">A heading</h2><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></div>
<ul><li>Another list item</li></ul>
!! html/parsoid
<ul><li>foo</li></ul>

<ul><li><ul><li>bar</li></ul></li></ul>
<h2 id="A_heading">A heading</h2>
<ul><li>Another list item</li></ul>
!!end

!! test
Multiple list tags generated by templates
!! wikitext
{{1x|<li>}}a
{{1x|<li>}}b
{{1x|<li>}}c
!! html/php
<li>a
</li><li>b
</li><li>c</li>
!! html/parsoid
<li about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>"}},"i":0}},"a"]}'>a</li>
<li about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>"}},"i":0}},"b"]}'>b</li>
<li about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>"}},"i":0}},"c"]}'>c</li>
!! end

!! test
Multiple newlines in between HTML list items don't induce paragraph wrapping
!! wikitext
<ul>
<li>hi</li>




<li>ho</li>
</ul>

<dl>
<dt>hi</dt>
<dd>ho<div>123</div>
</dd>


</dl>
!! html/php
<ul>
<li>hi</li>




<li>ho</li>
</ul>
<dl>
<dt>hi</dt>
<dd>ho<div>123</div>
</dd>


</dl>
!! end

!!test
Single-comment whitespace lines dont break lists, and neither do multi-comment whitespace lines
!! wikitext
*a
<!--This line will NOT split the list-->
*b
 <!--This line will NOT split the list either-->
*c
 <!--foo--> <!----> <!--This line NOT split the list either--> 
*d
!! html
<ul><li>a</li>
<li>b</li>
<li>c</li>
<li>d</li></ul>
!!end

!!test
Replacing whitespace with tabs still doesn't break the list (gerrit 78327)
!! wikitext
*a
<!--This line will NOT split the list-->	
*b
	<!--This line will NOT split the list either--> 	
*c
	<!--foo--> <!---->	<!--This line NOT split the list
        either-->	 
*d
!! html
<ul><li>a</li>
<li>b</li>
<li>c</li>
<li>d</li></ul>
!!end

## FIXME: This test could possibly be renamed / simplified since this is
## no longer a hack and works as expected without any special handling.
!!test
Test the li-hack (a hack from Tidy days, but doesn't work as advertised with Remex)
!!options
parsoid=wt2html,wt2wt
!! wikitext
*foo
*<li>li-hack
**bar1
*{{1x|<li>templated li-hack}}
**bar2
*<!--foo--><li> unsupported li-hack with preceding comments

<ul>
<li><li>not a li-hack
</li>
</ul>
!! html/php
<ul><li>foo</li>
<li class="mw-empty-elt"></li><li>li-hack
<ul><li>bar1</li></ul></li>
<li class="mw-empty-elt"></li><li>templated li-hack
<ul><li>bar2</li></ul></li>
<li class="mw-empty-elt"></li><li> unsupported li-hack with preceding comments</li></ul>
<ul>
<li class="mw-empty-elt"></li><li>not a li-hack
</li>
</ul>
!! html/parsoid
<ul><li>foo</li>
<li class="mw-empty-elt"></li><li data-parsoid='{"stx":"html","autoInsertedEnd":true}'>li-hack
<ul><li>bar1</li></ul></li>
<li class="mw-empty-elt"></li><li about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;li>templated li-hack"}},"i":0}},"\n**bar2"]}'>templated li-hack
<ul><li>bar2</li></ul></li>
<li class="mw-empty-elt"><!--foo--></li><li data-parsoid='{"stx":"html","autoInsertedEnd":true}'> unsupported li-hack with preceding comments</li></ul>

<ul data-parsoid='{"stx":"html"}'>
<li class="mw-empty-elt" data-parsoid='{"stx":"html","autoInsertedEnd":true}'></li><li data-parsoid='{"stx":"html"}'>not a li-hack
</li>
</ul>
!! end

!! test
Parsoid: Make sure nested lists are serialized on their own line even if HTML contains no newlines
!! wikitext
#foo
##bar

*foo
**bar

:foo
::bar
!! html/php
<ol><li>foo
<ol><li>bar</li></ol></li></ol>
<ul><li>foo
<ul><li>bar</li></ul></li></ul>
<dl><dd>foo
<dl><dd>bar</dd></dl></dd></dl>
!! html/parsoid
<ol>
<li>foo<ol>
<li>bar</li>
</ol></li>
</ol><ul>
<li>foo<ul>
<li>bar</li>
</ul></li>
</ul><dl>
<dd>foo<dl>
<dd>bar</dd>
</dl></dd>
</dl>
!! end

!! test
Parsoid: Test of whitespace serialization with Templated bullets
!! options
parsoid=wt2html
!! wikitext
* {{bullet}}
!! html/php
<ul><li class="mw-empty-elt"></li>
<li>Bar</li></ul>
!! html/parsoid
<ul><li class="mw-empty-elt"></li><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bullet","href":"./Template:Bullet"},"params":{},"i":0}}]}'>
</span><li about="#mwt1">Bar</li></ul>
!! end

# ------------------------------------------------------------------------
# The next set of tests are about Parsoid's ability to handle badly nested
# tags (parse, minimize scope of fixup, and roundtrip back)
# ------------------------------------------------------------------------

!! test
Unbalanced closing block tags break a list
!! wikitext
<div>
*a</div><div>
*b</div>
!! html/php
<div>
<ul><li>a</li></ul></div><div>
<li>b</li></div>
!! html/parsoid
<div><ul>
<li>a</li>
</ul></div>
<div><ul>
<li>b</li>
</ul></div>
!! end

## We call this "wikitext block" because we're diverging a bit from the HTML5
## parsing spec.  Remex output is because it doesn't need to generate the
## implied end tag for the list item when encountering the closing </p> but
## Parsoid's broader definition opts to.  This can happen for a number of other
## tags but those aren't allowed literal tags in wikitext.  There's also the
## opposite problem, where the wikitext blocks aren't a superset of the tags
## that generate implied ends in HTML5, but the missing ones again aren't
## allowed literal tags in wikitext.
!! test
Unbalanced closing wikitext block tags break a list
!! wikitext
<p>
*a</p><p>
*b</p>
!! html/php
<p class="mw-empty-elt">
</p><ul><li>a<p class="mw-empty-elt"></p><p class="mw-empty-elt"></p></li>
<li>b<p class="mw-empty-elt"></p></li></ul>
!! html/parsoid
<p class="mw-empty-elt" data-parsoid='{"stx":"html","autoInsertedEnd":true}'></p>
<ul><li>a</li></ul><p class="mw-empty-elt" data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p><p class="mw-empty-elt" data-parsoid='{"stx":"html","autoInsertedEnd":true}'></p>
<ul><li>b</li></ul><p class="mw-empty-elt" data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p>
!! end

!! test
Unbalanced closing non-block tags don't break a list
!! options
parsoid=wt2html,html2html
!! wikitext
<span>
*a</span><span>
*b</span>
!! html/php
<p><span>
</span></p>
<ul><li>a<span></span></li>
<li>b</li></ul>
!! html/parsoid
<p><span data-parsoid='{"stx":"html","autoInsertedEnd":true}'></span></p>
<ul><li>a<meta typeof="mw:Placeholder/StrippedTag" data-parsoid='{"src":"&lt;/span>","name":"span"}'/><span data-parsoid='{"stx":"html","autoInsertedEnd":true}'></span></li>
<li>b<meta typeof="mw:Placeholder/StrippedTag" data-parsoid='{"src":"&lt;/span>","name":"span"}'/></li></ul>
!! end

## The legacy parser output matches the HTML5 spec, the token is ignored.
## Parsoid's ListHandler doesn't track open elements outside of the list frame
## so the token induces an implied end to the list.  Considering that Parsoid
## already diverges from the HTML5 spec in which tag names induce implied ends
## (see the discussion above about "wikitext block"), we accept this edge case
## as a known difference.
!! test
T368721: Closing block tags not on the stack of open elements in lists
!! wikitext
<!-- block tag  -->
*a</div>b

<!-- wikitext block tag -->
*a</p>b
!! html/php
<ul><li>ab</li></ul>
<ul><li>a<p class="mw-empty-elt"></p>b</li></ul>
!! html/parsoid
<!-- block tag  -->
<ul><li>a</li></ul><p>b</p>

<!-- wikitext block tag -->
<ul><li>a</li></ul><p class="mw-empty-elt" data-parsoid='{"autoInsertedStart":true,"stx":"html"}'></p><p>b</p>
!! end

# Parsoid does some post-dom-building cleanup
# which is why its output differs from Remex.
!! test
Unclosed formatting tags that straddle lists are closed and reopened
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
#<s> a
#b </s>
!! html/php
<ol><li><s> a</s></li><s>
</s><li><s>b </s></li></ol>
!! html/parsoid
<ol><li><s> a</s></li>
<li><s>b </s></li></ol>
!! end

# Output is ugly because of all the misnested tag fixups.
!! test
1. List embedded in a formatting tag
!! wikitext
<small>
*foo
</small>
!! html/php
<p><small>
</small></p><small><ul><li>foo</li></ul></small><small></small><p><small></small>
</p>
!! html/parsoid
<p><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'></small></p><small data-parsoid='{"stx":"html","autoInsertedEnd":true,"autoInsertedStart":true}'>
<ul><li data-parsoid='{}'>foo</li></ul></small>
<p><small data-parsoid='{"stx":"html","autoInsertedStart":true}'></small></p>
!! end

# Output is ugly because of all the misnested tag fixups.
!! test
2. List embedded in a formatting tag in a misnested way
!! wikitext
<small>
*a
*b</small>
!! html/php
<p><small>
</small></p><small></small><ul><small><li>a</li>
</small><li><small>b</small></li></ul>
!! html/parsoid
<p><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'></small></p>
<ul><small data-parsoid='{"stx":"html","autoInsertedEnd":true,"autoInsertedStart":true}'><li>a</li></small>
<li><small data-parsoid='{"stx":"html","autoInsertedStart":true}'>b</small></li></ul>
!! end

# Output is ugly because of all the misnested tag fixups.
!! test
3. List embedded in a formatting tag in a misnested way
!! wikitext
<small>

** 123</small>
!! html/php
<p><small>
</small></p><small></small><ul><small></small><li><small></small><ul><small></small><li><small>123</small></li></ul></li></ul>
!! html/parsoid
<p><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'></small></p>

<ul><li><ul><li data-parsoid='{}'><small data-parsoid='{"stx":"html","autoInsertedStart":true}'> 123</small></li></ul></li></ul>
!! end

!! test
Parsoid: unknown parser function (T314524)
!! wikitext
{{#tag:b|This is a known parser function}}

Now show the unknown parser functions for comparison.

{{#foo}}

{{#foo:bar|bat}}
!! html/php
<p><b>This is a known parser function</b>
</p><p>Now show the unknown parser functions for comparison.
</p><p>{{#foo}}
</p><p>{{#foo:bar|bat}}
</p>
!! html/parsoid+standalone
<p><b typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#tag:b","function":"tag"},"params":{"1":{"wt":"This is a known parser function"}},"i":0}}]}'>This is a known parser function</b></p>
<p>Now show the unknown parser functions for comparison.</p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#foo","function":"foo"},"params":{},"i":0}}]}'>Parser function implementation for pf_foo missing in Parsoid.</span></p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#foo:bar","function":"foo"},"params":{"1":{"wt":"bat"}},"i":0}}]}'>Parser function implementation for pf_foo missing in Parsoid.</span></p>
!! html/parsoid+integrated
<p><b typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#tag:b","function":"tag"},"params":{"1":{"wt":"This is a known parser function"}},"i":0}}]}'>This is a known parser function</b></p>
<p>Now show the unknown parser functions for comparison.</p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#foo","function":"foo"},"params":{},"i":0}}]}'>{{#foo}}</span></p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#foo:bar","function":"foo"},"params":{"1":{"wt":"bat"}},"i":0}}]}'>{{#foo:bar|bat}}</span></p>
!! end

# From plwiki:PLOS_ONE
!! test
Parsoid: Page property magic word with magic word contents
!! options
showtitle
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! wikitext
{{DISPLAYTITLE:''{{PAGENAME}}''}}
!! metadata
<i>Parser test</i>
!! html/php
!! html/parsoid+integrated
<span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:&apos;&apos;{{PAGENAME}}&apos;&apos;","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

# NOTE: mw:ExpandedAttrs is not the best typeof here. mw:Transclusion is better.
# But, this is a limitation of our representation and is documented in
# TemplateHandler.php in processSpecialMagicWord
!! test
Parsoid: Template-generated DISPLAYTITLE
!! wikitext
{{{{1x|DISPLAYTITLE}}:Foo}}
!! options
showtitle
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! metadata
Foo
!! html/php
!! html/parsoid+integrated
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|DISPLAYTITLE}}:Foo","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

# Can be removed when T335843 is addressed
!! test
Parsoid html2wt b/c check: Cached Parsoid HTML for DISPLAYTITLE should be handled properly
!! options
parsoid=html2wt
!! html/parsoid
<meta property='mw:PageProp/displaytitle' content='foo'/>
<meta property="mw:PageProp/displaytitle" content="Parser test" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"src":"{{DISPLAYTITLE:&#39;&#39;{{PAGENAME}}&#39;&#39;}}"}' data-mw='{"attribs":[[{"txt":"content"},{"html":"DISPLAYTITLE:&lt;i data-parsoid=&#39;{\"dsr\":[15,31,2,2]}&#39;>&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[17,29,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"PAGENAME\",\"function\":\"pagename\"},\"params\":{},\"i\":0}}]}&#39;>Parser test&lt;/span>&lt;/i>"}]]}'/>
<meta property="mw:PageProp/displaytitle" content="Foo" about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"content"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[2,23,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"DISPLAYTITLE\"}},\"i\":0}}]}&#39;>DISPLAYTITLE&lt;/span>:Foo"}]]}'/>
!! wikitext
{{DISPLAYTITLE:foo}}
{{DISPLAYTITLE:''{{PAGENAME}}''}}
{{{{1x|DISPLAYTITLE}}:Foo}}
!! end

!! test
Namespace 1 {{ns:1}}
!! wikitext
{{ns:1}}
!! html/php
<p>Talk
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"ns:1","function":"ns"},"params":{},"i":0}}]}'>Talk</span></p>
!! end

!! test
Namespace 1 {{ns:01}}
!! wikitext
{{ns:01}}
!! html/php
<p>Talk
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"ns:01","function":"ns"},"params":{},"i":0}}]}'>Talk</span></p>
!! end

!! test
Namespace 0 {{ns:0}} (T6783)
!! wikitext
{{ns:0}}
!! html/php
!! html/parsoid+integrated
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"ns:0","function":"ns"},"params":{},"i":0}}]}'></span>
!! end

!! test
Namespace 0 {{ns:00}} (T6783)
!! wikitext
{{ns:00}}
!! html/php
!! html/parsoid+integrated
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"ns:00","function":"ns"},"params":{},"i":0}}]}'></span>
!! end

!! test
Namespace -1 {{ns:-1}}
!! wikitext
{{ns:-1}}
!! html/php
<p>Special
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"ns:-1","function":"ns"},"params":{},"i":0}}]}'>Special</span></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
__proto__ is treated as normal wikitext (T105997)
!!wikitext
__proto__
!!html
<p>__proto__
</p>
!!end

###
### Templates
####

!! test
Template titles with entities in them
!! wikitext
*{{Foo–bar}}
*{{Foo&ndash;bar}}
!! html/php
<ul><li>foo</li>
<li>foo</li></ul>
!! html/parsoid
<ul>
<li data-parsoid="{}"><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Foo–bar","href":"./Template:Foo–bar"},"params":{},"i":0}}]}'>foo</span></li>
<li data-parsoid="{}"><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Foo&amp;ndash;bar","href":"./Template:Foo–bar"},"params":{},"i":0}}]}'>foo</span></li>
</ul>
!! end

!! test
Nonexistent template
!! wikitext
{{thistemplatedoesnotexist}}
!! html/php
<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>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Template:Thistemplatedoesnotexist?action=edit&amp;redlink=1" title="Template:Thistemplatedoesnotexist" about="#mwt1" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./Template:Thistemplatedoesnotexist"},"sa":{"href":"Template:Thistemplatedoesnotexist"},"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"thistemplatedoesnotexist","href":"./Template:Thistemplatedoesnotexist"},"params":{},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:Thistemplatedoesnotexist"]}}'>Template:Thistemplatedoesnotexist</a></p>
!! end

!! test
Template with invalid target containing tags
!! wikitext
{{a<b>b</b>|{{1x|foo}}|{{1x|a}}={{1x|b}}|a = b}}
!! html
<p>{{a<b>b</b>|foo|a=b|a = b}}
</p>
!! end

!! test
Template with invalid target containing unclosed tag
!! options
parsoid=wt2html
!! wikitext
{{a<b>|{{1x|foo}}|{{1x|a}}={{1x|b}}|a = b}}
!! html/php
<p>{{a<b>|foo|a=b|a = b}}
</b></p>
!! html/parsoid
<p>{{a<b data-parsoid='{"stx":"html","autoInsertedEnd":true}'>|<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>|<span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span>=<span about="#mwt4" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b"}},"i":0}}]}'>b</span>|a = b}}</b></p>
!! end

!! test
Template with invalid target containing wikilink
!! wikitext
{{[[Main Page]]}}
!! html/php
<p>{{<a href="/wiki/Main_Page" title="Main Page">Main Page</a>}}
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"[[Main Page]]"},"params":{},"i":0}}]}'>{{</span><a rel="mw:WikiLink" href="./Main_Page" about="#mwt1">Main Page</a><span about="#mwt1">}}</span></p>
!! end

# The html2html output of this test is currently failing
# because the html2wt output is broken; see
# https://phabricator.wikimedia.org/T220018#5123777 for a discussion.
# Not (yet) including html2wt as a test mode because there are
# a couple of different correct ways this could be <nowiki>'ed.
!! test
Template with just whitespace in it, T70421
!! wikitext
{{1x|{{ }}}}
!! options
parsoid=wt2html,html2html
!! html/php
<p>{{ }}
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{ }}"}},"i":0}}]}'>{{ }}</span></p>
!! end

# This is currently the wikitext output of html2wt on the above test
# case; note that it is broken! Adding a <nowiki> around the closing
# brace changes how the open braces associate, breaking the outer
# {{1x}} template invocation.  *However* this "broken" wikitext
# exposed a useful tokenizer bug (T221384) in how the broken_template
# rule was being backtracked into, so it's a useful test case even
# if/when the above test case gets its html2wt output fixed.
!! test
Template with just whitespace (bad template brace matching)
!! options
parsoid=wt2html
!! wikitext
{{1x|{{ }<nowiki>}</nowiki>}}
!! html/php
<p>{{1x|{{ }}}}
</p>
!! html/parsoid
<p>{{1x|{{ }<span typeof="mw:Nowiki">}</span>}}</p>
!! end

!! article
Template:test
!! text
This is a test template
!! endarticle

!! test
Simple template
!! wikitext
{{test}}
!! html
<p>This is a test template
</p>
!! end

!! test
Template with explicit namespace
!! wikitext
{{Template:test}}
!! html
<p>This is a test template
</p>
!! end


!! article
Template:paramtest
!! text
This is a test template with parameter {{{param}}}
!! endarticle

!! test
Template parameter
!! wikitext
{{paramtest|param=foo}}
!! html
<p>This is a test template with parameter foo
</p>
!! end

!! article
Template:paramtestnum
!! text
[[{{{1}}}|{{{2}}}]]
!! endarticle

!! test
Template unnamed parameter
!! wikitext
{{paramtestnum|Main Page|the main page}}
!! html
<p><a href="/wiki/Main_Page" title="Main Page">the main page</a>
</p>
!! end

!! article
Template:templatesimple
!! text
(test)
!! endarticle

!! article
Template:templateredirect
!! text
#redirect [[Template:templatesimple]]
!! endarticle

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

!! article
Template:templateasargtest
!! text
{{template{{{templ}}}}}
!! endarticle

!! article
Template:templateasargtest2
!! text
{{{{{templ}}}}}
!! endarticle

!! test
Template with template name as unnamed argument
!! wikitext
{{templateasargtestnum|templatesimple}}
!! html
<p>(test)
</p>
!! end

!! test
Template with template name as argument
!! wikitext
{{templateasargtest|templ=simple}}
!! html
<p>(test)
</p>
!! end

!! test
Template with template name as argument (2)
!! wikitext
{{templateasargtest2|templ=templatesimple}}
!! html
<p>(test)
</p>
!! end

!! article
Template:templateasargtestdefault
!! text
{{{{{templ|templatesimple}}}}}
!! endarticle

!! article
Template:templa
!! text
'''templ'''
!! endarticle

!! test
Template with default value
!! wikitext
{{templateasargtestdefault}}
!! html
<p>(test)
</p>
!! end

!! test
Template with default value (value set)
!! wikitext
{{templateasargtestdefault|templ=templa}}
!! html
<p><b>templ</b>
</p>
!! end

!! test
Template redirect
!! wikitext
{{templateredirect}}
!! html/php
<p>(test)
</p>
!! html/parsoid+standalone
<link rel="mw:PageProp/redirect" href="./Template:Templatesimple" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"templateredirect","href":"./Template:Templateredirect"},"params":{},"i":0}}]}'/>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"templateredirect","href":"./Template:Templateredirect"},"params":{},"i":0}}]}'>(test)</span></p>
!! end

!! test
Template with argument in separate line
!! wikitext
{{ templateasargtest  |
 templ = simple }}
!! html
<p>(test)
</p>
!! end

!! test
Template with complex template as argument
!! wikitext
{{paramtest|
  param ={{ templateasargtest  |
 templ = simple }}}}
!! html
<p>This is a test template with parameter (test)
</p>
!! end

!! test
Templates with templated name
!! wikitext
{{{{1x|1x}}|foo}}
{{{{1x|inner list}} }}
!! html
<p>foo
</p>
<ul><li>item 1</li></ul>
!! html/parsoid
<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|1x}}","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
<ul about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|inner list}} ","href":"./Template:Inner_list"},"params":{},"i":0}}]}'><li>item 1</li></ul>
!! end

## Regression test; the output here isn't really that interesting.
## wt2html only, since the bare {{ will get escaped when serializing
## needs investigation!
## In integrated mode, since the whole "{{...}}" is sent to core for
## processing, we wrap the output (unexpanded text) in a Transclusion.
!! test
Templates with templated name and top level template args
!! options
parsoid=wt2html
!! wikitext
{{1{{2{{{3}}}|4=5}}}}
!! html/php
<p>{{1{{2{{{3}}}|4=5}}}}
</p>
!! html/parsoid+standalone
<p>{{1{{2<span about="#mwt5" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"3"},"params":{},"i":0}}]}'>{{{3}}}</span>|4=5}}}}</p>
!! html/parsoid+integrated
<p>{{1<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"2{{{3}}}","href":"./Template:2"},"params":{"4":{"wt":"5"}},"i":0}}]}'>{{2{{{3}}}|4=5}}</span>}}</p>
!! end

## Regression test (T372669) that is only exercised in integrated mode.
## By adding {{1x|ignore-this[[Category:Foo]]}} to the 2nd param of the surround {{1x|1x}},
## it ensures that the output is discarded, but not if Parsoid eagerly processes the attribute.
!! test
T372669: While processing templates with templated names, other attributes shouldn't be processed
!! options
cat
parsoid=wt2html
!! wikitext
{{{{1x|1x}}|foo|{{1x|ignore-this[[Category:Foo]]}}}}
!! html/php
<p>foo
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"},{"k":"2"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|1x}}","href":"./Template:1x"},"params":{"1":{"wt":"foo"},"2":{"wt":"{{1x|ignore-this[[Category:Foo]]}}"}},"i":0}}]}'>foo</span></p>
!! metadata/php
!! metadata/parsoid+integrated
!! end

!! test
T372669: Template names from multiple templates
!! options
parsoid=wt2html
!! wikitext
{{{{1x|1}}{{1x|x}}|foo}}
!! html/php
<p>foo
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|1}}{{1x|x}}","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
!! end

## wt2html only, since the bare {{ will get escaped when serializing
!! test
Templates with invalid templated targets
!! options
parsoid=wt2html
!! wikitext
{{1x
{{1x|foo}}
}}
!! html/php
<p>{{1x
foo
}}
</p>
!! html/parsoid
<p>{{1x
<span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>
}}</p>
!! end

!! article
Template:complextemplate
!! text
{{{1}}} {{paramtest|
  param ={{{param}}}}}
!! endarticle

!! test
Template with complex arguments
!! wikitext
{{complextemplate|
  param ={{ templateasargtest  |
 templ = simple }}|[[Template:complextemplate|link]]}}
!! html
<p><a href="/wiki/Template:Complextemplate" title="Template:Complextemplate">link</a> This is a test template with parameter (test)
</p>
!! end

!! test
T2553: link with two variables in a piped link
!! wikitext
{|
|[[{{{1}}}|{{{2}}}]]
|}
!! html/php
<table>
<tbody><tr>
<td>[[{{{1}}}|{{{2}}}]]
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>[[<span about="#mwt5" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"1"},"params":{},"i":0}}]}'>{{{1}}}</span>|<span about="#mwt2" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"2"},"params":{},"i":0}}]}'>{{{2}}}</span>]]</td></tr>
</tbody></table>
!! end

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

# See: T2553
!! test
Bail on table cell attribute parsing on wikilink
!! wikitext
{|
|testing [[one|two]] |three||four
|testing one two |three||four
|testing="[[one|two]]" |three||four
|}
!! html/php
<table>
<tbody><tr>
<td>testing <a href="/wiki/One" title="One">two</a> |three</td>
<td>four
</td>
<td>three</td>
<td>four
</td>
<td>testing="<a href="/wiki/One" title="One">two</a>" |three</td>
<td>four
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><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":"row"}'>four</td>
<td data-parsoid='{"a":{"testing":null,"one":null,"two":null},"sa":{"testing":"","one":"","two":""}}'>three</td><td data-parsoid='{"stx":"row"}'>four</td>
<td>testing="<a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"piped","a":{"href":"./One"},"sa":{"href":"one"}}'>two</a>" |three</td><td data-parsoid='{"stx":"row"}'>four</td></tr>
</tbody></table>
!! end

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

## We don't care about Parsoid's output here as much as whether
## attribute parsing breaks because of a wikilink.
## Parsoid's standalone mode doesn't have a compliant {{#tag}} implementation
!! test
Don't bail on table cell attribute parsing if wikilink is found in template arg
!! wikitext
{|
|Test {{#tag:spantag|One two "[[three]]" four}}
|}
!! html/parsoid+integrated
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td>Test <span typeof="mw:Extension/spantag mw:Transclusion" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"One two \"[[three]]\" four"},"parts":[{"template":{"target":{"wt":"#tag:spantag","function":"tag"},"params":{"1":{"wt":"One two \"[[three]]\" four"}},"i":0}}]}'>One two "<a rel="mw:WikiLink" href="./Three" title="Three">three</a>" four</span></td></tr>
</tbody></table>
!! end

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

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

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

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

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

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

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

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

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


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

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

!! test
Template infinite loop
!! wikitext
{{loop1}}
!! html/php
<p><span class="error">Template loop detected: <a href="/wiki/Template:Loop1" title="Template:Loop1">Template:Loop1</a></span>
</p>
!! html/parsoid
<p><span class="error" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"loop1","href":"./Template:Loop1"},"params":{},"i":0}}]}'>Template loop detected: <a rel="mw:WikiLink" href="./Template:Loop1" title="Template:Loop1">Template:Loop1</a></span></p>
!! end

!! test
Template from main namespace
!! wikitext
{{:Main Page}}
!! html
<p>blah blah
</p>
!! end

!! test
Template from non-includable namespace
!! options
wgNonincludableNamespaces=10
!! wikitext
{{1x|uh oh!}}
!! html
<p><a href="/wiki/Template:1x" title="Template:1x">Template:1x</a>
</p>
!! html/parsoid+integrated
<p><a rel="mw:WikiLink" href="./Template:1x" title="Template:1x" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"uh oh!"}},"i":0}}]}'>Template:1x</a></p>
!! end

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

!! test
T2529: Template with table, not included at beginning of line
!! wikitext
foo {{table}}
!! html/php
<p>foo 
</p>
<table>
<tbody><tr>
<td>1</td>
<td>2
</td></tr>
<tr>
<td>3</td>
<td>4
</td></tr></tbody></table>
!! html/parsoid
<p>foo </p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"table","href":"./Template:Table"},"params":{},"i":0}}]}'>
</span><table about="#mwt1">
<tbody><tr><td>1</td><td>2</td></tr>
<tr>
<td>3</td><td>4</td></tr>
</tbody></table>
!! end

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

!! test
T2041: Template parameters shown as broken links
!! wikitext
{{{parameter}}}
!! html/php
<p>{{{parameter}}}
</p>
!! html/parsoid
<p about="#mwt1" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"parameter"},"params":{},"i":0}}]}'>{{{parameter}}}</p>
!! end

!! test
Unsubstituted template argument with newlines
!! wikitext
{{{testing

123}}}
!! html/php
<p>{{{testing
</p><p>123}}}
</p>
!! html/parsoid
<p about="#mwt1" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"testing\n\n123"},"params":{},"i":0}}]}'>{{{testing</p><span about="#mwt1">

</span><p about="#mwt1">123}}}</p>
!! end

!! test
Template with targets containing wikilinks
!! options
parsoid=wt2html
!! wikitext
{{[[foo]]}}

{{[[{{1x|foo}}]]}}

{{{{1x|[[foo}}]]}}
!! html/php
<p>{{<a href="/wiki/Foo" title="Foo">foo</a>}}
</p><p>{{<a href="/wiki/Foo" title="Foo">foo</a>}}
</p><p>{{[[foo}}]]
</p>
!! html/parsoid
<p>{{<a rel="mw:WikiLink" href="./Foo" title="Foo">foo</a>}}</p>
<p>{{<a typeof="mw:ExpandedAttrs" rel="mw:WikiLink" href="./Foo" title="Foo" data-mw='{"attribs":[[{"txt":"href"},{"html":"&lt;span about=\"#mwt3\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"foo\"}},\"i\":0}}]}&#39;>foo&lt;/span>"}]]}'>foo</a>}}</p>
<p>{{<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[foo}}]]"}},"i":0}}]}'>[[foo}}]]</span></p>
!! end

!! article
Template:''
!! text
bar
!! endarticle

!! test
Templates: Double quotes as template target
!! wikitext
foo {{''}} baz
!! html/php
<p>foo bar baz
</p>
!! html/parsoid
<p>foo <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"&#39;&#39;","href":"./Template:&#39;&#39;"},"params":{},"i":0}}]}'>bar</span> baz
</p>
!! end

## This test is about making sure Parsoid's data-mw is well formed in the
## face of multiple templates with intersecting and overlapping ranges.  The
## wikitext itself is wretched.
!! test
Templates with intersecting and overlapping ranges
!! wikitext
{|{{1x|1=class="foo"
<p>ha</p>}}
{|{{1x|1=class="bar"
<p>ho</p>}}
{{1x|{{!}}hi}}
|}
!! html/php
<p>ha</p><table class="foo">

</table><p>ho</p><table class="bar">

<tbody><tr>
<td>hi
</td></tr></tbody></table>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1","named":true}],[{"k":"1","named":true}],[{"k":"1"}]],"firstWikitextNode":"TABLE"}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"class=\"foo\"\n&lt;p>ha&lt;/p>"}},"i":0}},"\n","{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"class=\"bar\"\n&lt;p>ho&lt;/p>"}},"i":1}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}hi"}},"i":2}},"\n|}"]}'>ha</p><table class="foo" about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"class","html":"class=\"foo\"","uneditable":true},{"html":""}]]}'>

</table><p about="#mwt1">ho</p><table class="bar" about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"class","html":"class=\"bar\"","uneditable":true},{"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:new-messages|lots of money|not!}}
!! html/php
<p>You have lots of money (not!).
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"},{"k":"2"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"int:new-messages","function":"int"},"params":{"1":{"wt":"lots of money"},"2":{"wt":"not!"}},"i":0}}]}'>You have lots of money (not!).</span></p>
!! end

!! test
int keyword - non-existing message
!! wikitext
{{int:var}}
!! html/php
<p>⧼var⧽
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"int:var","function":"int"},"params":{},"i":0}}]}'>⧼var⧽</span></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

## In integrated mode, Parsoid won't see the <*include*>..</*include*> tags from the expanded template
!! test
<onlyinclude> being included
!! wikitext
{{Includes2}}
!! html/php
<p>Foo
</p>
!! html/parsoid+standalone
<p><meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes2","href":"./Template:Includes2"},"params":{},"i":0}}]}'/><span about="#mwt1">Foo</span><meta typeof="mw:Includes/OnlyInclude/End" about="#mwt1"/></p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes2","href":"./Template:Includes2"},"params":{},"i":0}}]}'>Foo</span></p>
!! end


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

## In integrated mode, Parsoid won't see the <*include*>..</*include*> tags from the expanded template
!! test
<onlyinclude> and <includeonly> being included
!! wikitext
{{Includes3}}
!! html/php
<p>Foo
</p>
!! html/parsoid+standalone
<p><meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes3","href":"./Template:Includes3"},"params":{},"i":0}}]}'/><span about="#mwt1">Foo</span><meta typeof="mw:Includes/OnlyInclude/End" about="#mwt1"/></p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes3","href":"./Template:Includes3"},"params":{},"i":0}}]}'>Foo</span></p>
!! end

# FIXME: Parsoid's markup for this is quite ugly.
!! test
<includeonly> and <noinclude> on a page
!! wikitext
Foo<noinclude>zar</noinclude><includeonly>bar</includeonly>
!! html/php
<p>Foozar
</p>
!! html/parsoid
<p>Foo<meta typeof="mw:Includes/NoInclude" data-parsoid="{}"/>zar</p><meta typeof="mw:Includes/NoInclude/End" data-parsoid="{}"/><meta typeof="mw:Includes/IncludeOnly" data-mw='{"src":"&lt;includeonly>bar&lt;/includeonly>"}' data-parsoid="{}"/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid="{}"/>
!! end

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

!! test
Empty <noinclude>
!! wikitext
Hello<noinclude></noinclude>!
!! html/php
<p>Hello!
</p>
!! html/parsoid
<p>Hello<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>!</p>
!! end

!! test
Nested <noinclude>s
!! wikitext
<noinclude>
x
<noinclude>y</noinclude>
z
</noinclude>
!! html/php
<p>x
y
z
</p>
!! html/parsoid
<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<p>x
<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>y<meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>
z</p>
<meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>
!! end

!! test
<onlyinclude> on a page
!! wikitext
<onlyinclude>Foo</onlyinclude>bar
!! html
<p>Foobar
</p>
!! end

!! test
Un-closed <onlyinclude>
!! wikitext
<onlyinclude>
!! html
!! end

!! test
T236868: Un-closed <noinclude> caused bad SourceRange length
!! wikitext
{| <noinclude>
|- <noinclude>
| A
|-</noinclude>
|}
!! html/parsoid
<table about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"a":{"&lt;noinclude>\n|- &lt;noinclude>\n| A\n|-&lt;/noinclude>":null},"sa":{"&lt;noinclude>\n|- &lt;noinclude>\n| A\n|-&lt;/noinclude>":""}}' data-mw='{"attribs":[[{"txt":" A","html":"&lt;meta typeof=\"mw:Includes/NoInclude\" data-parsoid=&apos;{\"src\":\"&amp;lt;noinclude>\",\"dsr\":[3,14,null,null]}&apos;/>\n|- &lt;meta typeof=\"mw:Includes/NoInclude\" data-parsoid=&apos;{\"src\":\"&amp;lt;noinclude>\",\"dsr\":[18,29,null,null]}&apos;/>\n| A\n|-&lt;meta typeof=\"mw:Includes/NoInclude/End\" data-parsoid=&apos;{\"src\":\"&amp;lt;/noinclude>\",\"dsr\":[36,48,null,null]}&apos;/>"},{"html":""}]]}'>
</table>
!! end

!!test
Self-closed noinclude, includeonly, onlyinclude tags
!! wikitext
<noinclude />
<includeonly />
<onlyinclude />
!! html
<p><br />
</p>
!!end

!!test
Unbalanced includeonly and noinclude tags
!! wikitext
{|
|a</noinclude>
|b</noinclude></noinclude>
|c</noinclude></includeonly>
|d</includeonly></includeonly>
|}
!! html
<table>
<tbody><tr>
<td>a
</td>
<td>b
</td>
<td>c&lt;/includeonly&gt;
</td>
<td>d&lt;/includeonly&gt;&lt;/includeonly&gt;
</td></tr></tbody></table>
!!end

# We're more interested in the generation of <h2> when reading than in round-tripping these - the RT without the newline
# wouldn't be acceptable if "real" text were in the include tags, for instance.
!! test
includeonly / noinclude / onlyinclude and headers
!! options
parsoid = wt2html
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
<includeonly><!--hello1 --></includeonly>== test 1 == <includeonly><!--hello2 --></includeonly>
<noinclude><!--hello3 --></noinclude>== test 2 == <noinclude><!--hello4 --></noinclude>
<onlyinclude><!--hello5 --></onlyinclude>== test 3 == <onlyinclude><!--hello6 --></onlyinclude>
!! html/parsoid
<meta typeof="mw:Includes/IncludeOnly" data-mw='{"src":"&lt;includeonly>&lt;!--hello1 -->&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><h2 id="test_1">test 1</h2> <meta typeof="mw:Includes/IncludeOnly" data-mw='{"src":"&lt;includeonly>&lt;!--hello2 -->&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/>
<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><!--hello3 --><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/><h2 id="test_2">test 2</h2> <meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><!--hello4 --><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>
<meta typeof="mw:Includes/OnlyInclude" data-parsoid='{"src":"&lt;onlyinclude>"}'/><!--hello5 --><meta typeof="mw:Includes/OnlyInclude/End" data-parsoid='{"src":"&lt;/onlyinclude>"}'/><h2 id="test_3">test 3</h2> <meta typeof="mw:Includes/OnlyInclude" data-parsoid='{"src":"&lt;onlyinclude>"}'/><!--hello6 --><meta typeof="mw:Includes/OnlyInclude/End" data-parsoid='{"src":"&lt;/onlyinclude>"}'/>
!! html/php
<div class="mw-heading mw-heading2"><h2 id="test_1">test 1</h2></div>
<div class="mw-heading mw-heading2"><h2 id="test_2">test 2</h2></div>
<div class="mw-heading mw-heading2"><h2 id="test_3">test 3</h2></div>
!! 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: Section extraction for section suppressed by <includeonly>
!! options
section=1
!! wikitext
<includeonly>
==Includeonly section==
</includeonly>
==Section 1==
!! html
==Section 1==
!! end

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

## We used to, but no longer wt2wt this test since the default serializer
## will normalize the include directives to serialize on their own line.
## Selser will take care of preserving formatting in scenarios where they
## intermingled with other wikitext.
## This test also triggered T223411 during Parsoid-PHP porting.
!! test
Includes and comments at SOL
!! options
parsoid=wt2html,html2html
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
<!-- comment --><noinclude><!-- comment --></noinclude><!-- comment -->==hu==

<noinclude>
some
</noinclude>*stuff
*here

<noinclude>
some</noinclude>* stuff
* here

<includeonly>can have stuff</includeonly>===here===

__INDEX__== hi ==
!! html/php
<div class="mw-heading mw-heading2"><h2 id="hu">hu</h2></div>
<p>some
</p>
<ul><li>stuff</li>
<li>here</li></ul>
<p><br />
some* stuff
</p>
<ul><li>here</li></ul>
<div class="mw-heading mw-heading3"><h3 id="here">here</h3></div>
<div class="mw-heading mw-heading2"><h2 id="hi">hi</h2></div>
!! html/parsoid
<!-- comment --><meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><!-- comment --><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/><!-- comment --><h2 id="hu">hu</h2>

<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<p>some</p>
<meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/><ul><li>stuff</li>
<li>here</li></ul>

<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<p>some<meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>* stuff</p>
<ul><li>here</li></ul>

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

<meta property="mw:PageProp/index"/><h2 id="hi">hi</h2>
!! end

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

a{{1x|b
<table></table>
c}}d

{{1x|a

<table></table>

b}}
!! html/php
<p>ab</p><table></table><p>cd
</p><p>ab
</p>
<table></table>
<p>cd
</p><p>a
</p>
<table></table>
<p>b
</p>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["a",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b&lt;table>&lt;/table>c"}},"i":0}},"d"]}' data-parsoid='{"pi":[[{"k":"1"}]]}'>ab</p><table about="#mwt1" data-parsoid='{"stx":"html"}'></table><p about="#mwt1">cd</p>

<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":["a",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b\n&lt;table>&lt;/table>\nc"}},"i":0}},"d"]}' data-parsoid='{"pi":[[{"k":"1"}]]}'>ab</p><span about="#mwt2">
</span><table about="#mwt2" data-parsoid='{"stx":"html"}'></table><span about="#mwt2">
</span><p about="#mwt2">cd</p>

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

</span><table about="#mwt3" data-parsoid='{"stx":"html"}'></table><span about="#mwt3">

</span><p about="#mwt3">b</p>
!! end

!! test
Parsoid: Merge double tds (T52603)
!! wikitext
{|
|{{1x|{{!}} foo}}
|}
!! html/php
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
<table><tbody>
<tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}} foo"}},"i":0}}]}'> foo</td></tr>
</tbody></table>
!! end

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

!! article
Template:Temp?
!! text
temp {{{1}}}
!! endarticle

!! test
Template name with question mark
!! options
parsoid={
  "modes": [ "selser", "wt2html", "html2wt" ],
  "changes": [
    ["span", "attr", "data-mw", "{\"parts\":[{\"template\":{\"target\":{\"wt\":\"temp?\",\"href\":\"./Template:Temp%3F\"},\"params\":{\"1\":{\"wt\":\"456\"}},\"i\":0}}]}"]
  ]
}
!! wikitext
{{temp?|123}}
!! wikitext/edited
{{temp?|456}}
!! html/php
<p>temp 123
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"temp?","href":"./Template:Temp%3F"},"params":{"1":{"wt":"123"}},"i":0}}]}'>temp 123</span></p>
!! end

###
### <includeonly> and <noinclude> in attributes
###
!!test
0. includeonly around the entire attribute
!! wikitext
<span <includeonly>id="v1"</includeonly><noinclude>id="v2"</noinclude>>bar</span>
!! html
<p><span id="v2">bar</span>
</p>
!!end

!!test
1. includeonly in html attr key
!! wikitext
<span <noinclude>id</noinclude><includeonly>about</includeonly>="foo">bar</span>
!! html
<p><span id="foo">bar</span>
</p>
!!end

!!test
2. includeonly in html attr value
!! wikitext
<span id="<noinclude>v1</noinclude><includeonly>v2</includeonly>">bar</span>
<span id=<noinclude>"v1"</noinclude><includeonly>"v2"</includeonly>>bar</span>
!! html
<p><span id="v1">bar</span>
<span id="v1">bar</span>
</p>
!!end

!!test
3. includeonly in part of an attr value
!! wikitext
<span style="color:<noinclude>red</noinclude><includeonly>blue</includeonly>;">bar</span>
!! html
<p><span style="color:red;">bar</span>
</p>
!!end

!!test
4. includeonly in table attributes
!! wikitext
{|
|- <noinclude>
|-
|a
</noinclude>
|- <includeonly>
|-
|b
</includeonly>
|}
!! html
<table>


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

###
### Token Stream Patcher tests
###
### These tests won't always pass wt2wt and other modes because
### on serialization, the table will be output on a new line.
### For now, we are prohibiting them, and using this to test selser.
###

!!test
1. Table tag in SOL posn. should get reparsed correctly with valid TSR
!!options
parsoid=wt2html,wt2wt
!!wikitext
{{1x|}}{| width = '100%'
|foo
|}
!!html/parsoid
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":""}},"i":0}}]}'></span><table width="100%">
<tbody><tr><td>foo</td></tr>
</tbody></table>
!!end

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

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

!! test
Content after <tr> like wikitext should get fully processed
!! wikitext
x
|- [[Foo]] and {{1x|bar}}
y
!! html/php
<p>x
|- <a href="/wiki/Foo" title="Foo">Foo</a> and bar
y
</p>
!! html/parsoid
<p>x
|- <a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"simple","a":{"href":"./Foo"},"sa":{"href":"Foo"}}'>Foo</a> and <span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"bar"}},"i":0}}]}'>bar</span>
y</p>
!! end

!! test
P-wrapping should not break after <td>s separated by newlines are converted back to pipes
!! wikitext
a
|b

|c
d
!! html/php
<p>a
|b
</p><p>|c
d
</p>
!! html/parsoid
<p>a
|b</p>

<p>|c
d</p>
!! end

!! test
Orphaned table row wikitext with templated table for an attribute should not duplicate table
!! wikitext
|-{{1x|
{{{!}}
{{!}}foo
{{!}}}
}}
!! html/php
<p>|-
</p>
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]],"firstWikitextNode":"TR"}' data-mw='{"parts":["|-",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n{{{!}}\n{{!}}foo\n{{!}}}\n"}},"i":0}}]}'>|-</p><span about="#mwt1">
</span><table about="#mwt1">
<tbody><tr><td>foo</td></tr>
</tbody></table><span about="#mwt1">
</span>
!! end

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

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

!! test
Templates: Template Name/Arg clash: 1. Use of positional param
!! wikitext
{{quote|foo}}
!! html/php
<p>foo
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"quote","href":"./Template:Quote"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
!! end

!! test
Templates: Template Name/Arg clash: 2. Use of named param
!! wikitext
{{quote|quote=foo}}
!! html/php
<p>foo
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"quote","href":"./Template:Quote"},"params":{"quote":{"wt":"foo"}},"i":0}}]}'>foo</span></p>
!! end

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

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

!!test
Templates: 2. Inside a block tag
!! wikitext
<div>{{1x|Foo}}</div>
<blockquote>{{1x|Foo}}</blockquote>
!! html
<div>Foo</div>
<blockquote><p>Foo</p></blockquote>
!!end

!!test
Templates: P-wrapping: 1a. Templates on consecutive lines
!! wikitext
{{1x|Foo}}
{{1x|bar}}
!! html
<p>Foo
bar
</p>
!!end

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

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

!!test
Templates: P-wrapping: 1c. Templates on consecutive lines
!! wikitext
{{1x|Foo}}
{{1x|bar}} <div>baz</div>
!! html
<p>Foo
</p><p>
bar </p><div>baz</div>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Foo"}},"i":0}}]}'>Foo</span></p>
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"bar"}},"i":0}}]}'>bar</p> <div data-parsoid='{"stx":"html"}'>baz</div>
!! end

!! test
Templates: P-wrapping: 1d. Template preceded by comment-only line
!! wikitext
<!-- foo -->
{{1x|Bar}}
!! html/php
<p>Bar
</p>
!! html/parsoid
<!-- foo -->

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

!! test
Templates: Scopes should not be expanded unnecessarily
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{1x|<div>a</div>}}b{{1x|
<div>c</div>}}
!! html/php
<div>a</div><p>b
</p><div>c</div>
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>a&lt;/div>"}},"i":0}}]}'>a</div><p>b</p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n&lt;div>c&lt;/div>"}},"i":0}}]}'>
</span><div about="#mwt2">c</div>
!! end

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

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

!!test
Templates: Block Tags: 1. Multiple template uses
!! wikitext
{{1x|<div>Foo</div>}}<div>bar</div>{{1x|<div>baz</div>}}
!! html
<div>Foo</div><div>bar</div><div>baz</div>
!!end

!!test
Templates: Block Tags: 2. Back-to-back template uses
!! wikitext
{{1x|<div>Foo</div>}}{{1x|<div>bar</div>}}
!! html
<div>Foo</div><div>bar</div>
!!end

## Parsoid drops empty elements in templates.
!! test
Templates: Correctly encapsulate templates producing </p> tag without a corresponding <p> tag
!! wikitext
{{1x|a
b</p>}}
!! html/php
<p>a
</p><p>
b</p><p class="mw-empty-elt"></p>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\nb&lt;/p>"}},"i":0}}]}'>a</p><span about="#mwt1">
</span><p about="#mwt1">b</p>
!! end

!! test
Drop stripped tag markers, unless they have encapsulation info
!! wikitext
{{1x|<tr></tr>}}
!! html/php

!! html/parsoid
<meta typeof="mw:Transclusion mw:Placeholder/StrippedTag" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tr>&lt;/tr>"}},"i":0}}]}'/>
!! end

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

!!test
Templates: Links: 2. Generation of link href
!! wikitext
[[{{1x|Foo}}|bar]]
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

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

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

!!test
Templates: Links: 3. Generation of part of a link href
!! wikitext
[[Fo{{1x|o}}|bar]]

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

[[Foo{{1x|bar}}baz]]

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

[[:Foo{{1x|bar}}]]

[[:Foo{{1x|bar}}|bar]]
!! html/php
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p><p><a href="/wiki/Foobar" title="Foobar">Foobar</a>
</p><p><a href="/wiki/Foobarbaz" title="Foobarbaz">Foobarbaz</a>
</p><p><a href="/wiki/Foobar" title="Foobar">bar</a>
</p><p><a href="/wiki/Foobar" title="Foobar">Foobar</a>
</p><p><a href="/wiki/Foobar" title="Foobar">bar</a>
</p>
!! html/parsoid
<p><a typeof="mw:ExpandedAttrs" about="#mwt2" rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"piped","a":{"href":"./Foo"},"sa":{"href":"Fo{{1x|o}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"Fo&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[4,12,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"o\"}},\"i\":0}}]}&apos;>o&lt;/span>"}]]}'>bar</a></p>

<p><a typeof="mw:ExpandedAttrs" about="#mwt4" rel="mw:WikiLink" href="./Foobar" title="Foobar" data-parsoid='{"stx":"simple","a":{"href":"./Foobar"},"sa":{"href":"Foo{{1x|bar}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"Foo&lt;span about=\"#mwt3\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[25,35,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"bar\"}},\"i\":0}}]}&apos;>bar&lt;/span>"}]]}'>Foobar</a></p>

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

<p><a typeof="mw:ExpandedAttrs" about="#mwt8" rel="mw:WikiLink" href="./Foobar" title="Foobar" data-parsoid='{"stx":"piped","a":{"href":"./Foobar"},"sa":{"href":"Foo{{1x|bar}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"Foo&lt;span about=\"#mwt7\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[66,76,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"bar\"}},\"i\":0}}]}&apos;>bar&lt;/span>"}]]}'>bar</a></p>

<p><a typeof="mw:ExpandedAttrs" about="#mwt10" rel="mw:WikiLink" href="./Foobar" title="Foobar" data-parsoid='{"stx":"simple","a":{"href":"./Foobar"},"sa":{"href":":Foo{{1x|bar}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":":Foo&lt;span about=\"#mwt9\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[90,100,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"bar\"}},\"i\":0}}]}&apos;>bar&lt;/span>"}]]}'>Foobar</a></p>

<p><a typeof="mw:ExpandedAttrs" about="#mwt12" rel="mw:WikiLink" href="./Foobar" title="Foobar" data-parsoid='{"stx":"piped","a":{"href":"./Foobar"},"sa":{"href":":Foo{{1x|bar}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":":Foo&lt;span about=\"#mwt11\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[110,120,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"bar\"}},\"i\":0}}]}&apos;>bar&lt;/span>"}]]}'>bar</a></p>
!!end

!!test
Templates: Links: 4. Multiple templates generating link href
!! wikitext
[[{{1x|F}}{{1x|o}}ob{{1x|ar}}]]
!! html/php
<p><a href="/wiki/Foobar" title="Foobar">Foobar</a>
</p>
!! html/parsoid
<p><a typeof="mw:ExpandedAttrs" about="#mwt4" rel="mw:WikiLink" href="./Foobar" title="Foobar" data-parsoid='{"stx":"simple","a":{"href":"./Foobar"},"sa":{"href":"{{1x|F}}{{1x|o}}ob{{1x|ar}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[2,10,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"F\"}},\"i\":0}}]}&apos;>F&lt;/span>&lt;span about=\"#mwt2\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[10,18,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"o\"}},\"i\":0}}]}&apos;>o&lt;/span>ob&lt;span about=\"#mwt3\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[20,29,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"ar\"}},\"i\":0}}]}&apos;>ar&lt;/span>"}]]}'>Foobar</a></p>
!!end

!!test
Templates: Links: 5. Generation of link text
!! wikitext
[[Foo|{{1x|bar}}]]
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

!!test
Templates: Links: 5. Nested templates (only outermost template should be marked)
!! wikitext
{{1x|[[{{1x|Foo}}|bar]]}}
!! html
<p><a href="/wiki/Foo" title="Foo">bar</a>
</p>
!!end

!! test
File with template filename
!! wikitext
[[File:{{1x|Foobar.jpg}}]]
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:File mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"href"},{"html":"File:&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"Foobar.jpg\"}},\"i\":0}}]}&apos;>Foobar.jpg&lt;/span>"}]]}'><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:{{1x|Foobar.jpg}}"}}' class="mw-file-element"/></a></span></p>
!! end

!!test
Templates: HTML Tag: 1. Generation of HTML attr. key
!! wikitext
<div {{1x|style}}="color:red;">foo</div>
!! html
<div style="color:red;">foo</div>
!!end

!!test
Templates: HTML Tag: 2. Generation of HTML attr. value
!! wikitext
<div style={{1x|'color:red;'}}>foo</div>
!! html
<div style="color:red;">foo</div>
!!end

!!test
Templates: HTML Tag: 3. Generation of HTML attr key and value
!! wikitext
<div {{1x|style}}={{1x|'color:red;'}}>foo</div>
!! html
<div style="color:red;">foo</div>
!!end

!!test
Templates: HTML Tag: 4. Generation of starting piece of HTML attr value
!! wikitext
<div title="{{1x|This is a long title}} with just one piece templated">foo</div>
!! html
<div title="This is a long title with just one piece templated">foo</div>
!!end

!!test
Templates: HTML Tag: 5. Generation of middle piece of HTML attr value
!! wikitext
<div title="This is a long title with just {{1x|one piece}} templated">foo</div>
!! html
<div title="This is a long title with just one piece templated">foo</div>
!!end

!!test
Templates: HTML Tag: 6. Generation of end piece of HTML attr value
!! wikitext
<div title="This is a long title with just one piece {{1x|templated}}">foo</div>
!! html
<div title="This is a long title with just one piece templated">foo</div>
!!end

# SSS FIXME: While it is great we added support for all this,
# do we want to make this part of the spec? Maybe we want to
# deprecate this kind of usage in the future?
!!test
Templates: HTML Tag: 7. Generation of partial attribute key string
!! wikitext
<div st{{1x|yle}}="color:red;">foo</div>
!! html
<div style="color:red;">foo</div>
!!end

!! test
Templates: HTML Tag: 8. Template-generated attribute (k=v)
!! wikitext
<div {{1x|1=id="v1"}}>bar</div>
!! html
<div id="v1">bar</div>
!!end

!! test
Templates: HTML Tag: 9. Multiple template-generated attributes
!! wikitext
<div {{1x|1=id="v1" title="foo"}}>bar</div>
!! html
<div id="v1" title="foo">bar</div>
!!end

!! test
Templates: Support for templates generating attributes and content
!! wikitext
{| {{mixed_attr_content_template}}
|-
|bar
|}
!! html/php
<table style="color:red;" title="T48811">

<tbody><tr>
<td>foo
</td></tr>
<tr>
<td>bar
</td></tr></tbody></table>
!! html/parsoid
<table style="color:red;" title="T48811" about="#mwt1" typeof="mw:Transclusion mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"style","html":"style=\"color:red;\" title=\"T48811\"","uneditable":true},{"html":""}]],"parts":["{| ",{"template":{"target":{"wt":"mixed_attr_content_template","href":"./Template:Mixed_attr_content_template"},"params":{},"i":0}},"\n|-\n|bar\n|}"]}'>
<tbody><tr>
<td>foo</td></tr>
<tr>
<td>bar</td></tr>
</tbody></table>
!!end

!! test
Templates: Support for templates generating table attributes and content (with fostered categories)
!! wikitext
{| {{mixed_attr_content_template_2}}
|-
|bar
|}
!! html/php
<table style="color:red;" title="T249740">
<tbody><tr>
<td>foo
</td></tr>
<tr>
<td>bar
</td></tr></tbody></table>
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Fostered_Content" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:Fostered_Content"},"sa":{"href":"Category:Fostered Content"},"pi":[[]],"firstWikitextNode":"TABLE"}' data-mw='{"parts":["{| ",{"template":{"target":{"wt":"mixed_attr_content_template_2","href":"./Template:Mixed_attr_content_template_2"},"params":{},"i":0}},"\n|-\n|bar\n|}"]}'/><table style="color:red;" title="T249740" about="#mwt1" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"style","html":"style=\"color:red;\" title=\"T249740\"","uneditable":true},{"html":""}]]}'>
<tbody><tr>

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

!! article
Template:attribute_from_template
!! text
class="123"
!! endarticle

!! test
Table cell with attribute before expanded attribute
!! wikitext
{|
| align="center" {{attribute_from_template}} |456
|}
!! html/parsoid
<table>
<tbody><tr><td align="center" class="123" about="#mwt2" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"class","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[]],\"dsr\":[20,47,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"attribute_from_template\",\"href\":\"./Template:Attribute_from_template\"},\"params\":{},\"i\":0}}]}&apos;>class=\"123\"&lt;/span>"},{"html":""}]]}'>456</td></tr>
</tbody></table>
!! end

# In integrated mode, the {{=}} template is expanded before Parsoid sees it
!! test
1. Entities and nowikis inside templated attributes should be handled correctly
!! wikitext
<div {{1x|style{{=}}"background:&#35;f9f9f9;"}}>foo</div>
!! html/php
<div style="background:#f9f9f9;">foo</div>
!! html/parsoid+standalone
<div style="background:#f9f9f9;" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html"}' data-mw='{"attribs":[[{"txt":"style","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"style{{=}}\\\"background:&amp;amp;#35;f9f9f9;\\\"\"}},\"i\":0}}]}&#39;>style&lt;/span>&lt;span typeof=\"mw:Nowiki\" about=\"#mwt1\" data-parsoid=\"{}\">=&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">\"background:&lt;/span>&lt;span typeof=\"mw:Entity\" about=\"#mwt1\" data-parsoid=&#39;{\"src\":\"&amp;amp;#35;\",\"srcContent\":\"#\"}&#39;>#&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">f9f9f9;\"&lt;/span>"},{"html":""}]]}'>foo</div>
!! html/parsoid+integrated
<div style="background:#f9f9f9;" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html"}' data-mw='{"attribs":[[{"txt":"style","html":"&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[{\"k\":\"1\"}]]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"style{{=}}\\\"background:&amp;amp;#35;f9f9f9;\\\"\"}},\"i\":0}}]}&#39;>style=\"background:&lt;/span>&lt;span typeof=\"mw:Entity\" about=\"#mwt1\" data-parsoid=&#39;{\"src\":\"&amp;amp;#35;\",\"srcContent\":\"#\"}&#39;>#&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">f9f9f9;\"&lt;/span>"},{"html":""}]]}'>foo</div>
!! end

!! test
2. Entities and nowikis inside templated attributes should be handled correctly
!! wikitext
{|
|{{table_attribs_3}}
|}
!! html/php
<table>
<tbody><tr>
<td style="background:#f9f9f9;">Foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td style="background:#f9f9f9;" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["|",{"template":{"target":{"wt":"table_attribs_3","href":"./Template:Table_attribs_3"},"params":{},"i":0}}]}'>Foo</td></tr>
</tbody></table>
!! end

!! test
3. Entities and nowikis inside templated attributes should be handled correctly inside templated tables
!! wikitext
{{tbl-start}}
|{{table_attribs_3}}
{{tbl-end}}
!! html/php
<table>
<tbody><tr>
<td style="background:#f9f9f9;">Foo
</td></tr></tbody></table>
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[],[],[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"tbl-start","href":"./Template:Tbl-start"},"params":{},"i":0}},"\n|",{"template":{"target":{"wt":"table_attribs_3","href":"./Template:Table_attribs_3"},"params":{},"i":1}},"\n",{"template":{"target":{"wt":"tbl-end","href":"./Template:Tbl-end"},"params":{},"i":2}}]}'>
<tbody><tr><td style="background:#f9f9f9;">Foo</td></tr>
</tbody></table>
!! end

# T107622
!! test
4. Entities and nowikis inside templated attributes should be handled correctly inside templated tables
!! wikitext
{|
|{{table_attribs_6}} hi
|}
!! html/php
<table>
<tbody><tr>
<td style="background: red;">hi
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td style="background:  red;" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["|",{"template":{"target":{"wt":"table_attribs_6","href":"./Template:Table_attribs_6"},"params":{},"i":0}}," hi"]}'> hi</td></tr>
</tbody></table>
!! end

!! test
Extension tag in templated tag attribute
!! wikitext
{{1x|1=
{{{!}} class="123" <nowiki />
{{!}} hi
{{!}}}
}}
!! html/php
<table class="123">
<tbody><tr>
<td>hi
</td></tr></tbody></table>
!! html/parsoid
<table class="123" about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"startTagSrc":"{{{!}}","a":{"&lt;nowiki />":null},"sa":{"&lt;nowiki />":""},"pi":[[{"k":"1","named":true,"spc":["","","\n","\n"]}]]}' data-mw='{"attribs":[[{"txt":"","html":"&lt;span typeof=\"mw:Nowiki\">&lt;/span>"},{"html":""}]],"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{{!}} class=\"123\" &lt;nowiki />\n{{!}} hi\n{{!}}}"}},"i":0}}]}'>
<tbody><tr><td>hi</td></tr>
</tbody></table>
!! end

!!test
Templates: HTML Tables: 1. Generating start of a HTML table
!! wikitext
{{1x|<table><tr><td>foo</td>}}</tr></table>
!! html
<table><tbody><tr><td>foo</td></tr></tbody></table>
!!end

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

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

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

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

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

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

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

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

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

!!test
Templates: HTML Tables: 5. Proper fostering of categories from inside
!!options
parsoid=wt2html,wt2wt
!! wikitext
<table>[[Category:foo1]]<tr><td>foo</td></tr></table>
<!--Two categories (T52330)-->
<table>[[Category:bar1]][[Category:bar2]]<tr><td>foo</td></tr></table>
!! html/php
<table><tbody><tr><td>foo</td></tr></tbody></table>
<table><tbody><tr><td>foo</td></tr></tbody></table>
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Foo1"><table><tbody><tr><td>foo</td></tr></tbody></table>
<!--Two categories (T52330)-->
<link rel="mw:PageProp/Category" href="./Category:Bar1"><link rel="mw:PageProp/Category" href="./Category:Bar2"><table><tbody><tr><td>foo</td></tr></tbody></table>
!!end

## Remex doesn't account for fostered content.
!! test
Templates: Wiki Tables: 1a. Fostering of entire template content
!! wikitext
{|
{{1x|a}}
|}
!! html/php

a
<table><tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}},"\n|}"]}'>a</p><table about="#mwt2">

</table>
!! end

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

<tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<div about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"stx":"html","fostered":true,"autoInsertedEnd":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}],[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>"}},"i":0}},"\nfoo\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/div>"}},"i":1}},"\n|}"]}'>
<p>foo</p>
</div><table about="#mwt3">

</table>
!! end

## Remex doesn't account for fostered content.
!! test
Templates: Wiki Tables: 2. Fostering of partial template content
!! wikitext
{|
{{1x|a
<div>b</div>}}
|}
!! html/php

a
<div>b</div><table>
<tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\n&lt;div>b&lt;/div>"}},"i":0}},"\n|}"]}'>a</p><div about="#mwt2">b</div><table about="#mwt2">


</table>
!! end

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

!!test
Templates: Wiki Tables: 4. Templated tags, no content
!! wikitext
{{tbl-start}}
{{tbl-end}}
!! html/php
<table>
<tbody><tr><td></td></tr></tbody></table>
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[],[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"tbl-start","href":"./Template:Tbl-start"},"params":{},"i":0}},"\n",{"template":{"target":{"wt":"tbl-end","href":"./Template:Tbl-end"},"params":{},"i":1}}]}'>
</table>
!! end

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

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

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

!! test
Templates: Wiki Tables: 8. Fosterable meta-tags should get fostered
!! wikitext
{{UnclosedTableEndsWithTR}}
<onlyinclude>
|foo
</onlyinclude>
|}

<noinclude>
{{UnclosedTableEndsWithTR}}
</noinclude>
|foo
|}
!! html/parsoid
<meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"UnclosedTableEndsWithTR","href":"./Template:UnclosedTableEndsWithTR"},"params":{},"i":0}},"\n&lt;onlyinclude>\n|foo\n&lt;/onlyinclude>\n|}"]}'/>
<table about="#mwt1">
<tbody><tr>

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

<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<meta about="#mwt2" typeof="mw:Transclusion mw:Includes/NoInclude/End" data-mw='{"parts":[{"template":{"target":{"wt":"UnclosedTableEndsWithTR","href":"./Template:UnclosedTableEndsWithTR"},"params":{},"i":0}},"\n&lt;/noinclude>\n|foo\n|}"]}'/> <table about="#mwt2">
<tbody><tr>

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

## Parsoid standalone mode seems to drop nonexisting templates
!! test
Templates: Lists: Multi-line list-items via templates
!! wikitext
*{{1x|a {{nonexistent|
unused}}}}
*{{1x|b {{nonexistent|
unused}}}}
!! html/php
<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>
!! html/parsoid
<ul><li><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a {{nonexistent|\nunused}}"}},"i":0}}]}'>a </span><a rel="mw:WikiLink" href="./Template:Nonexistent?action=edit&amp;redlink=1" title="Template:Nonexistent" about="#mwt1" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Template:Nonexistent"},"sa":{"href":"Template:Nonexistent"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:Nonexistent"]}}'>Template:Nonexistent</a></li>
<li><span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"b {{nonexistent|\nunused}}"}},"i":0}}]}'>b </span><a rel="mw:WikiLink" href="./Template:Nonexistent?action=edit&amp;redlink=1" title="Template:Nonexistent" about="#mwt3" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Template:Nonexistent"},"sa":{"href":"Template:Nonexistent"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:Nonexistent"]}}'>Template:Nonexistent</a></li></ul>
!! end

!!test
Templates: Ugly nesting: 1. Quotes opened/closed across templates (1x)
!! wikitext
{{1x|''a}}{{1x|b''c''d}}{{1x|''e}}
!! html
<p><i>ab</i>c<i>d</i>e
</p>
!!end

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

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

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

!! test
Templates: Ugly templates: 3. newline-only template parameter
!! wikitext
foo {{1x|
}}
!! html
<p>foo 
</p>
!! end

# This looks like a bug: a single newline triggers p/br for some reason.
!! test
Templates: Ugly templates: 4. newline-only template parameter inconsistency
!! wikitext
{{1x|
}}
!! html
<p><br />
</p>
!! end

# T66017 -- ugly wikitext with fostered content generates two template ranges that
# have a true overlap (T1-start - T2-start - T1-end - T2-end).
!! test
Templates: Ugly templates: 5. Template encapsulation test: Non-trivial overlap of template ranges is properly handled
!! wikitext
{{1x|<table>}}
{{1x|<div>foo}}
{{1x|</table>}}
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>"}},"i":0}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>foo"}},"i":1}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/table>"}},"i":2}}]}'>foo</div><span about="#mwt1">
</span><table about="#mwt1">
</table>
!! end

# T66017 -- ugly wikitext with fostered content generates two template ranges
# that are "identical" and generate nesting cycles in the algorithm
!! test
Templates: Ugly templates: 6. Template encapsulation test: Cyclical nesting of template ranges is properly handled
!! wikitext
{{1x|<table><tr><td><table>}}
{{1x|<div>}}
{{1x|</div>}}
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>&lt;tr>&lt;td>&lt;table>"}},"i":0}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>"}},"i":1}},"\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/div>"}},"i":2}}]}' data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[{"k":"1"}],[{"k":"1"}],[{"k":"1"}]]}'><tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'><div data-parsoid='{"stx":"html"}'>
</div><table about="#mwt1" data-parsoid='{"stx":"html"}'>
</table></td></tr></tbody></table>
!! end

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

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

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

!! test
Templates: Param with empty arg in the final position
!! wikitext
{{{hi|}}}
!! html/parsoid
<span about="#mwt1" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"hi"},"params":{"1":{"wt":""}},"i":0}}]}'></span>
!! end

!! test
Compound transclusion with template and top level templatearg
!! wikitext
{{1x|<table>}}
{{{top|<td>123</td>}}}
</table>
!! html/php
<table>
<tbody><tr><td>123</td>
</tr></tbody></table>
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>"}},"i":0}},"\n",{"templatearg":{"target":{"wt":"top"},"params":{"1":{"wt":"&lt;td>123&lt;/td>"}},"i":1}},"\n&lt;/table>"]}'>
<tbody><tr><td>123</td></tr>
</tbody></table>
!! end

!!test
Parser Functions: 1. Simple example
!! wikitext
{{uc:foo}}
!! html
<p>FOO
</p>
!!end

!!test
Parser Functions: 2. Nested use (only outermost should be marked up)
!! wikitext
{{uc:{{lc:FOO}}}}
!! html
<p>FOO
</p>
!!end

## Note that the templates inside the extension tag are not wrapped
## and that the extsrc attributes in integrated mode are missing
## the nested template (FIXME!)
!! test
Template nested in extension tag in template
!! options
title=[[Main Page]]
language=zh
!! wikitext
{{1x|hi<span>[[ho|{{1x|hi}}]]</span>}}
{{1x|hi<spantag>[[ho|{{1x|hi}}]]</spantag>}}
{{1x|hi<spantag>[http://test.com?q={{1x|ho}}]</spantag>}}
{{1x|hi<spantag>-{ho|{{1x|hi}}}-</spantag>}}
!! html/php
<p>hi<span><a href="/wiki/Ho" title="Ho">hi</a></span>
hi<span><a href="/wiki/Ho" title="Ho">hi</a></span>
hi<span><a rel="nofollow" class="external autonumber" href="http://test.com?q=ho">[1]</a></span>
hi<span>hi</span>
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;span>[[ho|{{1x|hi}}]]&lt;/span>"}},"i":0}}]}'>hi</span><span about="#mwt1" data-parsoid='{"stx":"html"}'><a rel="mw:WikiLink" href="./Ho" title="Ho">hi</a></span>
<span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;spantag>[[ho|{{1x|hi}}]]&lt;/spantag>"}},"i":0}}]}'>hi</span><span about="#mwt2" typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"[[ho|{{1x|hi}}]]"}}'><a rel="mw:WikiLink" href="./Ho" title="Ho">hi</a></span>
<span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;spantag>[http://test.com?q={{1x|ho}}]&lt;/spantag>"}},"i":0}}]}'>hi</span><span about="#mwt3" typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"[http://test.com?q={{1x|ho}}]"}}'><a rel="mw:ExtLink" href="http://test.com?q=ho" class="external autonumber"></a></span>
<span about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;spantag>-{ho|{{1x|hi}}}-&lt;/spantag>"}},"i":0}}]}'>hi</span><span about="#mwt4" typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"-{ho|{{1x|hi}}}-"}}'><span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["ho"],"t":"hi"}}'></span></span></p>
!! end

!! test
ParserTest <spantag> tag, using data-mw.body serialization shortcut
!! wikitext
Hello <spantag>'''world'''!</spantag>
!! html/php
<p>Hello <span><b>world</b>!</span>
</p>
!! html/parsoid
<p>Hello <span typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"&apos;&apos;&apos;world&apos;&apos;&apos;!"}}'><b>world</b>!</span></p>
!! end

!! test
ParserTest <spantag> tag, without data-mw.body serialization shortcut
!! options
parsoid=html2wt
!! wikitext
Hello <spantag>'''world'''!</spantag>
!! html/php
<p>Hello <span><b>world</b>!</span>
</p>
!! html/parsoid
<p>Hello <span typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{}}'><b>world</b>!</span></p>
!! end

!! test
Parsoid: Recognize nowiki with odd capitalization
!! options
parsoid=wt2html
!! wikitext
<noWikI ><div>[[foo]]</Nowiki >
!! html/php
<p>&lt;div&gt;[[foo]]
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">&lt;div&gt;[[foo]]</span></p>
!! end


!! test
Parsoid: Escape nowiki with trailing space in tags
!! options
parsoid=html2wt
!! html/parsoid
<p>&lt;nowiki &gt; foo &lt/nowiki ></p>
<p>a&lt;nowiki /&gt;b</p>
<p>c&lt;nowiki/ &gt;d</p>
!! wikitext
&lt;nowiki &gt; foo &lt;/nowiki &gt;

a&lt;nowiki /&gt;b

c&lt;nowiki/ &gt;d
!! end

!! test
Parsoid: Escape weird noWikI capitalizations
!! options
parsoid=html2wt
!! html/parsoid
<p>&lt;noWikI &gt; foo &lt/NoWikI ></p>
!! wikitext
&lt;noWikI &gt; foo &lt;/NoWikI &gt;
!! end

###
### Message transform tests
###
!! test
message transform: magic variables
!! options
msg
!! wikitext
{{SITENAME}}
!! html
MediaWiki
!! end

!! test
message transform: should not transform wiki markup
!! options
msg
!! wikitext
''test''
!! html
''test''
!! end

!! test
message transform: <noinclude> in transcluded template (T6926)
!! options
msg
!! wikitext
{{Includes}}
!! html/php
Foobar
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Includes","href":"./Template:Includes"},"params":{},"i":0}}]}'>Foobar</span></p>
!! end

!! test
message transform: <onlyinclude> in transcluded template (T6926)
!! options
msg
!! wikitext
{{Includes2}}
!! html/php
Foo
!! html/parsoid+standalone
<p><meta typeof="mw:Transclusion mw:Includes/OnlyInclude" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"Includes2","href":"./Template:Includes2"},"params":{},"i":0}}]}'/><span about="#mwt1">Foo</span><meta typeof="mw:Includes/OnlyInclude/End" about="#mwt1"/></p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Includes2","href":"./Template:Includes2"},"params":{},"i":0}}]}'>Foo</span></p>
!! end

!! test
{{#special:}} page name, known
!! options
msg
!! wikitext
{{#special:Recentchanges}}
!! html/php
Special:RecentChanges
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#special:Recentchanges","function":"special"},"params":{},"i":0}}]}'>Special:RecentChanges</span></p>
!! end

!! test
{{#special:}} page name with subpage, known
!! options
msg
!! wikitext
{{#special:Recentchanges/param}}
!! html/php
Special:RecentChanges/param
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#special:Recentchanges/param","function":"special"},"params":{},"i":0}}]}'>Special:RecentChanges/param</span></p>
!! end

!! test
{{#special:}} page name, unknown
!! options
msg
!! wikitext
{{#special:foobar nonexistent}}
!! html/php
Special:Foobar nonexistent
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#special:foobar nonexistent","function":"special"},"params":{},"i":0}}]}'>Special:Foobar nonexistent</span></p>
!! end

!! test
{{#speciale:}} page name, known
!! options
msg
!! wikitext
{{#speciale:Recentchanges}}
!! html/php
Special:RecentChanges
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#speciale:Recentchanges","function":"speciale"},"params":{},"i":0}}]}'>Special:RecentChanges</span></p>
!! end

!! test
{{#speciale:}} page name with subpage, known
!! options
msg
!! wikitext
{{#speciale:Recentchanges/param}}
!! html/php
Special:RecentChanges/param
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#speciale:Recentchanges/param","function":"speciale"},"params":{},"i":0}}]}'>Special:RecentChanges/param</span></p>
!! end

!! test
{{#speciale:}} page name, unknown
!! options
msg
!! wikitext
{{#speciale:foobar nonexistent}}
!! html/php
Special:Foobar_nonexistent
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#speciale:foobar nonexistent","function":"speciale"},"params":{},"i":0}}]}'>Special:Foobar_nonexistent</span></p>
!! end

###
### Subpages
###

!! article
Subpage test/subpage
!! text
foo
!! endarticle

!! test
Subpage link
!! options
subpage title=[[Subpage test]]
!! wikitext
[[/subpage]]
!! html
<p><a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">/subpage</a>
</p>
!! end

!! test
Subpage noslash link
!! options
subpage title=[[Subpage test]]
!! wikitext
[[/subpage/]]
!! html
<p><a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">subpage</a>
</p>
!! end

!! article
Subpage test/1/2/subpage
!! text
blah
!! endarticle

!! test
Relative subpage noslash link
!! options
parsoid=wt2wt,wt2html,html2html
subpage title=[[Subpage test/1/2/3/4]]
!! wikitext
[[../../subpage/]]

[[../../subpage]]
!! html/php
<p><a href="/wiki/Subpage_test/1/2/subpage" title="Subpage test/1/2/subpage">subpage</a>
</p><p><a href="/wiki/Subpage_test/1/2/subpage" title="Subpage test/1/2/subpage">Subpage test/1/2/subpage</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/1/2/subpage" title="Subpage test/1/2/subpage">subpage</a></p>
<p><a rel="mw:WikiLink" href="./Subpage_test/1/2/subpage" title="Subpage test/1/2/subpage">Subpage test/1/2/subpage</a></p>
!! end

!! test
Parsoid: dot-slash prefixed wikilinks
!! wikitext
[[./foo]]

[[././bar]]

[[././baz/]]
!! html/php
<p>[[./foo]]
</p><p>[[././bar]]
</p><p>[[././baz/]]
</p>
!! html/parsoid
<p>[[./foo]]
</p><p>[[././bar]]
</p><p>[[././baz/]]
</p>
!! end

!! test
Render invalid page names as plain text (T53090)
!! wikitext
[[./../foo|bar]]
[[foo�|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~bar]]
[[foo>bar]]
[[foo[bar]]
[[.]]
[[..]]
[[foo././bar]]
[[foo[http://example.com]xyz]]

[[{{1x|./../foo}}|bar]]
[[{{1x|foo/.}}|bar]]
[[{{1x|foo/..}}|bar]]
[[{{1x|foo~~~~bar}}]]
[[{{1x|foo>bar}}]]
[[{{1x|foo././bar}}]]
[[{{1x|foo{bar}}]]
[[{{1x|foo}bar}}]]
[[{{1x|foo[bar}}]]
[[{{1x|foo]bar}}]]
[[{{1x|foo<bar}}]]
!!html/php
<p>[[./../foo|bar]]
[[foo�|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~bar]]
[[foo&gt;bar]]
[[foo[bar]]
[[.]]
[[..]]
[[foo././bar]]
[[foo<a rel="nofollow" class="external autonumber" href="http://example.com">[1]</a>xyz]]
</p><p>[[./../foo|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~~bar]]
[[foo&gt;bar]]
[[foo././bar]]
[[foo{bar]]
[[foo}bar]]
[[foo[bar]]
[[foo]bar]]
[[foo&lt;bar]]
</p>
!!html/parsoid
<p>[[./../foo|bar]]
[[foo�|bar]]
[[foo/.|bar]]
[[foo/..|bar]]
[[foo~~~bar]]
[[foo>bar]]
[[foo[bar]]
[[.]]
[[..]]
[[foo././bar]]
[[foo<a rel="mw:ExtLink" href="http://example.com" class="external autonumber"></a>xyz]]</p>

<p>[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"./../foo"}},"i":0}}]}'>./../foo</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo/."}},"i":0}}]}'>foo/.</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo/.."}},"i":0}}]}'>foo/..</span>|bar]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo~~~~bar"}},"i":0}}]}'>foo~~~~bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo>bar"}},"i":0}}]}'>foo>bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo././bar"}},"i":0}}]}'>foo././bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo{bar"}},"i":0}}]}'>foo{bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo}bar"}},"i":0}}]}'>foo}bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo[bar"}},"i":0}}]}'>foo[bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo]bar"}},"i":0}}]}'>foo]bar</span>]]
[[<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;bar"}},"i":0}}]}'>foo&lt;bar</span>]]</p>
!!end

!! test
Disabled subpages
!! wikitext
[[/subpage]]
!! html/php
<p><a href="/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href=".//subpage?action=edit&amp;redlink=1" title="/subpage" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":".//subpage"},"sa":{"href":"/subpage"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["/subpage"]}}'>/subpage</a></p>
!! end

!! test
T2561: {{/Subpage}}
!! options
subpage title=[[Page]]
!! wikitext
{{/Subpage}}
!! html/php
<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>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Page/Subpage?action=edit&amp;redlink=1" title="Page/Subpage" about="#mwt1" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./Page/Subpage"},"sa":{"href":"Page/Subpage"},"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"/Subpage","href":"./Page/Subpage"},"params":{},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Page/Subpage"]}}'>Page/Subpage</a></p>
!! end

!! test
Subpage with namespaces
!! options
subpage title=[[Subpage test/1/2/3/4]]
!! wikitext
[[User:../subpage]]
[[meatball:../subpage]]
!! html
<p>[[User:../subpage]]
[[meatball:../subpage]]
</p>
!! end

!! test
T335847: Resolve forward slash title
!! options
subpage title=[[/]]
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
===123===
!! html/php
<div class="mw-heading mw-heading3"><h3 id="123">123</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=/&amp;action=edit&amp;section=1" title="Edit section: 123">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h3 id="123" data-parsoid="{}">123</h3>
!! end

## The next two tests capture an inconsistency between relative link parsing on
## the "/" page in the legacy parser.  Parsoid's output seems preferable.

!! test
T335847: Resolve subpage of control title
!! options
subpage title=[[Asdf]]
!! wikitext
[[../Hi]]
!! html/php
<p>[[../Hi]]
</p>
!! html/parsoid
<p>[[../Hi]]</p>
!! end

!! test
T335847: Resolve subpage of forward slash title
!! options
subpage title=[[/]]
!! wikitext
[[../Hi]]
!! html/php
<p><a href="/index.php?title=/Hi&amp;action=edit&amp;redlink=1" class="new" title="/Hi (page does not exist)">/Hi</a>
</p>
!! html/parsoid
<p>[[../Hi]]</p>
!! end

###
### Categories
###
!! article
Category:MediaWiki User's Guide
!! text
blah
!! endarticle

!! test
Link to category
!! options
cat
!! wikitext
[[:Category:MediaWiki User's Guide]]
!! metadata
!! html
<p><a href="/wiki/Category:MediaWiki_User%27s_Guide" title="Category:MediaWiki User&#39;s Guide">Category:MediaWiki User's Guide</a>
</p>
!! end

!! test
Simple category
!! options
cat
!! metadata
cat=MediaWiki_User's_Guide sort=
!! wikitext
[[Category:MediaWiki User's Guide]]
!! html/php
!! 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
Simple category with whitespace as sort key
!! options
cat
!! metadata
cat=Foo sort= 
!! wikitext
[[Category:Foo| ]]
!! html/php
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Foo#%20" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo#%20"},"sa":{"href":"Category:Foo#%20"}}'/>
!! end

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

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

!! test
Category with newline in sort key
!! options
cat
parsoid=wt2html,html2html
!! wikitext
[[Category:Wikidata:Tools|
*]]
!! metadata
cat=Wikidata:Tools sort=
*
!! html/php
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Wikidata:Tools#*"/>
!! end

!! test
Category with template-generated sort key
!! options
cat
!! metadata
cat=MediaWiki_User's_Guide sort=MediaWiki Foo Guide
!! wikitext
[[Category:MediaWiki User's Guide|MediaWiki {{1x|Foo}} Guide]]
!! html/php
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:MediaWiki_User's_Guide#MediaWiki%20Foo%20Guide" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"mw:sortKey"},{"html":"MediaWiki &lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"Foo\"}},\"i\":0}}]}&apos;>Foo&lt;/span> Guide"}]]}'/>
!! end

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

Foo [[Category:Baz]]
Bar

Foo
[[Category:Baz]]
Bar

Foo
[[Category:Baz]] Bar

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

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

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

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

* Foo[[Category:Foo]][[Category:Bar]]Bar
* Foo[[Category:Foo]][[Category:Bar]] Bar
* Foo[[Category:Foo]] [[Category:Bar]]Bar
* Foo[[Category:Foo]] [[Category:Bar]] Bar
* Foo [[Category:Foo]][[Category:Bar]]Bar
* Foo [[Category:Foo]][[Category:Bar]] Bar
* Foo [[Category:Foo]] [[Category:Bar]]Bar
* Foo [[Category:Foo]] [[Category:Bar]] Bar
!! html/php
<ul><li>FooBar</li>
<li>Foo Bar</li>
<li>Foo Bar</li>
<li>Foo  Bar</li></ul>
<ul><li>FooBar</li>
<li>Foo Bar</li>
<li>Foo Bar</li>
<li>Foo  Bar</li>
<li>Foo Bar</li>
<li>Foo  Bar</li>
<li>Foo  Bar</li>
<li>Foo   Bar</li></ul>
!! html/parsoid
<ul>
<li>Foo<link rel="mw:PageProp/Category" href="./Category:Foo"/>Bar</li>
<li>Foo<link rel="mw:PageProp/Category" href="./Category:Foo"/> Bar</li>
<li>Foo <link rel="mw:PageProp/Category" href="./Category:Foo"/>Bar</li>
<li>Foo <link rel="mw:PageProp/Category" href="./Category:Foo"/> Bar</li>
</ul>
<ul>
<li>Foo<link rel="mw:PageProp/Category" href="./Category:Foo"/><link rel="mw:PageProp/Category" href="./Category:Bar"/>Bar</li>
<li>Foo<link rel="mw:PageProp/Category" href="./Category:Foo"/><link rel="mw:PageProp/Category" href="./Category:Bar"/> Bar</li>
<li>Foo<link rel="mw:PageProp/Category" href="./Category:Foo"/> <link rel="mw:PageProp/Category" href="./Category:Bar"/>Bar</li>
<li>Foo<link rel="mw:PageProp/Category" href="./Category:Foo"/> <link rel="mw:PageProp/Category" href="./Category:Bar"/> Bar</li>
<li>Foo <link rel="mw:PageProp/Category" href="./Category:Foo"/><link rel="mw:PageProp/Category" href="./Category:Bar"/>Bar</li>
<li>Foo <link rel="mw:PageProp/Category" href="./Category:Foo"/><link rel="mw:PageProp/Category" href="./Category:Bar"/> Bar</li>
<li>Foo <link rel="mw:PageProp/Category" href="./Category:Foo"/> <link rel="mw:PageProp/Category" href="./Category:Bar"/>Bar</li>
<li>Foo <link rel="mw:PageProp/Category" href="./Category:Foo"/> <link rel="mw:PageProp/Category" href="./Category:Bar"/> Bar</li>
</ul>
!! end

## Same as the above test, but with equally-invisible interlanguage links
!! test
Language link / non-newline whitespace interactions (T359886)
!! options
parsoid=wt2html
!! wikitext
* Foo[[es:Foo]]Bar
* Foo[[es:Foo]] Bar
* Foo [[es:Foo]]Bar
* Foo [[es:Foo]] Bar

* Foo[[es:Foo]][[es:Bar]]Bar
* Foo[[es:Foo]][[es:Bar]] Bar
* Foo[[es:Foo]] [[es:Bar]]Bar
* Foo[[es:Foo]] [[es:Bar]] Bar
* Foo [[es:Foo]][[es:Bar]]Bar
* Foo [[es:Foo]][[es:Bar]] Bar
* Foo [[es:Foo]] [[es:Bar]]Bar
* Foo [[es:Foo]] [[es:Bar]] Bar
!! html/php
<ul><li>FooBar</li>
<li>Foo Bar</li>
<li>Foo Bar</li>
<li>Foo  Bar</li></ul>
<ul><li>FooBar</li>
<li>Foo Bar</li>
<li>Foo Bar</li>
<li>Foo  Bar</li>
<li>Foo Bar</li>
<li>Foo  Bar</li>
<li>Foo  Bar</li>
<li>Foo   Bar</li></ul>
!! html/parsoid
<ul>
<li>Foo<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/>Bar</li>
<li>Foo<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/> Bar</li>
<li>Foo <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/>Bar</li>
<li>Foo <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/> Bar</li>
</ul>
<ul>
<li>Foo<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar"/>Bar</li>
<li>Foo<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar"/> Bar</li>
<li>Foo<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/> <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar"/>Bar</li>
<li>Foo<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/> <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar"/> Bar</li>
<li>Foo <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar"/>Bar</li>
<li>Foo <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar"/> Bar</li>
<li>Foo <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/> <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar"/>Bar</li>
<li>Foo <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo"/> <link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar"/> Bar</li>
</ul>
!! 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. cats/langlinks and newlines: All preceding newlines should be suppressed (courtesy T2087)
!! options
parsoid=wt2html
!! wikitext
This
   
[[Category:Foo]] and this
[[es:Foo]] and this should be part of same paragraph (not an indent-pre)
   
{{1x|[[Category:Foo]] and so should this!}}
{{1x|[[es:Foo]] and this!}}
!! html/php
<p>This and this and this should be part of same paragraph (not an indent-pre) and so should this! and this!
</p>
!! html/parsoid
<p>This
   
<link rel="mw:PageProp/Category" href="./Category:Foo" /> and this
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" /> and this should be part of same paragraph (not an indent-pre)
   
<link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Category:Foo]] and so should this!"}},"i":0}}]}'/><span about="#mwt1"> and so should this!</span>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[es:Foo]] and this!"}},"i":0}}]}'/><span about="#mwt2"> and 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. cats/langlinks and newlines: All preceding newlines should be suppressed (courtesy T2087)
!! options
parsoid=wt2html
!! wikitext
* This
   
[[Category:Foo]] and this
[[es:Foo]] and this should be part of the same list item
* So should this

{{1x|[[Category:Foo]] and this}}
{{1x|[[es:Foo]] and this should be part of the same list item}}
!! html/php
<ul><li>This and this and this should be part of the same list item</li>
<li>So should this and 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
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" /> and this should be part of the same list item</li>
<li>So should this

<link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Category:Foo]] and this"}},"i":0}}]}'/><span about="#mwt1"> and this</span>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[es:Foo]] and this should be part of the same list item"}},"i":0}}]}'/><span about="#mwt2"> 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. cats/langlinks and newlines: newline suppression for last list item should RT properly
!! wikitext
*a
*b
   
[[Category:Foo]]
   
[[Category:Bar]]
[[Category:Baz]]
[[es:Foo]]

:c

[[Category:C]]

;d

[[Category:D]]
[[es:Bar]]
!! html/parsoid
<ul><li>a</li>
<li>b</li></ul>
   
<link rel="mw:PageProp/Category" href="./Category:Foo" />
   
<link rel="mw:PageProp/Category" href="./Category:Bar" />
<link rel="mw:PageProp/Category" href="./Category:Baz" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" />

<dl><dd>c</dd></dl>

<link rel="mw:PageProp/Category" href="./Category:C" />

<dl><dt>d</dt></dl>

<link rel="mw:PageProp/Category" href="./Category:D" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Bar" />
!! end

!! test
4. cats/langlinks: newline suppression for last list item should RT properly
!! wikitext
*a
****b

[[Category:Foo]]
[[es: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" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" />
!! end

## only wt2html for this to make sure the algo only applies to the rightmost path
!! test
5. cats/langlinks: migrateTrailingSolTransparentLinks dom pass should only run on the rightmost path of nested lists
!! options
parsoid=wt2html
!! wikitext
*a
**b
[[Category:Foo]]
*c
**d
[[Category:Foo]]
[[es:Foo]]
!! html/parsoid
<ul><li>a
<ul><li>b
<link rel="mw:PageProp/Category" href="./Category:Foo" /></li></ul></li>
<li>c
<ul><li>d</li></ul></li></ul>
<link rel="mw:PageProp/Category" href="./Category:Foo" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/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. cats/langlinks: migrateTrailingSolTransparentLinks dom pass should not migrate them when not preceded by newlines
!! options
parsoid=wt2html
!! wikitext
*a [[Category:Foo]]
*b [[es:Foo]]
!! html/parsoid
<ul><li>a<link rel="mw:PageProp/Category" href="./Category:Foo" /></li>
<li>b<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/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. cats/langlinks: migrateTrailingSolTransparentLinks dom pass should leave template content alone
!! wikitext
*{{1x|a
[[Category:Foo]]
[[es:Foo]]}}
!! html/parsoid
<ul><li><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\n[[Category:Foo]]\n[[es:Foo]]"}},"i":0}}]}'>a
</span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" /><span about="#mwt1">
</span><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" about="#mwt1"/></li></ul>
!! end

!! test
8. cats/langlinks: migrateTrailingSolTransparentLinks dom pass should not get tripped by intervening templates
!! wikitext
*a

{{1x|[[Category:Foo]]
[[Category:Bar]]}}
[[Category:Baz]]
[[es:Baz]]
!! html/parsoid
<ul><li>a</li></ul>

<link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Category:Foo]]\n[[Category:Bar]]"}},"i":0}}]}'/><span about="#mwt1">
</span><link rel="mw:PageProp/Category" href="./Category:Bar" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Bar"},"sa":{"href":"Category:Bar"}}'/>
<link rel="mw:PageProp/Category" href="./Category:Baz" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:Baz"}}'/>
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Baz" />
!! end

!! test
cats/langlinks: migrateTrailingSolTransparentLinks dom pass should not get tripped by comments and whitespace
!! wikitext
*a

[[Category:Bar]]<!--boo1--> <!--boo2-->
[[Category:Baz]]<!--boo3--> <!--boo4-->
[[es:Foo]]<!--boo5--> <!--boo6-->
!! html/parsoid
<ul><li>a</li></ul>

<link rel="mw:PageProp/Category" href="./Category:Bar" /><!--boo1--> <!--boo2-->
<link rel="mw:PageProp/Category" href="./Category:Baz" /><!--boo3--> <!--boo4-->
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" /><!--boo5--> <!--boo6-->
!! end

!! test
Categories and newlines: should behave properly with linkprefix (T87753)
!! options
language=ar
!! wikitext
foo bar
foo bar
[[تصنيف:Foo]]
[[تصنيف:Bar]]
!! html/php
<p>foo bar
foo bar
</p>
!! html/parsoid
<p>foo bar
foo bar</p>
<link rel="mw:PageProp/Category" href="./تصنيف:Foo"/>
<link rel="mw:PageProp/Category" href="./تصنيف:Bar"/>
!! end

!! test
No regressions on internal links following category (T174639)
!! options
parsoid=wt2html,html2html
!! wikitext
[[Category:Foo]]<div>a

[[Foo]]</div>
!! html/php
<div>a
<a href="/wiki/Foo" title="Foo">Foo</a></div>
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Foo"/><div>a

<a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a></div>
!! end

# Note that Parsoid differs slightly from PHP due to T175421
!! test
11. Special case where only newlines separate links (T175416)
!! options
parsoid=wt2html,html2html
!! wikitext
[[Category:Foo]]

[[Foo]][[es:Alimento]]

[[Foo]]
!! html/php
<p><br />
<a href="/wiki/Foo" title="Foo">Foo</a>
</p><p><a href="/wiki/Foo" title="Foo">Foo</a>
</p>
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Foo"/>

<p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a></p><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Alimento"/>

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

!! test
Category links with multiple namespaces
!! wikitext
[[Category:Project:Foo]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Project:Foo" />
!! end

!! test
Parsoid: Serialize link to category page with colon escape
!! wikitext
[[:Category:Foo]]
[[:Category:Foo|Bar]]
!! html/php
<p><a href="/index.php?title=Category:Foo&amp;action=edit&amp;redlink=1" class="new" title="Category:Foo (page does not exist)">Category:Foo</a>
<a href="/index.php?title=Category:Foo&amp;action=edit&amp;redlink=1" class="new" title="Category:Foo (page does not exist)">Bar</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Category:Foo?action=edit&amp;redlink=1" title="Category:Foo" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":":Category:Foo"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Category:Foo"]}}'>Category:Foo</a>
<a rel="mw:WikiLink" href="./Category:Foo?action=edit&amp;redlink=1" title="Category:Foo" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"piped","a":{"href":"./Category:Foo"},"sa":{"href":":Category:Foo"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["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
Link prefix/suffixes aren't applied to language links
!! options
parsoid=wt2html
language=is
!! wikitext
x[[es:Foo]]y
!! html/php
<p>xy
</p>
!! html/parsoid
<p>x<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" data-parsoid=""/>y</p>
!! end

!! test
Parsoid: Serialize link to file page with colon escape
!! wikitext

[[:File:Foo.png]]
[[:File:Foo.png|Bar]]
!! html/php
<p><a href="/index.php?title=File:Foo.png&amp;action=edit&amp;redlink=1" class="new" title="File:Foo.png (page does not exist)">File:Foo.png</a>
<a href="/index.php?title=File:Foo.png&amp;action=edit&amp;redlink=1" class="new" title="File:Foo.png (page does not exist)">Bar</a>
</p>
!! html/parsoid

<p><a rel="mw:WikiLink" href="./File:Foo.png?action=edit&amp;redlink=1" title="File:Foo.png" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./File:Foo.png"},"sa":{"href":":File:Foo.png"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["File:Foo.png"]}}'>File:Foo.png</a>
<a rel="mw:WikiLink" href="./File:Foo.png?action=edit&amp;redlink=1" title="File:Foo.png" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"piped","a":{"href":"./File:Foo.png"},"sa":{"href":":File:Foo.png"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["File:Foo.png"]}}'>Bar</a></p>
!! end

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

!! test
Normalize hrefs properly before testing for invalid link targets (T72894)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Toxine_bactérienne"/>
!! wikitext
[[Category:Toxine bactérienne]]
!! end

!! article
Template:emptytemplate
!! text
!! endarticle

!! test
Empty templates should be handled properly without being redlinked
!! options
parsoid=wt2html
!! wikitext
{{emptytemplate}}
!! html/php
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"emptytemplate","href":"./Template:Emptytemplate"},"params":{},"i":0}}]}'></span>
!! end

!! test
Parsoid: Defaultsort
!! wikitext
{{DEFAULTSORT:Foo}}
!! html/parsoid+integrated
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DEFAULTSORT:Foo","function":"defaultsort"},"params":{},"i":0}}]}'></span>
!! end

!! test
Parsoid: Defaultsort variations (T236846)
!! wikitext
{{DEFAULTSORT}}

{{DEFAULTSORT:}}
{{DEFAULTSORT:DOGGIE}}
!! html/php
<p><a href="/index.php?title=Template:DEFAULTSORT&amp;action=edit&amp;redlink=1" class="new" title="Template:DEFAULTSORT (page does not exist)">Template:DEFAULTSORT</a>
</p><p><br />
</p>
!! html/parsoid+integrated
<p><a rel="mw:WikiLink" href="./Template:DEFAULTSORT?action=edit&amp;redlink=1" title="Template:DEFAULTSORT" about="#mwt1" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./Template:DEFAULTSORT"},"sa":{"href":"Template:DEFAULTSORT"},"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"DEFAULTSORT","href":"./Template:DEFAULTSORT"},"params":{},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:DEFAULTSORT"]}}'>Template:DEFAULTSORT</a></p>

<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DEFAULTSORT:","function":"defaultsort"},"params":{},"i":0}}]}'></span>
<span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DEFAULTSORT:DOGGIE","function":"defaultsort"},"params":{},"i":0}}]}'></span>
!! end

# Can be removed when T335843 is addressed
!! test
Parsoid html2wt b/c check: Defaultsort with key content being added (T236846)
!! options
parsoid=html2wt
!! html/parsoid
<meta property="mw:PageProp/categorydefaultsort" content="BIRD" data-parsoid='{"src":"{{DEFAULTSORT}}"}'/>
!! wikitext
{{DEFAULTSORT:BIRD}}
!! end

# NOTE: mw:ExpandedAttrs is not the best typeof here. mw:Transclusion is better.
# But, this is a limitation of our representation and is documented in
# TemplateHandler.php in processSpecialMagicWord
!! test
Parsoid: Defaultsort (template-generated)
!! wikitext
{{{{1x|DEFAULTSORT}}:Foo}}
!! html/parsoid+integrated
<span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{1x|DEFAULTSORT}}:Foo","function":"defaultsort"},"params":{},"i":0}}]}'></span>
!! end

!! test
{{defaultsort}} should be location-independent (T353530)
!! options
cat
!! wikitext
[[Category:Foo]]
{{DEFAULTSORT:Bar}}
[[Category:Bat]]
!! metadata
cat=Foo sort=Bar
cat=Bat sort=Bar
!! end

###
### Inter-language links
###
!! test
Interlanguage links
!! options
ill
!! wikitext
[[es:Alimento]]
[[fr:Nourriture]]
[[zh:食品]]
!! metadata
ill=es:Alimento
ill=fr:Nourriture
ill=zh:食品
!! html/php
!! 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

# Integrated-mode parsoid behavior will match other modes after
# I82a05a51d94782ebb9fa87ff889ca0f633b3e15c is merged in core.
!! test
Duplicate interlanguage links (T26502)
!! options
ill
!! wikitext
[[es:1]]
[[es:2]]
[[fr:1]]
[[fr:2]]
!! metadata
ill=es:1
ill=fr:1
!! html/php
!! 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

!! test
Single-line or multiline-comments can follow headings
!! options
parsoid=wt2html,wt2wt
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==foo==<!---->
==bar==<!--c1-->
==baz==<!--
c2
c3-->
!! html/php
<div class="mw-heading mw-heading2"><h2 id="foo">foo</h2><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></div>
<div class="mw-heading mw-heading2"><h2 id="bar">bar</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="baz">baz</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: baz">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="foo">foo</h2><!---->
<h2 id="bar">bar</h2><!--c1-->
<h2 id="baz">baz</h2><!--
c2
c3-->
!! end

!! test
T3186 news: in the middle of text
!! wikitext
http://en.wikinews.org/wiki/Wikinews:Workplace
!! html
<p><a rel="nofollow" class="external free" href="http://en.wikinews.org/wiki/Wikinews:Workplace">http://en.wikinews.org/wiki/Wikinews:Workplace</a>
</p>
!!end


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

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


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

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

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

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

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

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

!! test
div with empty attribute value, space before equals
!! options
parsoid=wt2html,html2html
!! wikitext
<div class =>HTML rocks</div>
!! html/php
<div class="">HTML rocks</div>
!! html/parsoid
<div class="" data-parsoid='{"stx":"html"}'>HTML rocks</div>
!! end

!! test
div with multiple empty attribute values
!! config
wgFragmentMode=[ "html5", "legacy" ]
!! options
parsoid=wt2html,html2html
!! wikitext
<div id= title=>HTML rocks</div>
!! html/php
<div id="title=">HTML rocks</div>
!! html/parsoid
<div id="title=" data-parsoid='{"stx":"html"}'>HTML rocks</div>
!! end

# FIXME Parsoid doesn't actually match PHP here.
!! test
Extension tag in attribute value
!! options
wgRawHtml=1
!! wikitext
<span title="<html><div>123</div></html>">ok</span>
!! html/php
<p><span title="&lt;div&gt;123&lt;/div&gt;">ok</span>
</p>
!! html/parsoid
<p><span title="123" about="#mwt4" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"title":"123"},"sa":{"title":"&lt;html>&lt;div>123&lt;/div>&lt;/html>"}}' data-mw='{"attribs":[[{"txt":"title"},{"html":"&lt;div typeof=\"mw:Extension/html\" about=\"#mwt3\" data-parsoid=&apos;{\"dsr\":[13,40,2,2]}&apos; data-mw=&apos;{\"name\":\"html\",\"attrs\":{},\"body\":{\"extsrc\":\"&amp;lt;div>123&amp;lt;/div>\"}}&apos;>123&lt;/div>"}]]}'>ok</span></p>
!! end

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

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

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

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

!! test
Table multiple attributes correction
!! wikitext
{|
!+ class="error" class="awesome"|status
|}
!! html
<table>
<tbody><tr>
<th class="awesome">status
</th></tr></tbody></table>
!! end

!! test
DIV IN UPPERCASE
!! wikitext
<DIV ID="x">HTML ROCKS</DIV>
!! html
<div id="x">HTML ROCKS</div>
!! end

!! test
Non-ASCII pseudo-tags are rendered as text
!! wikitext
<khyô>
!! html
<p>&lt;khyô&gt;
</p>
!! end

!! test
Pseudo-tag with URL 'name' renders as url link
!! wikitext
<http://example.com/>
!! html
<p>&lt;<a rel="nofollow" class="external free" href="http://example.com/">http://example.com/</a>&gt;
</p>
!! end

!! test
text with amp in the middle of nowhere
!! wikitext
Remember AT&T?
!! html
<p>Remember AT&amp;T?
</p>
!! end

!! test
text with character entity: eacute
!! wikitext
I always thought &eacute; was a cute letter.
!! html
<p>I always thought &#233; was a cute letter.
</p>
!! end

!! test
text with entity-escaped character entity-like string: eacute
!! wikitext
I always thought &amp;eacute; was a cute letter.
!! html
<p>I always thought &amp;eacute; was a cute letter.
</p>
!! end

!! test
text with undefined character entity: xacute
!! wikitext
I always thought &xacute; was a cute letter.
!! html
<p>I always thought &amp;xacute; was a cute letter.
</p>
!! end

!! test
Text with HTML5 semicolon-less entity (should not decode)
!! wikitext
&ampamp;
!! html/php
<p>&amp;ampamp;
</p>
!! html/parsoid
<p>&amp;ampamp;</p>
!! end

!! test
HTML5 tags
!! wikitext
<data value="5">five</data>
<time datetime="2000-01-01T00:00Z">The new millenium started</time>
<mark>This highlighted text</mark>
!! html
<p><data value="5">five</data>
<time datetime="2000-01-01T00:00Z">The new millenium started</time>
<mark>This highlighted text</mark>
</p>
!! end

!! test
HTML tag with leading space is parsed as text
!! wikitext
< div>foo< /div>
!! html
<p>&lt; div&gt;foo&lt; /div&gt;
</p>
!! end

## FIXME: The untrimmed attribute in Parsoid is T205737
!! test
Element with broken attribute syntax
!! options
parsoid=wt2html
!! wikitext
<div style=" style="123">hi</div>
<div =>ho</div>
!! html/php
<div style="style=">hi</div>
<div>ho</div>
!! html/parsoid
<div style=" style=" data-parsoid='{"stx":"html","a":{"123\"":null},"sa":{"123\"":""}}'>hi</div>
<div data-parsoid='{"stx":"html","a":{"=":null},"sa":{"=":""}}'>ho</div>
!! end

###
### Nesting tests (see T43545, T52604, T53081)
###

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

# This was T43545 in the PHP parser.
!! test
Nesting of <kbd>
!! wikitext
<kbd>X<kbd>Y</kbd>Z</kbd>
!! html
<p><kbd>X<kbd>Y</kbd>Z</kbd>
</p>
!! end

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

!! test
Nesting of <em>
!! wikitext
<em>X<em>Y</em>Z</em>
!! html
<p><em>X<em>Y</em>Z</em>
</p>
!! end

!! 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
<p><q>X<q>Y</q>Z</q>
</p>
!! end

!! test
Nesting of <ruby>
!! wikitext
<ruby>X<ruby>Y</ruby>Z</ruby>
!! html
<p><ruby>X<ruby>Y</ruby>Z</ruby>
</p>
!! end

!! test
Nesting of <bdo>
!! wikitext
<bdo>X<bdo>Y</bdo>Z</bdo>
!! html
<p><bdo>X<bdo>Y</bdo>Z</bdo>
</p>
!! end


###
### Media links
###

!! test
Media link
!! wikitext
[[Media:Foobar.jpg]]
[[Media:Video.ogv]]
[[:Media:Video.ogv]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Media:Foobar.jpg</a>
<a href="http://example.com/images/0/00/Video.ogv" class="internal" title="Video.ogv">Media:Video.ogv</a>
<a href="http://example.com/images/0/00/Video.ogv" class="internal" title="Video.ogv">Media:Video.ogv</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">Media:Foobar.jpg</a>
<a rel="mw:MediaLink" href="http://example.com/images/0/00/Video.ogv" resource="./Media:Video.ogv" title="Video.ogv">Media:Video.ogv</a>
<a rel="mw:MediaLink" href="http://example.com/images/0/00/Video.ogv" resource="./Media:Video.ogv" title="Video.ogv" data-parsoid='{"a":{"resource":"./Media:Video.ogv"},"sa":{"resource":":Media:Video.ogv"}}'>Media:Video.ogv</a></p>
!! end

!! test
Media link with text
!! wikitext
[[Media:Foobar.jpg|A neat file to look at]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">A neat file to look at</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">A neat file to look at</a></p>
!! end

# This won't pass in standalone mode because we don't have redirect handling in our mock data access.
# Not sure if it is worth dealing with it.
!! test
Media link redirect
!! wikitext
[[Media:Redirect to foobar.jpg]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Media:Redirect to foobar.jpg</a>
</p>
!! html/parsoid+integrated
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">Media:Redirect to foobar.jpg</a></p>
!! end

!! test
Localized media link
!! options
language=is
!! wikitext
[[Miðill:Foobar.jpg]]

[[Miðill:Foobar.jpg|Icelandic]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Miðill:Foobar.jpg</a>
</p><p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Icelandic</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Miðill:Foobar.jpg" title="Foobar.jpg">Miðill:Foobar.jpg</a></p>
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Miðill:Foobar.jpg" title="Foobar.jpg">Icelandic</a></p>
!! end

# FIXME: this is still bad HTML tag nesting
# FIXME: doBlockLevels won't wrap this in a paragraph because it contains a div
# Parsoid & Remex fix the p-wrapping since they operate on the DOM.
!! test
Media link with nasty text
!! options
parsoid=wt2html,html2html
!! wikitext
[[Media:Foobar.jpg|Safe Link<div style=display:none>" onmouseover="alert(document.cookie)" onfoo="</div>]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">Safe Link</a></p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg"><div style="display:none">" onmouseover="alert(document.cookie)" onfoo="</div></a>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">Safe Link</a></p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg"><div style="display:none" data-parsoid='{"stx":"html"}'>" onmouseover="alert(document.cookie)" onfoo="</div></a>
!! end

!! test
Media link from missing resource (parsoid-only)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg">Bat!</a>
!! wikitext
[[Media:Foobar.jpg|Bat!]]
!! end

!! test
Media link from missing resource, localized (parsoid-only)
!! options
parsoid=html2wt
language=is
!! html/parsoid
<a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg">Bat!</a>
!! wikitext
[[Miðill:Foobar.jpg|Bat!]]
!! end

# This is a test to ensure we don't crash or choke when given
# old cached 1.7.0 HTML for media links; we don't require that the
# result be "valid" because wt2wt was completely broken in 1.7.0
!! test
Media link from old 1.7.0 DOM spec (crash test, parsoid-only) T198511
!! options
parsoid=html2wt
!! html/parsoid
<p>This is what Parsoid would emit (and we still handle this HTML fine):</p>
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" title="Foobar.jpg">A neat file to look at</a></p>
<p>But VisualEditor would mangle the rel attribute, and give us back this:</p>
<p><a rel="mw:ExtLink" href="http://example.com/images/3/3a/Foobar.jpg" title="Foobar.jpg">A neat file to look at</a></p>
<p>But at least we don't crash when trying to handle the mangled HTML!</p>
!! wikitext
This is what Parsoid would emit (and we still handle this HTML fine):

[[Media:Foobar.jpg|A neat file to look at]]

But VisualEditor would mangle the rel attribute, and give us back this:

[http://example.com/images/3/3a/Foobar.jpg A neat file to look at]

But at least we don't crash when trying to handle the mangled HTML!
!! end

!! test
Media link to nonexistent file (T3702)
!! wikitext
[[Media:No such.jpg]]
[[Media:No_such file.jpg]]
!! html/php
<p><a href="/index.php?title=Special:Upload&amp;wpDestFile=No_such.jpg" class="new" title="No such.jpg">Media:No such.jpg</a>
<a href="/index.php?title=Special:Upload&amp;wpDestFile=No_such_file.jpg" class="new" title="No such file.jpg">Media:No_such file.jpg</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="./Special:FilePath/No_such.jpg" resource="./Media:No_such.jpg" title="No such.jpg" typeof="mw:Error" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}' data-parsoid='{"a":{"resource":"./Media:No_such.jpg"},"sa":{"resource":"Media:No such.jpg"}}'>Media:No such.jpg</a>
<a rel="mw:MediaLink" href="./Special:FilePath/No_such_file.jpg" resource="./Media:No_such_file.jpg" title="No such file.jpg" typeof="mw:Error" data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}' data-parsoid='{"a":{"resource":"./Media:No_such_file.jpg"},"sa":{"resource":"Media:No_such file.jpg"}}'>Media:No_such file.jpg</a></p>
!! end

!! test
Media link with nested wikilinks
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
[[Media:Foobar.jpg|[[Test]]]]
[[Media:Foobar.jpg|[[File:Foobar.jpg]]]]
!! html/php
<p>[[Media:Foobar.jpg|<a href="/wiki/Test" title="Test">Test</a>]]
[[Media:Foobar.jpg|<span class="mw-default-size" typeof="mw:File"><a href="/wiki/File:Foobar.jpg" class="mw-file-description"><img src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" class="mw-file-element" /></a></span>]]
</p>
!! html/parsoid
<p>[[Media:Foobar.jpg|<a rel="mw:WikiLink" href="./Test" title="Test" data-parsoid='{"stx":"simple","a":{"href":"./Test"},"sa":{"href":"Test"}}'>Test</a>]]
[[Media:Foobar.jpg|<span class="mw-default-size" typeof="mw:File" data-parsoid='{"optList":[]}'><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" 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"}}' class="mw-file-element"/></a></span>]]</p>
!! end

!! test
Media link with multiple options
!! wikitext
[[Media:Foobar.jpg|123|345]]
!! html/php
<p><a href="http://example.com/images/3/3a/Foobar.jpg" class="internal" title="Foobar.jpg">123|345</a>
</p>
!! html/parsoid
<p><a rel="mw:MediaLink" href="http://example.com/images/3/3a/Foobar.jpg" resource="./Media:Foobar.jpg" title="Foobar.jpg">123|345</a></p>
!! end

!! test
Character reference normalization in link text (T3938)
!! wikitext
[[Main Page|this&that]]
!! html
<p><a href="/wiki/Main_Page" title="Main Page">this&amp;that</a>
</p>
!! end

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

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

# Parsoid has a regression here (T258858) note the incorrect redlink as well
!! test
(T21451) Links should refer to the normalized form.
!! wikitext
[[&#xFB2E;]]
[[&#x5d0;&#x5b7;]]
[[&#x5d0;ַ]]
[[א&#x5b7;]]
[[אַ]]
!! html/php
<p><a href="/wiki/%D7%90%D6%B7" title="אַ">&#xfb2e;</a>
<a href="/wiki/%D7%90%D6%B7" title="אַ">&#x5d0;&#x5b7;</a>
<a href="/wiki/%D7%90%D6%B7" title="אַ">&#x5d0;ַ</a>
<a href="/wiki/%D7%90%D6%B7" title="אַ">א&#x5b7;</a>
<a href="/wiki/%D7%90%D6%B7" title="אַ">אַ</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./אַ?action=edit&amp;redlink=1" title="אַ" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"&amp;#xFB2E;"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["אַ"]}}'>אַ</a>
<a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"&amp;#x5d0;&amp;#x5b7;"}}'>אַ</a>
<a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"&amp;#x5d0;ַ"}}'>אַ</a>
<a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"א&amp;#x5b7;"}}'>אַ</a>
<a rel="mw:WikiLink" href="./אַ" title="אַ" data-parsoid='{"stx":"simple","a":{"href":"./אַ"},"sa":{"href":"אַ"}}'>אַ</a></p>
!! end

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

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

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

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

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

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

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

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

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


###
### Safety
###

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

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

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

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

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

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

!! test
T4304: HTML attribute safety (safe parameter; 2309)
!! wikitext
{{div style|width: 200px}}
!! html/php
<div style="float: right; width: 200px">Magic div</div>
!! html/parsoid
<div style="float: right; width: 200px" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","a":{"style":"float: right; width: 200px"},"sa":{"style":"float: right; {{{1}}}"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"div style","href":"./Template:Div_style"},"params":{"1":{"wt":"width: 200px"}},"i":0}}]}'>Magic div</div>
!! end

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

!! test
T4304: HTML attribute safety (unsafe breakout parameter; 2309)
!! wikitext
{{div style|"><script>alert(document.cookie)</script>}}
!! html/php
<div style="float: right;">&lt;script&gt;alert(document.cookie)&lt;/script&gt;"&gt;Magic div</div>
!! html/parsoid+integrated
<div style="float: right; " about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"div style","href":"./Template:Div_style"},"params":{"1":{"wt":"\">&lt;script>alert(document.cookie)&lt;/script>"}},"i":0}}]}'>&lt;script>alert(document.cookie)&lt;/script>">Magic div</div>
!! end

!! test
T4304: HTML attribute safety (unsafe breakout parameter 2; 2309)
!! wikitext
{{div style|" ><script>alert(document.cookie)</script>}}
!! html/php
<div style="float: right;">&lt;script&gt;alert(document.cookie)&lt;/script&gt;"&gt;Magic div</div>
!! html/parsoid+integrated
<div style="float: right; " about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"div style","href":"./Template:Div_style"},"params":{"1":{"wt":"\" >&lt;script>alert(document.cookie)&lt;/script>"}},"i":0}}]}'>&lt;script>alert(document.cookie)&lt;/script>">Magic div</div>
!! end

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

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

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

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

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

!! test
T5244: HTML attribute safety (extension; safe)
!! wikitext
<div style="<nowiki>background:blue</nowiki>"></div>
!! html/php
<div style="background:blue"></div>
!! html/parsoid
<div style="background:blue" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"style":"background:blue"},"sa":{"style":"&lt;nowiki>background:blue&lt;/nowiki>"}}' data-mw='{"attribs":[[{"txt":"style"},{"html":"&lt;span typeof=\"mw:Nowiki\" data-parsoid=&apos;{\"dsr\":[12,44,8,9]}&apos;>background:blue&lt;/span>"}]]}'></div>
!! end

!! test
T5244: HTML attribute safety (extension; unsafe)
!! wikitext
<div style="<nowiki>border-left:expression(alert(document.cookie))</nowiki>"></div>
!! html/php
<div style="/* insecure input */"></div>
!! html/parsoid
<div style="/* insecure input */" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"style":"/* insecure input */"},"sa":{"style":"&lt;nowiki>border-left:expression(alert(document.cookie))&lt;/nowiki>"}}' data-mw='{"attribs":[[{"txt":"style"},{"html":"&lt;span typeof=\"mw:Nowiki\" data-parsoid=&apos;{\"dsr\":[12,75,8,9]}&apos;>border-left:expression(alert(document.cookie))&lt;/span>"}]]}'></div>
!! end

# More MSIE fun discovered by Tom Gilder

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

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

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

!! test
MSIE CSS safety test: comment in expression
!! wikitext
<div style="background-image:expres/**/sion(alert('boo4'))">evil4</div>
!! html/php
<div style="background-image:expres sion(alert(&#39;boo4&#39;))">evil4</div>
!! html/parsoid
<div style="background-image:expres sion(alert('boo4'))" data-parsoid='{"stx":"html","a":{"style":"background-image:expres sion(alert(&#39;boo4&#39;))"},"sa":{"style":"background-image:expres/**/sion(alert(&#39;boo4&#39;))"}}'>evil4</div>
!! end

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

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

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

!! test
Table attribute safety
!! wikitext
{|
!+ style="<nowiki>border-width:expression(0+alert(document.cookie))</nowiki>"|status
|}
!! html
<table>
<tbody><tr>
<th style="/* insecure input */">status
</th></tr></tbody></table>
!! end

!! test
CSS line continuation 1
!! wikitext
<div style="background-image: u\&#10;rl(test.jpg);"></div>
!! html
<div style="/* insecure input */"></div>
!! end

!! test
CSS line continuation 2
!! wikitext
<div style="background-image: u\&#13;rl(test.jpg); "></div>
!! html
<div style="/* invalid control char */"></div>
!! end

!! test
Allow aria attributes
!! config
wgFragmentMode=[ "legacy" ]
!! wikitext
<span aria-describedby="id1" aria-flowto="id2" aria-hidden="true" aria-label="id3" aria-labelledby="id4" aria-level="3" aria-owns="id5">foo</span>
<span aria-bogus="stripped">bar</span>
!! html/php
<p><span aria-describedby="id1" aria-flowto="id2" aria-hidden="true" aria-label="id3" aria-labelledby="id4" aria-level="3" aria-owns="id5">foo</span>
<span>bar</span>
</p>
!! html/parsoid
<p><span aria-describedby="id1" aria-flowto="id2" aria-hidden="true" aria-label="id3" aria-labelledby="id4" aria-level="3" aria-owns="id5">foo</span>
<span data-parsoid='{"stx":"html","a":{"aria-bogus":null},"sa":{"aria-bogus":"stripped"}}'>bar</span></p>
!! end

!! test
Expansion of multi-line templates in attribute values (T8255)
!! wikitext
<div style="background: {{1x|#00FF00}}">-</div>
!! html/php
<div style="background: #00FF00">-</div>
!! html/parsoid+integrated
<div style="background: 
#00FF00" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"style":"background: \n#00FF00"},"sa":{"style":"background: {{1x|#00FF00}}"}}' data-mw='{"attribs":[[{"txt":"style"},{"html":"background: &lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"}]],\"dsr\":[24,38,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"#00FF00\"}},\"i\":0}}]}&apos;>\n#00FF00&lt;/span>"}]]}'>-</div>
!! end

### FIXME ptsync 2024-02-21: "multi-line" part of these tests appears to
### have been lost at some point.

### FIXME ptsync 2024-02-21: {{#if}} is not defined for core tests, so
### this test should use a different parser function (maybe {{lc}}); marked
### html/php+disabled for now.

!! test
Expansion of multi-line parser-functions in attribute values (T8255)
!! wikitext
<div style="background: {{#if:1|#00FF00|#FF00FF}}">-</div>
!! html/php+disabled
<div style="background: #00FF00">-</div>
!! html/parsoid+integrated
<div style="background: 
#00FF00" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"style":"background: \n#00FF00"},"sa":{"style":"background: {{#if:1|#00FF00|#FF00FF}}"}}' data-mw='{"attribs":[[{"txt":"style"},{"html":"background: &lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-parsoid=&apos;{\"pi\":[[{\"k\":\"1\"},{\"k\":\"2\"}]],\"dsr\":[24,49,null,null]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:1\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"#00FF00\"},\"2\":{\"wt\":\"#FF00FF\"}},\"i\":0}}]}&apos;>\n#00FF00&lt;/span>"}]]}'>-</div>
!! end

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

# BlockLevelPass suppresses P-wrapping for tags whose names begin with
# `mw:`.  We'll somewhat arbitrarily chose `mw:editsection` to
# represent this class of tags for testing purposes.
!! test
Tags which are hidden from tidiers cannot pass through the Sanitizer
!! options
parsoid=wt2html,html2html
!! wikitext
<mw:editsection><script>alert();</script></mw:editsection>

<meta property="mw:PageProp/toc" />
!! html/php
<p>&lt;mw:editsection&gt;&lt;script&gt;alert();&lt;/script&gt;&lt;/mw:editsection&gt;
</p><p>&lt;meta property="mw:PageProp/toc" /&gt;
</p>
!! html/parsoid
<p>&lt;mw:editsection>&lt;script>alert();&lt;/script>&lt;/mw:editsection></p>

<p>&lt;meta property="mw:PageProp/toc" /></p>
!! end

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

!! test
Parser hook: empty input
!! wikitext
<tag></tag>
!! html/php
<pre>''
array (
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":""}}' about="#mwt2">''
array (
)</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" about="#mwt3" data-mw='{"name":"tag","attrs":{}}'>NULL
array (
)
</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" about="#mwt3" data-mw='{"name":"tag","attrs":{}}'>NULL
array (
)
</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"}}' about="#mwt2">'input'
array (
)</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" about="#mwt3" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"input"}}'>'input'
array (
)
</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" about="#mwt3" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"input"}}'>'input'
array (
)
</pre>
!! end

!! test
Parser hook: nested tags
!! options
parsoid=wt2html
!! wikitext
<tag><tag></tag></tag>
!! html/php
<pre>'<tag>'
array (
)
</tag></pre><p>&lt;/tag&gt;</p>
!! html/parsoid
<pre typeof="mw:Extension/tag" about="#mwt3" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"&lt;tag>"}}'>'<tag>'
array (
)
</tag></pre><p>&lt;/tag></p>
!! end

!! test
Parser hook: basic arguments
!! wikitext
<tag width="200" height="100" depth="50" square=""></tag>
!! html/php
<pre>''
array (
  'width' =&gt; '200',
  'height' =&gt; '100',
  'depth' =&gt; '50',
  'square' =&gt; '',
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" about="#mwt3" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":{"extsrc":""}}'>''
array (
  'width' => '200',
  'height' => '100',
  'depth' => '50',
  'square' => '',
)
</pre>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: basic arguments, variations
!! options
parsoid=wt2html,html2html
!! wikitext
<tag width=200 height = "100" depth = '50' square></tag>
!! html/php
<pre>''
array (
  'width' =&gt; '200',
  'height' =&gt; '100',
  'depth' =&gt; '50',
  'square' =&gt; '',
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" about="#mwt3" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":{"extsrc":""}}'>''
array (
  'width' => '200',
  'height' => '100',
  'depth' => '50',
  'square' => '',
)
</pre>
!! end

!! test
Parser hook: argument containing a forward slash (T7344)
!! wikitext
<tag filename="/tmp/bla"></tag>
!! html/php
<pre>''
array (
  'filename' =&gt; '/tmp/bla',
)
</pre>
!! html/parsoid
<pre typeof="mw:Extension/tag" about="#mwt3" data-mw='{"name":"tag","attrs":{"filename":"/tmp/bla"},"body":{"extsrc":""}}'>''
array (
  'filename' => '/tmp/bla',
)
</pre>
!! end

## Don't expect parsoid to rt this form.
!! test
Parser hook: empty input using terminated empty elements (T4374)
!! options
parsoid=wt2html,html2html
!! wikitext
<tag foo=bar/>text
!! html/php
<pre>NULL
array (
  'foo' =&gt; 'bar',
)
</pre><p>text</p>
!! html/parsoid
<pre typeof="mw:Extension/tag" about="#mwt3" data-mw='{"name":"tag","attrs":{"foo":"bar"}}'>NULL
array (
  'foo' => 'bar',
)
</pre><p>text</p>
!! end

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

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

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

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

!! test
Parser hook: horizontal rule inside extension tag that outputs <pre>
!! wikitext
<tag>
Hello
<hr/>
Goodbye
</tag>
!! html/php
<pre>'
Hello
<hr />
Goodbye
'
array (
)
</pre>
!! end

###
### (see tests/parser/ParserTestParserHook.php for the <statictag> extension)
###

!! test
Parser hook: static parser hook not inside a comment
!! wikitext
<statictag>hello, world</statictag>

<statictag action="flush" />
!! html/php
<p><br />
hello, world
</p>
!! html/parsoid
<p><span typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{},"body":{"extsrc":"hello, world"}}' about="#mwt2"></span></p>
<p><span typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{"action":"flush"}}' about="#mwt4">hello, world</span></p>
!! end

!! test
Parser hook: static parser hook inside a comment
!! wikitext
<!-- <statictag>hello, world</statictag> -->
<statictag action="flush" />
!! html/php
<p><br />
</p>
!! html/parsoid
<!-- <statictag&#x3E;hello, world</statictag&#x3E; -->
<p><span typeof='mw:Extension/statictag' data-mw='{"name":"statictag","attrs":{"action":"flush"}}' data-parsoid='{}' about='#mwt2'></span></p>
!! end

# Nested template calls; this case was broken by Parser.php rev 1.506,
# since reverted.

!! article
Template:One-parameter
!! text
(My parameter is: {{{1}}})
!! endarticle

!! article
Template:Map-one-parameter
!! text
{{{{{1}}}|{{{2}}}}}
!! endarticle

!! test
Nested template calls
!! wikitext
{{Map-one-parameter|One-parameter|param}}
!! html
<p>(My parameter is: param)
</p>
!! end


###
### Sanitizer
###

!! test
Sanitizer: Closing of open tags
!! wikitext
<s></s><table></table>
!! html/php
<p><s></s></p><table></table>
!! html/parsoid
<p><s data-parsoid='{"stx":"html"}'></s></p><table data-parsoid='{"stx":"html"}'></table>
!! end

# Legacy parser adds an extra newline (seen as a space) which Parsoid does not
!! test
Sanitizer: Closing of open but not closed tags
!! wikitext
<s>foo
!! html/php
<p><s>foo
</s></p>
!! html/parsoid
<p><s data-parsoid='{"stx":"html","autoInsertedEnd":true}'>foo</s></p>
!! end

!! test
Sanitizer: Closing of closed but not open tags
!! options
parsoid=wt2html
!! wikitext
</s>
!! html
<p class="mw-empty-elt">
</p>
!! end

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

!! test
Sanitizer: Escaping of spaces, multibyte characters, colons & other stuff in id=""
!! options
title=[[Main Page]]
!! config
wgFragmentMode=[ "html5", "legacy" ]
!! wikitext
<span id="æ: v">byte</span>[[#æ: v|backlink]]
!! html/php
<p><span id="æ:_v">byte</span><a href="#æ:_v">backlink</a>
</p>
!! html/parsoid
<p><span id="æ:_v" data-parsoid='{"stx":"html","a":{"id":"æ:_v"},"sa":{"id":"æ: v"}}'>byte</span><a rel="mw:WikiLink" href="./Main_Page#æ:_v" class="mw-selflink-fragment" data-parsoid='{"stx":"piped","a":{"href":"./Main_Page#æ:_v"},"sa":{"href":"#æ: v"}}'>backlink</a></p>
!! end

!! test
Sanitizer: Escaping of spaces, multibyte characters, colons & other stuff in id="" (legacy)
!! config
wgFragmentMode=[ "legacy" ]
!! wikitext
<span id="æ: v">byte</span>[[#æ: v|backlink]]
!! html/php
<p><span id=".C3.A6:_v">byte</span><a href="#.C3.A6:_v">backlink</a>
</p>
!! end

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

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

!! test
Sanitizer: Validating that <meta> and <link> work, but only for Microdata
!! wikitext
<div itemscope>
	<meta itemprop="hello" content="world">
	<meta http-equiv="refresh" content="5">
	<meta itemprop="hello" http-equiv="refresh" content="5">
	<link itemprop="hello" href="{{SERVER}}">
	<link rel="stylesheet" href="{{SERVER}}">
	<link rel="stylesheet" itemprop="hello" href="{{SERVER}}">
</div>
!! html
<div itemscope="">
<p>	<meta itemprop="hello" content="world" />
	&lt;meta http-equiv="refresh" content="5"&gt;
	<meta itemprop="hello" content="5" />
	<link itemprop="hello" href="http&#58;//example.org" />
	&lt;link rel="stylesheet" href="<a rel="nofollow" class="external free" href="http://example.org">http://example.org</a>"&gt;
	<link itemprop="hello" href="http&#58;//example.org" />
</p>
</div>
!! end

!! test
Sanitizer: Strip comments from CSS attributes
!! options
parsoid=wt2html,wt2wt
!! wikitext
<span style="margin:/*negate mbox-text padding */-0.125em -0.45em; /*rainbow*/rgba(255, 0, 0, 0.3)">2013</span>
!! html/php
<p><span style="margin: -0.125em -0.45em;  rgba(255, 0, 0, 0.3)">2013</span>
</p>
!! html/parsoid
<p><span style="margin: -0.125em -0.45em;  rgba(255, 0, 0, 0.3)">2013</span></p>
!! end

!! test
Sanitizer: Avoid unnecessary percent encoded characters in interwiki links
!! wikitext
[[meatball:Soft"Security]]
!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?Soft%22Security" class="extiw" title="meatball:Soft&quot;Security">meatball:Soft"Security</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href='http://www.usemod.com/cgi-bin/mb.pl?Soft"Security' title='meatball:Soft"Security' class="extiw">meatball:Soft"Security</a></p>
!! end

!! test
Sanitizer: angle brackets are invalid, even in interwiki links (T182338)
!! wikitext
[[meatball:Foo<Bar]]
[[meatball:Foo>Bar]]
[[meatball:Foo&lt;bar]]
[[meatball:Foo&gt;bar]]
!! html/php
<p>[[meatball:Foo&lt;Bar]]
[[meatball:Foo&gt;Bar]]
[[meatball:Foo&lt;bar]]
[[meatball:Foo&gt;bar]]
</p>
!! html/parsoid
<p>[[meatball:Foo&lt;Bar]]
[[meatball:Foo>Bar]]
[[meatball:Foo<span typeof="mw:Entity" data-parsoid='{"src":"&amp;lt;","srcContent":"&lt;"}'>&lt;</span>bar]]
[[meatball:Foo<span typeof="mw:Entity" data-parsoid='{"src":"&amp;gt;","srcContent":">"}'>></span>bar]]</p>
!! end

!! test
Self closed html pairs (T7487)
!! wikitext
<center><font id="bug" />Centered text</center>
<div><font id="bug2" />In div text</div>
!! html
<center><font id="bug">Centered text</font></center><font id="bug"><div><font id="bug2">In div text</font></div></font>
!! end

!! test
Punctuation: nbsp before exclamation
!! wikitext
C'est grave !
!! html/php
<p>C'est grave&#160;!
</p>
!! html/parsoid
<p>C'est grave<span typeof="mw:DisplaySpace"> </span>!</p>
!! end

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

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

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

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

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

!! test
HTML nested ordered list, open tags (T7497)
!! wikitext
<ol>
<li>One
<li>Two:
<ol>
<li>Sub-one
<li>Sub-two
</ol>
</ol>
!! html/php
<ol>
<li>One
</li><li>Two:
<ol>
<li>Sub-one
</li><li>Sub-two
</li></ol>
</li></ol>
!! html/parsoid
<ol>
<li>One
</li>
<li>Two:
<ol>
<li>Sub-one
</li>
<li>Sub-two
</li>
</ol>
</li>
</ol>
!! end

!! test
HTML ordered list item with parameters oddity
!! wikitext
<ol><li id="fragment">One</li>
</ol>
!! html
<ol><li id="fragment">One</li>
</ol>
!! end

# parsoid doesn't explicitly mark autonumbered links, see T55505
!!test
T7918: autonumbering
!! wikitext
[http://first/] [http://second] [ftp://ftp]

ftp://inlineftp

[mailto:enclosed@mail.tld With target]

[mailto:enclosed@mail.tld]

mailto:inline@mail.tld
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://first/">[1]</a> <a rel="nofollow" class="external autonumber" href="http://second">[2]</a> <a rel="nofollow" class="external autonumber" href="ftp://ftp">[3]</a>
</p><p><a rel="nofollow" class="external free" href="ftp://inlineftp">ftp://inlineftp</a>
</p><p><a rel="nofollow" class="external text" href="mailto:enclosed@mail.tld">With target</a>
</p><p><a rel="nofollow" class="external autonumber" href="mailto:enclosed@mail.tld">[4]</a>
</p><p><a rel="nofollow" class="external free" href="mailto:inline@mail.tld">mailto:inline@mail.tld</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://first/" class="external autonumber"></a> <a rel="mw:ExtLink" href="http://second" class="external autonumber"></a> <a rel="mw:ExtLink" href="ftp://ftp" class="external autonumber"></a></p>
<p><a rel="mw:ExtLink" href="ftp://inlineftp" class="external free">ftp://inlineftp</a></p>
<p><a rel="mw:ExtLink" href="mailto:enclosed@mail.tld" class="external text">With target</a></p>
<p><a rel="mw:ExtLink" href="mailto:enclosed@mail.tld" class="external autonumber"></a></p>
<p><a rel="mw:ExtLink" href="mailto:inline@mail.tld" class="external free">mailto:inline@mail.tld</a></p>
!! end


#
# Security and HTML correctness
# From Nick Jenkins' fuzz testing
#

!! test
Fuzz testing: Parser13
!! wikitext
{| 
| http://a|
!! html
<table>
<tbody><tr>
<td>
</td>
</tr>
</tbody></table>
!! end

# Known to produce bogus xml (extra </td>)
# Don't add the html/php section since it generates broken HTML
!! test
Fuzz testing: Parser16
!! wikitext
{|
!https://||||||
!! html
<table>
<tbody><tr>
<th>https://</th>
<th></th>
<th></th>
<th>

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

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

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

{|
!! html/php
<p><a rel="nofollow" class="external free" href="http://===r:::https://b">http://===r:::https://b</a>
</p>
<table>
<tbody><tr><td></td></tr>
</tbody></table>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://===r:::https://b" class="external free" data-parsoid='{"stx":"url"}'>http://===r:::https://b</a></p>

<table data-parsoid='{"autoInsertedEnd":true}'></table>
!! end

# The above 'Parser24' fuzz test exposed a tokenizer bug (T221384);
# this is a minimized version of the above test to catch regressions.
!! test
Fuzz testing: Parser24 (minimized)
!! options
parsoid=wt2html
!! wikitext
{{<u {{{{[[Sx-->}}
!! html/php
<p>{{<u>}}
</u></p>
!! html/parsoid
<p>{{<u data-parsoid='{"stx":"html","a":{"{{{{[[Sx--":null},"sa":{"{{{{[[Sx--":""},"autoInsertedEnd":true}'>}}</u></p>
!! end

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

MOVE YOUR MOUSE CURSOR OVER THIS TEXT
|
!! html/php

{{{|
<u class="&#124;">}}}} &gt;
<br style="onmouseover=&#39;alert(document.cookie);&#39;" />

MOVE YOUR MOUSE CURSOR OVER THIS TEXT
</u><table><tbody><tr>
<td>
</td>
</tr>
</tbody></table>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>
{{{|
<u class="|" data-parsoid='{"stx":"html","a":{"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--":null},"sa":{"{{{{SSSll!!!!!!!VVVV)]]][[Special:*xxxxxxx--":""},"autoInsertedEnd":true}'><meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>}}}} >
<br style="onmouseover='alert(document.cookie);' " data-parsoid='{"stx":"html","selfClose":true}'/>

MOVE YOUR MOUSE CURSOR OVER THIS TEXT</u></p>
<table data-parsoid='{"autoInsertedEnd":true}'><tbody><tr data-parsoid='{"autoInsertedStart":true}'><td></td></tr></tbody></table>
!! end

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

!!test
Fuzz testing: URL adjacent extension (with space, clean)
!! wikitext
http://example.com <nowiki>junk</nowiki>
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a> junk
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a> <span typeof="mw:Nowiki">junk</span></p>
!! end

!!test
Fuzz testing: URL adjacent extension (no space, dirty; nowiki)
!! wikitext
http://example.com<nowiki>junk</nowiki>
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a>junk
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a><span typeof="mw:Nowiki">junk</span></p>
!! end

!! test
Fuzz testing: URL adjacent extension (no space, dirty; pre)
!! wikitext
http://example.com<pre>junk</pre>
!! html/php
<p><a rel="nofollow" class="external free" href="http://example.com">http://example.com</a></p><pre>junk</pre>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com" class="external free" data-parsoid='{"stx":"url"}'>http://example.com</a></p><pre typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"junk"}}'>junk</pre>
!! end

# Parsoid will emit the newline literally in wt2wt; see next test case.
!! test
Fuzz testing: encoded newline in generated HTML replacements (T8577)
!! options
parsoid=wt2html
!! wikitext
<pre dir="&#10;"></pre>
!! html/php
<pre dir="&#10;"></pre>
!! html/parsoid
<pre dir="
" typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{"dir":""},"body":{"extsrc":""}}'></pre>
!! end

!! test
Fuzz testing: encoded newline in generated HTML replacements, html2wt (T8577)
!! options
parsoid=html2wt
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt2" dir="
" data-mw='{"name":"pre","attrs":{"dir":"\n"},"body":{"extsrc":""}}'></pre>
!! wikitext
<pre dir="
"></pre>
!! html/php
<pre dir=""></pre>
!! end

!! test
Templates in extension attributes are not expanded
!! wikitext
<pre dir="{{1x|ltr}}"></pre>
!! html/php
<pre dir="{{1x|ltr}}"></pre>
!! html/parsoid
<pre dir="{{1x|ltr}}" typeof="mw:Extension/pre" about="#mwt2" data-mw='{"name":"pre","attrs":{"dir":"{{1x|ltr}}"},"body":{"extsrc":""}}'></pre>
!! end

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

!! test
Correct handling of <td>, <tr> (T8171)
!! options
!! wikitext
<table>
  <tr>
    <td> Some tabular data</td>
    <td> More tabular data ...</td>
    <td> And yet som tabular data</td>
  </tr>
</table>
!! html
<table>
  <tbody><tr>
    <td> Some tabular data</td>
    <td> More tabular data ...</td>
    <td> And yet som tabular data</td>
  </tr>
</tbody></table>
!! end


!! test
Parsing crashing regression (fr:JavaScript)
!! wikitext
</body></x>
!! html
<p>&lt;/body&gt;&lt;/x&gt;
</p>
!! end

!! test
Inline wiki vs wiki block nesting
!! wikitext
'''Bold paragraph

New wiki paragraph
!! html
<p><b>Bold paragraph</b>
</p><p>New wiki paragraph
</p>
!! end

# FIXME: The current php output is documented
# and desired output is the parsoid target.
!! test
Inline HTML vs wiki block nesting
!! wikitext
<b>Bold paragraph

New wiki paragraph
!! html/php
<p><b>Bold paragraph
</b></p><p><b>New wiki paragraph
</b></p>
!! html/parsoid
<p><b>Bold paragraph</b>
</p><p>New wiki paragraph
</p>
!! end

# Original result was this:
# <p><b>bold</b><b>bold<i>bolditalics</i></b>
# </p>
# While that might be marginally more intuitive, maybe, the six-apostrophe
# construct is clearly pathological and the result stated here (which is what
# the parser actually does) is about as reasonable as anything.
!!test
Mixing markup for italics and bold
!! options
!! wikitext
'''bold''''''bold''bolditalics'''''
!! html
<p>'<i>bold'</i><b>bold<i>bolditalics</i></b>
</p>
!! end


!! article
Xyzzyx
!! text
Article for special page transclusion test
!! endarticle

!! test
Special page transclusion
!! wikitext
{{Special:Prefixindex/Xyzzyx}}
!! html/php
<ul class="mw-prefixindex-list"><li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>
!! html/parsoid+integrated
<ul class="mw-prefixindex-list" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Special:Prefixindex/Xyzzyx","href":"./Special:PrefixIndex/Xyzzyx"},"params":{},"i":0}}]}'>
<li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>
!! end

!! test
Special page transclusion twice (T7021)
!! wikitext
{{Special:Prefixindex/Xyzzyx}}
{{Special:Prefixindex/Xyzzyx}}
!! html/php
<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>
!! html/parsoid+integrated
<ul class="mw-prefixindex-list" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Special:Prefixindex/Xyzzyx","href":"./Special:PrefixIndex/Xyzzyx"},"params":{},"i":0}}]}'>
<li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>
<ul class="mw-prefixindex-list" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Special:Prefixindex/Xyzzyx","href":"./Special:PrefixIndex/Xyzzyx"},"params":{},"i":0}}]}'>
<li><a href="/wiki/Xyzzyx" title="Xyzzyx">Xyzzyx</a></li>
</ul>
!! end

!! test
Transclusion of default MediaWiki message
!! wikitext
{{MediaWiki:Mainpage}}
!! html/php
<p>Main Page
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"MediaWiki:Mainpage","href":"./MediaWiki:Mainpage"},"params":{},"i":0}}]}'>Main Page</span></p>
!! end

!! test
Transclusion of nonexistent MediaWiki message
!! wikitext
{{MediaWiki:Mainpagexxx}}
!! html/php
<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>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./MediaWiki:Mainpagexxx?action=edit&amp;redlink=1" title="MediaWiki:Mainpagexxx" about="#mwt1" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./MediaWiki:Mainpagexxx"},"sa":{"href":"MediaWiki:Mainpagexxx"},"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"MediaWiki:Mainpagexxx","href":"./MediaWiki:Mainpagexxx"},"params":{},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["MediaWiki:Mainpagexxx"]}}'>MediaWiki:Mainpagexxx</a></p>
!! end

!! test
Transclusion of MediaWiki message with underscore
!! wikitext
{{MediaWiki:history_short}}
!! html/php
<p>History
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"MediaWiki:history_short","href":"./MediaWiki:History_short"},"params":{},"i":0}}]}'>History</span></p>
!! end

!! test
Transclusion of MediaWiki message with space
!! wikitext
{{MediaWiki:history short}}
!! html/php
<p>History
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"MediaWiki:history short","href":"./MediaWiki:History_short"},"params":{},"i":0}}]}'>History</span></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 check)
!! options
section=1
!! wikitext
==a==
                   a
!! html/php
==a==
                   a
!! end


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

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

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

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

xxx
!! end

!! test
Handling of &#x0A; in URLs
!! wikitext
*irc://&#x0A;a
!! html/php
<ul><li><a rel="nofollow" class="external free" href="irc://%0Aa">irc://%0Aa</a></li></ul>
!! html/parsoid
<ul><li><a rel="mw:ExtLink" href="irc://%0Aa" class="external free" data-parsoid='{"stx":"url","a":{"href":"irc://%0Aa"},"sa":{"href":"irc://&amp;#x0A;a"}}'>irc://%0Aa</a></li></ul>
!! end

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

# The PHP parser strips the empty tags out for giggles; parsoid doesn't.
!! test
5 quotes, code coverage +1 line
!! options
parsoid=wt2html
!! wikitext
'''''
!! html/php
!! html/parsoid
<p><b><i></i></b></p>
!! end

# same html as previous, but wikitext adjusted to match parsoid html2wt
# note that wt2html will put the <i> before the <b>
!! test
5 quotes, code coverage +1 line (1)
!! options
parsoid=html2wt
!! html/parsoid
<p><b><i></i></b></p>
!! wikitext
!! end

# same as previous, just swapping the <i> and <b>
!! test
5 quotes, code coverage +1 line (2)
!! options
parsoid=html2wt
!! html/parsoid
<p><i><b></b></i></p>
!! wikitext
!! end

!! test
Special:Search page linking.
!! wikitext
{{Special:search}}
!! html/php
<p><a href="/wiki/Special:Search" title="Special:Search">Special:Search</a>
</p>
!! html/parsoid+integrated
<p><a href="/wiki/Special:Search" title="Special:Search" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Special:search","href":"./Special:Search"},"params":{},"i":0}}]}'>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-mw='{"parts":[{"template":{"target":{"wt":"!","function":"!"},"params":{},"i":0}}]}'>|</span> is a magic word there and <span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"!","function":"!"},"params":{},"i":0}}]}'>|</span> is still a magic word here
| is not a magic word here but <span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"!","function":"!"},"params":{},"i":0}}]}'>|</span> is still a magic word here</p>
!! end

!! test
Single {{!}} in table cell
!! wikitext
{|
| colspan="1" |foo {{!}} bar
|}
!! html/php
<table>
<tbody><tr>
<td colspan="1">foo | bar
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td colspan="1">foo <span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"!","function":"!"},"params":{},"i":0}}]}'>|</span> bar</td></tr>
</tbody></table>
!! end

!! article
Template:T290526
!! text
Main Page{{!}}Something else
!! endarticle

!! test
Using {{!}} in wikilinks (T290526)
!! wikitext
[[Main Page{{!}}Something else]]

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

!! test
Using {{!}} in template arguments (T290526)
!! wikitext
{{1x|Main Page{{!}}Something else}}

{{1x|{{T290526}}}}
!! html/php
<p>Main Page|Something else
</p><p>Main Page|Something else
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Main Page{{!}}Something else"}},"i":0}}]}'>Main Page|Something else</span></p>

<p><span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{T290526}}"}},"i":0}}]}'>Main Page|Something else</span></p>
!! end

# wt2wt,html2wt,html2html modes will add <nowiki> around the {{ }} in
# the last line
!! test
Using {{!}} in template arguments, part 2 (T290526)
!! options
parsoid=wt2html
!! wikitext
{{ Main Page|Something else }}

{{ {{T290526}} }}
!! html/php
<p><a href="/index.php?title=Template:Main_Page&amp;action=edit&amp;redlink=1" class="new" title="Template:Main Page (page does not exist)">Template:Main Page</a>
</p><p>{{ Main Page|Something else }}
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Template:Main_Page?action=edit&amp;redlink=1" title="Template:Main Page" about="#mwt1" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./Template:Main_Page"},"sa":{"href":"Template:Main_Page"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"Main Page","href":"./Template:Main_Page"},"params":{"1":{"wt":"Something else "}},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:Main Page"]}}'>Template:Main_Page</a></p>

<p>{{ <span about="#mwt5" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"T290526","href":"./Template:T290526"},"params":{},"i":0}}]}'>Main Page|Something else</span> }}</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/php
<ul><li>Parser test</li>
<li>Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li>Talk:Parser test</li>
<li>Talk:Parser_test</li>
<li>Parser test</li>
<li>Parser_test</li>
<li class="mw-empty-elt"></li>
<li class="mw-empty-elt"></li>
<li>0</li>
<li>Talk</li>
<li>Talk</li>
<li class="mw-empty-elt"></li>
<li class="mw-empty-elt"></li>
<li><a href="/index.php?title=Template:Dynamic&amp;action=edit&amp;redlink=1" class="new" title="Template:Dynamic (page does not exist)">Template:Dynamic</a></li></ul>
!! html/parsoid
<ul><li><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"PAGENAME","function":"pagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"PAGENAMEE","function":"pagenamee"},"params":{},"i":0}}]}'></span></li>
<li><span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"FULLPAGENAME","function":"fullpagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt4" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"FULLPAGENAMEE","function":"fullpagenamee"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt5" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"BASEPAGENAME","function":"basepagename"},"params":{},"i":0}}]}'>Parser function implementation for pf_basepagename missing in Parsoid.</span></li>
<li><span about="#mwt6" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"BASEPAGENAMEE","function":"basepagenamee"},"params":{},"i":0}}]}'>Parser function implementation for pf_basepagenamee missing in Parsoid.</span></li>
<li><span about="#mwt7" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"SUBPAGENAME","function":"subpagename"},"params":{},"i":0}}]}'>Parser function implementation for pf_subpagename missing in Parsoid.</span></li>
<li><span about="#mwt8" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"SUBPAGENAMEE","function":"subpagenamee"},"params":{},"i":0}}]}'>Parser function implementation for pf_subpagenamee missing in Parsoid.</span></li>
<li><span about="#mwt9" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"ROOTPAGENAME","function":"rootpagename"},"params":{},"i":0}}]}'>Parser function implementation for pf_rootpagename missing in Parsoid.</span></li>
<li><span about="#mwt10" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"ROOTPAGENAMEE","function":"rootpagenamee"},"params":{},"i":0}}]}'>Parser function implementation for pf_rootpagenamee missing in Parsoid.</span></li>
<li><span about="#mwt11" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"TALKPAGENAME","function":"talkpagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt12" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"TALKPAGENAMEE","function":"talkpagenamee"},"params":{},"i":0}}]}'>Parser function implementation for pf_talkpagenamee missing in Parsoid.</span></li>
<li><span about="#mwt13" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"SUBJECTPAGENAME","function":"subjectpagename"},"params":{},"i":0}}]}'>Parser function implementation for pf_subjectpagename missing in Parsoid.</span></li>
<li><span about="#mwt14" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"SUBJECTPAGENAMEE","function":"subjectpagenamee"},"params":{},"i":0}}]}'>Parser function implementation for pf_subjectpagenamee missing in Parsoid.</span></li>
<li><span about="#mwt15" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"NAMESPACEE","function":"namespacee"},"params":{},"i":0}}]}'>Main</span></li>
<li><span about="#mwt16" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"NAMESPACE","function":"namespace"},"params":{},"i":0}}]}'>Main</span></li>
<li><span about="#mwt17" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"NAMESPACENUMBER","function":"namespacenumber"},"params":{},"i":0}}]}'>0</span></li>
<li><span about="#mwt18" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"TALKSPACE","function":"talkspace"},"params":{},"i":0}}]}'>Talk</span></li>
<li><span about="#mwt19" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"TALKSPACEE","function":"talkspacee"},"params":{},"i":0}}]}'>Parser function implementation for pf_talkspacee missing in Parsoid.</span></li>
<li><span about="#mwt20" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"SUBJECTSPACE","function":"subjectspace"},"params":{},"i":0}}]}'>Main</span></li>
<li><span about="#mwt21" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"SUBJECTSPACEE","function":"subjectspacee"},"params":{},"i":0}}]}'>Parser function implementation for pf_subjectspacee missing in Parsoid.</span></li>
<li><a rel="mw:WikiLink" href="./Template:Dynamic?action=edit&amp;redlink=1" title="Template:Dynamic" about="#mwt22" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./Template:Dynamic"},"sa":{"href":"Template:Dynamic"},"pi":[[{"k":"1"},{"k":"2"},{"k":"3"},{"k":"4"},{"k":"5"},{"k":"6"},{"k":"7"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"Dynamic","href":"./Template:Dynamic"},"params":{"1":{"wt":"{{NUMBEROFUSERS}}"},"2":{"wt":"{{NUMBEROFPAGES}}"},"3":{"wt":"{{CURRENTVERSION}}"},"4":{"wt":"{{CONTENTLANGUAGE}}"},"5":{"wt":"{{DIRECTIONMARK}}"},"6":{"wt":"{{CURRENTTIMESTAMP}}"},"7":{"wt":"{{NUMBEROFARTICLES}}"}},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:Dynamic"]}}'>Template:Dynamic</a></li></ul>
!! html/parsoid+integrated
<ul><li><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"PAGENAME","function":"pagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"PAGENAMEE","function":"pagenamee"},"params":{},"i":0}}]}'>Parser_test</span></li>
<li><span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"FULLPAGENAME","function":"fullpagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"FULLPAGENAMEE","function":"fullpagenamee"},"params":{},"i":0}}]}'>Parser_test</span></li>
<li><span about="#mwt5" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"BASEPAGENAME","function":"basepagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt6" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"BASEPAGENAMEE","function":"basepagenamee"},"params":{},"i":0}}]}'>Parser_test</span></li>
<li><span about="#mwt7" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SUBPAGENAME","function":"subpagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt8" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SUBPAGENAMEE","function":"subpagenamee"},"params":{},"i":0}}]}'>Parser_test</span></li>
<li><span about="#mwt9" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"ROOTPAGENAME","function":"rootpagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt10" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"ROOTPAGENAMEE","function":"rootpagenamee"},"params":{},"i":0}}]}'>Parser_test</span></li>
<li><span about="#mwt11" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"TALKPAGENAME","function":"talkpagename"},"params":{},"i":0}}]}'>Talk:Parser test</span></li>
<li><span about="#mwt12" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"TALKPAGENAMEE","function":"talkpagenamee"},"params":{},"i":0}}]}'>Talk:Parser_test</span></li>
<li><span about="#mwt13" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SUBJECTPAGENAME","function":"subjectpagename"},"params":{},"i":0}}]}'>Parser test</span></li>
<li><span about="#mwt14" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SUBJECTPAGENAMEE","function":"subjectpagenamee"},"params":{},"i":0}}]}'>Parser_test</span></li>
<li><span about="#mwt15" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"NAMESPACEE","function":"namespacee"},"params":{},"i":0}}]}'></span></li>
<li><span about="#mwt16" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"NAMESPACE","function":"namespace"},"params":{},"i":0}}]}'></span></li>
<li><span about="#mwt17" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"NAMESPACENUMBER","function":"namespacenumber"},"params":{},"i":0}}]}'>0</span></li>
<li><span about="#mwt18" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"TALKSPACE","function":"talkspace"},"params":{},"i":0}}]}'>Talk</span></li>
<li><span about="#mwt19" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"TALKSPACEE","function":"talkspacee"},"params":{},"i":0}}]}'>Talk</span></li>
<li><span about="#mwt20" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SUBJECTSPACE","function":"subjectspace"},"params":{},"i":0}}]}'></span></li>
<li><span about="#mwt21" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SUBJECTSPACEE","function":"subjectspacee"},"params":{},"i":0}}]}'></span></li>
<li><a rel="mw:WikiLink" href="./Template:Dynamic?action=edit&amp;redlink=1" title="Template:Dynamic" about="#mwt22" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./Template:Dynamic"},"sa":{"href":":Template:Dynamic"},"pi":[[{"k":"1"},{"k":"2"},{"k":"3"},{"k":"4"},{"k":"5"},{"k":"6"},{"k":"7"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"Dynamic","href":"./Template:Dynamic"},"params":{"1":{"wt":"{{NUMBEROFUSERS}}"},"2":{"wt":"{{NUMBEROFPAGES}}"},"3":{"wt":"{{CURRENTVERSION}}"},"4":{"wt":"{{CONTENTLANGUAGE}}"},"5":{"wt":"{{DIRECTIONMARK}}"},"6":{"wt":"{{CURRENTTIMESTAMP}}"},"7":{"wt":"{{NUMBEROFARTICLES}}"}},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:Dynamic"]}}'>Template:Dynamic</a></li></ul>
!! end
### Note: Above tests excludes the "{{NUMBEROFADMINS}}" magic word because it generates a MySQL error when included.

!! test
HTML Hex character encoding (spells the word "JavaScript")
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
&#x4A;&#x061;&#x0076;&#x00061;&#x000053;&#x0000063;&#114;&#x0000069;&#00000112;&#x0000000074;
!! html/php
<p>&#x4a;&#x61;&#x76;&#x61;&#x53;&#x63;&#114;&#x69;&#112;&#x74;
</p>
!! html/parsoid
<p><span typeof="mw:Entity">J</span><span typeof="mw:Entity">a</span><span typeof="mw:Entity">v</span><span typeof="mw:Entity">a</span><span typeof="mw:Entity">S</span><span typeof="mw:Entity">c</span><span typeof="mw:Entity">r</span><span typeof="mw:Entity">i</span><span typeof="mw:Entity">p</span><span typeof="mw:Entity">t</span></p>
!! end

!! test
HTML Hex character encoding bogus encoding (T28437 regression check)
!! wikitext
&#xsee;&#XSEE;
!! html
<p>&amp;#xsee;&amp;#XSEE;
</p>
!! end

!! test
HTML Hex character encoding mixed case
!! options
parsoid=wt2html,wt2wt,html2html
!! wikitext
&#xEE;&#Xee;
!! html/php
<p>&#xee;&#xee;
</p>
!! html/parsoid
<p><span typeof="mw:Entity">î</span><span typeof="mw:Entity">î</span></p>
!! end

# See: https://www.w3.org/TR/html5/syntax.html#character-references
# Note that U+000C (form feed) is not a valid XML character, so
# it is banned even though allowed in HTML5.
# Note there are also weird legacy numeric entities which are mapped
# elsewhere; see T113194
!! test
Illegal character references (T106578, T113194)
!! options
parsoid={ "modes": ["wt2html","html2html"], "normalizePhp": true }
!! wikitext
; Null: &#00;
; FF: &#xC;
; CR: &#xD;
; Control (low): &#8;
; Control (high): &#x7F; &#x9F;
; Unsupported legacy: &#128; &#130; &#131; &#150; &#159;
; Surrogate: &#xD83D;&#xDCA9;
; Invalid characters: &#xfffe; &#xffff;
; This is an okay astral character: &#x1F4A9;
; This is an okay multi-codepoint HTML5 entity: &acE;
; This are valid wikitext-specific entities: &רלמ; &رلم;
; Highest valid characters: &#x10fffd; &#x10fffe; &#x10ffff;
!! html
<dl><dt>Null</dt>
<dd>&amp;#00;</dd>
<dt>FF</dt>
<dd>&amp;#xC;</dd>
<dt>CR</dt>
<dd>&amp;#xD;</dd>
<dt>Control (low)</dt>
<dd>&amp;#8;</dd>
<dt>Control (high)</dt>
<dd>&amp;#x7F; &amp;#x9F;</dd>
<dt>Unsupported legacy</dt>
<dd>&amp;#128; &amp;#130; &amp;#131; &amp;#150; &amp;#159;</dd>
<dt>Surrogate</dt>
<dd>&amp;#xD83D;&amp;#xDCA9;</dd>
<dt>Invalid characters</dt>
<dd>&amp;#xfffe; &amp;#xffff;</dd>
<dt>This is an okay astral character</dt>
<dd>&#x1f4a9;</dd>
<dt>This is an okay multi-codepoint HTML5 entity</dt>
<dd>&#8766;&#819;</dd>
<dt>This are valid wikitext-specific entities</dt>
<dd>&rlm; &rlm;</dd>
<dt>Highest valid characters</dt>
<dd>&#x10fffd; &#x10fffe; &#x10ffff;</dd></dl>
!! end

!! test
Another italics / bold test
!! options
parsoid=wt2html
!! wikitext
 ''' ''x'
!! html/*
<pre>'<i> </i>x'
</pre>
!! end

!! test
dt/dd/dl test
!! wikitext
:;;;::
!! html
<dl><dd><dl><dt><dl><dt><dl><dt><dl><dd><dl><dd></dd></dl></dd></dl></dt></dl></dt></dl></dt></dl></dd></dl>
!! end

!! test
[Before] HTML without raw HTML enabled ($wgRawHtml==false)
!! wikitext
<html><script>alert(1);</script></html>
!! html
<p>&lt;html&gt;&lt;script&gt;alert(1);&lt;/script&gt;&lt;/html&gt;
</p>
!! end

!! test
HTML with raw HTML ($wgRawHtml==true)
!! options
wgRawHtml=1
!! wikitext
<html><script>alert(1);</script></html>
!! html/php
<p><script>alert(1);</script>
</p>
!! html/parsoid
<p><script typeof="mw:Extension/html" about="#mwt3" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;script>alert(1);&lt;/script>"}}'>alert(1);</script></p>
!! end

!! test
Empty tag w/ raw HTML ($wgRawHtml==true)
!! options
wgRawHtml=1
!! wikitext
<html />
!! html/php
<p class="mw-empty-elt">
</p>
!! html/parsoid
<p><link typeof="mw:Extension/html" about="#mwt2" data-mw='{"name":"html","attrs":{}}'/></p>
!! end


!! article
Subpage test
!! text
subpage
!! end

!! article
Subpage test/L1
!! text
subpage l1
!! end

!! article
Subpage test/L1/L2
!! text
subpage l2
!! end

!! test
Parents of subpages, one level up
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../|L2]]
!! html/php
<p><a href="/wiki/Subpage_test/L1/L2" title="Subpage test/L1/L2">L2</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/L1/L2" title="Subpage test/L1/L2" data-parsoid='{"stx":"piped","a":{"href":"./Subpage_test/L1/L2"},"sa":{"href":"../"}}'>L2</a></p>
!! end

!! test
Parents of subpages, one level up, not named
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../]]
!! html/php
<p><a href="/wiki/Subpage_test/L1/L2" title="Subpage test/L1/L2">Subpage test/L1/L2</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/L1/L2" title="Subpage test/L1/L2" data-parsoid='{"stx":"simple","a":{"href":"./Subpage_test/L1/L2"},"sa":{"href":"../"}}'>Subpage test/L1/L2</a></p>
!! end

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

[[../../|L1]]l
!! html/php
<p><a href="/wiki/Subpage_test/L1" title="Subpage test/L1">L1</a>2
</p><p><a href="/wiki/Subpage_test/L1" title="Subpage test/L1">L1l</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/L1" title="Subpage test/L1" data-parsoid='{"stx":"piped","a":{"href":"./Subpage_test/L1"},"sa":{"href":"../../"}}'>L1</a>2</p>

<p><a rel="mw:WikiLink" href="./Subpage_test/L1" title="Subpage test/L1" data-parsoid='{"stx":"piped","a":{"href":"./Subpage_test/L1"},"sa":{"href":"../../"},"tail":"l"}'>L1l</a></p>
!! end

!! test
Parents of subpages, two levels up, without trailing slash or name.
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../..]]
!! html
<p>[[../..]]
</p>
!! end

!! test
Parents of subpages, two levels up, with lots of extra trailing slashes.
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
[[../../////]]
!! html/php
<p><a href="/wiki/Subpage_test/L1" title="Subpage test/L1">Subpage test/L1</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Subpage_test/L1" title="Subpage test/L1" data-parsoid='{"stx":"simple","a":{"href":"./Subpage_test/L1"},"sa":{"href":"../../////"}}'>Subpage test/L1</a></p>
!! end

!! article
Subpage test/L1/L2/L3Sibling
!! text
Sibling article
!! endarticle

!! test
Transclusion of a sibling page (one level up)
!! options
subpage title=[[Subpage test/L1/L2/L3]]
!! wikitext
{{../L3Sibling}}
!! html
<p>Sibling article
</p>
!! end

!! test
Transclusion of a child page
!! options
subpage title=[[Subpage test/L1/L2]]
!! wikitext
{{/L3Sibling}}
!! html
<p>Sibling article
</p>
!! end

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

!! test
Definition list code coverage
!! options
parsoid=wt2html,html2html
!! wikitext
;title   :def
;title :def
;title:def
!! html/php
<dl><dt>title</dt>
<dd>def</dd>
<dt>title</dt>
<dd>def</dd>
<dt>title</dt>
<dd>def</dd></dl>
!! html/parsoid
<dl><dt>title   </dt><dd>def</dd>
<dt>title </dt><dd>def</dd>
<dt>title</dt><dd>def</dd></dl>
!! end

!! test
Don't fall for the self-closing div
!! wikitext
<div>hello world</div/>
!! html
<div>hello world</div>
!! end

!! test
MSGNW magic word
!! wikitext
{{MSGNW:msg}}
!! html/php
<p>&#91;&#91;:Template:Msg&#93;&#93;
</p>
!! end

!! test
RAW magic word
!! wikitext
{{RAW:QUERTY}}
!! html/php
<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>
!! html/parsoid+integrated
<p><a rel="mw:WikiLink" href="./Template:QUERTY?action=edit&amp;redlink=1" title="Template:QUERTY" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-mw='{"parts":[{"template":{"target":{"wt":"RAW:QUERTY","href":"./Template:RAW:QUERTY"},"params":{},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:QUERTY"]}}'>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

!! test
anchorencode
!! config
wgFragmentMode=[ "html5", "legacy" ]
!! wikitext
{{anchorencode:foo bar©#%n}}
!! html/php
<p>foo_bar©#%n
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode:foo bar©#%n","function":"anchorencode"},"params":{},"i":0}}]}'>foo_bar©#%n</span></p>
!! end

!! test
anchorencode (legacy)
!! config
wgFragmentMode=[ "legacy" ]
!! wikitext
{{anchorencode:foo bar©#%n}}
!! html/php
<p>foo_bar.C2.A9.23.25n
</p>
!! end

!! test
anchorencode trims spaces
!! config
wgFragmentMode=[ "html5", "legacy" ]
!! wikitext
{{anchorencode: __pretty__please__}}
!! html/php
<p>pretty_please
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: __pretty__please__","function":"anchorencode"},"params":{},"i":0}}]}'>pretty_please</span></p>
!! end

!! test
anchorencode deals with links
!! config
wgFragmentMode=[ "html5", "legacy" ]
!! wikitext
{{anchorencode: [[hello|world]] [[hi]]}}
!! html/php
<p>world_hi
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: [[hello|world]] [[hi]]","function":"anchorencode"},"params":{},"i":0}}]}'>world_hi</span></p>
!! end

!! test
anchorencode deals with templates
!! config
wgFragmentMode=[ "html5", "legacy" ]
!! wikitext
{{anchorencode: {{Foo}} x}}
!! html/php
<p>FOO_x
</p>
!! html/parsoid
<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: {{Foo}} x","function":"anchorencode"},"params":{},"i":0}}]}'>FOO_x</span></p>
!! end

!! test
anchorencode encodes like the TOC generator: (T20431)
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
===_ +:.3A%3A _ &&amp;]] x===
{{anchorencode: _ +:.3A%3A _ &&amp;]] x}}

__NOEDITSECTION__
!! html/php
<div class="mw-heading mw-heading3"><h3 id="+:.3A%3A_&amp;&amp;]]_x"><span id=".2B:.3A.253A_.26.26.5D.5D_x"></span>_ +:.3A%3A _ &amp;&amp;]] x</h3></div>
<p>+:.3A%253A_&amp;&amp;&#93;&#93;_x
</p><p><br />
</p>
!! html/parsoid+standalone
<h3 id="+:.3A%3A_&amp;&amp;]]_x"><span id=".2B:.3A.253A_.26.26.5D.5D_x" typeof="mw:FallbackId"></span>_ +:.3A%3A _ &amp;<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>]] x</h3>
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: _ +:.3A%3A _ &amp;&amp;amp;]] x","function":"anchorencode"},"params":{},"i":0}}]}'>+:.3A%253A_&amp;&amp;</span><span typeof="mw:Entity" about="#mwt1">]</span><span typeof="mw:Entity" about="#mwt1">]</span><span about="#mwt1">_x</span></p>
<meta property="mw:PageProp/noeditsection"/>
!! html/parsoid+integrated
<h3 id="+:.3A%3A_&amp;&amp;]]_x"><span id=".2B:.3A.253A_.26.26.5D.5D_x" typeof="mw:FallbackId"></span>_ +:.3A%3A _ &amp;<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>]] x</h3>
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode: _ +:.3A%3A _ &amp;&amp;amp;]] x","function":"anchorencode"},"params":{},"i":0}}]}'>+:.3A%253A_</span><span typeof="mw:Entity" about="#mwt1">&amp;</span><span typeof="mw:Entity" about="#mwt1">&amp;</span><span typeof="mw:Entity" about="#mwt1">]</span><span typeof="mw:Entity" about="#mwt1">]</span><span about="#mwt1">_x</span></p>
<meta property="mw:PageProp/noeditsection"/>
!! end

!! test
anchorencode encodes like the TOC generator: (T20431) (legacy)
!! config
wgFragmentMode=[ "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
===_ +:.3A%3A&&amp;]]===
{{anchorencode: _ +:.3A%3A&&amp;]] }}
__NOEDITSECTION__
!! html/php
<div class="mw-heading mw-heading3"><h3 id=".2B:.3A.253A.26.26.5D.5D">_ +:.3A%3A&amp;&amp;]]</h3></div>
<p>.2B:.3A.253A.26.26.5D.5D
</p>
!! end

!! test
T8200: blockquotes and paragraph formatting
!! wikitext
<blockquote>
foo
</blockquote>

bar

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

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

bar

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

!!test
Parsing of overlapping (improperly nested) inline html tags
!! wikitext
<span><s>x</span></s>
!! html
<p><span><s>x</s></span>
</p>
!!end

!! test
T2529: Uncovered bullet
!! wikitext
*Foo {{bullet}}
!! html/php
<ul><li>Foo</li>
<li>Bar</li></ul>
!! html/parsoid
<ul><li>Foo</li><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bullet","href":"./Template:Bullet"},"params":{},"i":0}}]}'>
</span><li about="#mwt1">Bar</li></ul>
!! end

!! test
T2529: Uncovered bullet in a deeply nested list
!! wikitext
*******Foo {{bullet}}
!! html/php
<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>
!! html/parsoid
<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><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bullet","href":"./Template:Bullet"},"params":{},"i":0}}]}'>
</span><li about="#mwt1">Bar</li></ul>
!! end

!! test
T2529: Uncovered table already at line-start
!! wikitext
x

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

<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"table","href":"./Template:Table"},"params":{},"i":0}}]}'>
<tbody><tr><td>1</td><td>2</td></tr>
<tr>
<td>3</td><td>4</td></tr>
</tbody></table>
<p>y</p>
!! end

!! test
T2529: Uncovered bullet in parser function result
!! wikitext
*Foo{{lc:{{bullet}} }}
!! html/php
<ul><li>Foo</li>
<li>bar</li></ul>
!! html/parsoid+integrated
<ul><li>Foo</li><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"lc:{{bullet}} ","function":"lc"},"params":{},"i":0}}]}'>
</span><li about="#mwt1">bar</li></ul>
!! end

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

## wt2html only, since the bare {{ will get escaped when serializing
!! test
T7678: Double-parsed template invocation
!! options
parsoid=wt2html
!! wikitext
{{lc:{{paramtest {{!}} param = hello }} }}
!! html/php
<p>{{paramtest | param = hello }}
</p>
!! html/parsoid+integrated
<p><span about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"lc:{{paramtest {{!}} param = hello }} ","function":"lc"},"params":{},"i":0}}]}'>{{paramtest | param = hello }}</span></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
Paragraphs inside divs (no extra line breaks)
!! wikitext
<div>Line one

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

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

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

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

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

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

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

# doBlockLevels screws up this output and Remex cleans up as much as it can.
!! test
Nesting tags, paragraphs on lines which begin with <div>
!! wikitext
<div></div><strong>A
B</strong>
!! html/php
<div></div><p><strong>A
</strong></p><strong></strong><p><strong>B</strong>
</p>
!! html/parsoid
<div data-parsoid='{"stx":"html"}'></div><p><strong data-parsoid='{"stx":"html","autoInsertedEnd":true}'>A</strong></p>
<p><strong data-parsoid='{"stx":"html","autoInsertedStart":true}'>B</strong></p>
!! end

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

Line two</blockquote>
!! html
<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><p>
Line two</p></blockquote>
!! end

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

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

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

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

## This is a corner case interaction between the paragraph wrapping in the
## php parser's BlockLevelPass and Remex.  `doBlockLevels` has a notion of
## some tags which close paragraphs (and thus prevent wrapping on their line),
## of which "div" is one, but do p-wrapping inside them.  These are referred
## to as "never suppressing".  Remex, for its part, doesn't traverse into
## "div"s to p-wrap.  Hence, we only get this partial wrapping.
!! test
Paragraphs inside blockquotes/divs (no extra line breaks)
!! wikitext
<blockquote><div>Line one

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

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

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

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

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

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

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

!! test
Interwiki links trounced by handleExternalLinks after early LinkHolderArray expansion
!! options
wgLinkHolderBatchSize=0
!! wikitext
[[meatball:1]]
[[meatball:2]]
[[meatball:3]]
!! html
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?1" class="extiw" title="meatball:1">meatball:1</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?2" class="extiw" title="meatball:2">meatball:2</a>
<a href="http://www.usemod.com/cgi-bin/mb.pl?3" class="extiw" title="meatball:3">meatball:3</a>
</p>
!! end

!! test
T17196: localised external link numbers
!! options
language=fa
!! wikitext
[http://en.wikipedia.org/]
!! html/php
<p><a rel="nofollow" class="external autonumber" href="http://en.wikipedia.org/">[۱]</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://en.wikipedia.org/" class="external autonumber"></a></p>
!! end

!! test
Multibyte character in padleft
!! wikitext
{{padleft:-Hello|7|Æ}}
!! html/php
<p>Æ-Hello
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padleft:-Hello","function":"padleft"},"params":{"1":{"wt":"7"},"2":{"wt":"Æ"}},"i":0}}]}'>Æ-Hello</span></p>
!! end

!! test
Multibyte character in padright
!! wikitext
{{padright:Hello-|7|Æ}}
!! html/php
<p>Hello-Æ
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:Hello-","function":"padright"},"params":{"1":{"wt":"7"},"2":{"wt":"Æ"}},"i":0}}]}'>Hello-Æ</span></p>
!! end

!!test
formatdate parser function
!! wikitext
{{#formatdate:2009-03-24}}
!! html/php
<p><span class="mw-formatted-date" title="2009-03-24">2009-03-24</span>
</p>
!! html/parsoid+integrated
<p><span class="mw-formatted-date" title="2009-03-24" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:2009-03-24","function":"formatdate"},"params":{},"i":0}}]}'>2009-03-24</span></p>
!! end

!!test
formatdate parser function, with default format
!! wikitext
{{#formatdate:2009-03-24|mdy}}
!! html/php
<p><span class="mw-formatted-date" title="2009-03-24">March 24, 2009</span>
</p>
!! html/parsoid+integrated
<p><span class="mw-formatted-date" title="2009-03-24" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:2009-03-24","function":"formatdate"},"params":{"1":{"wt":"mdy"}},"i":0}}]}'>March 24, 2009</span></p>
!! end

!! test
Spacing of numbers in formatted dates
!! wikitext
{{#formatdate:January 15}}
!! html/php
<p><span class="mw-formatted-date" title="01-15">January 15</span>
</p>
!! html/parsoid+integrated
<p><span class="mw-formatted-date" title="01-15" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:January 15","function":"formatdate"},"params":{},"i":0}}]}'>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/php
<p><span class="mw-formatted-date" title="2009-03-24">24 March 2009</span>
</p>
!! html/parsoid+integrated
<p><span class="mw-formatted-date" title="2009-03-24" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:2009-03-24","function":"formatdate"},"params":{"1":{"wt":"dmy"}},"i":0}}]}'>24 March 2009</span></p>
!! end

!! test
formatdate with invalid month
!! wikitext
{{#formatdate:2019-22-22|dmy}}
!! html/php
<p>2019-22-22
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:2019-22-22","function":"formatdate"},"params":{"1":{"wt":"dmy"}},"i":0}}]}'>2019-22-22</span></p>
!! end

!! test
formatdate: dots in month name do not match any char (T220563)
!! options
language=de
!! wikitext
{{#formatdate:jun. 3|dmy}}
{{#formatdate:junx 3|dmy}}
!! html/php
<p><span class="mw-formatted-date" title="06-03">3 Juni</span>
junx 3
</p>
!! html/parsoid+integrated
<p><span class="mw-formatted-date" title="06-03" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:jun. 3","function":"formatdate"},"params":{"1":{"wt":"dmy"}},"i":0}}]}'>3 Juni</span>
<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:junx 3","function":"formatdate"},"params":{"1":{"wt":"dmy"}},"i":0}}]}'>junx 3</span></p>
!! end

!! test
formatdate uses correct capitalisation in French
!! options
language=fr
!! wikitext
{{#formatdate:Juin 3|dmy}}
!! html/php
<p><span class="mw-formatted-date" title="06-03">3 juin</span>
</p>
!! html/parsoid+integrated
<p><span class="mw-formatted-date" title="06-03" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:Juin 3","function":"formatdate"},"params":{"1":{"wt":"dmy"}},"i":0}}]}'>3 juin</span></p>
!! end

!! test
formatdate uses correct capitalisation in English
!! wikitext
{{#formatdate:june 3|dmy}}
!! html/php
<p><span class="mw-formatted-date" title="06-03">3 June</span>
</p>
!! html/parsoid+integrated
<p><span class="mw-formatted-date" title="06-03" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:june 3","function":"formatdate"},"params":{"1":{"wt":"dmy"}},"i":0}}]}'>3 June</span></p>
!! end

!! test
formatdate formats ISO year 0 as 1 BC
!! wikitext
{{#formatdate:-0001-12-31|mdy}}
{{#formatdate:0000-12-31|mdy}}
{{#formatdate:0001-12-31|mdy}}
!! html/php
<p><span class="mw-formatted-date" title="-0001-12-31">December 31, 2 BC</span>
<span class="mw-formatted-date" title="0000-12-31">December 31, 1 BC</span>
<span class="mw-formatted-date" title="0001-12-31">December 31, 1</span>
</p>
!! html/parsoid+integrated
<p><span class="mw-formatted-date" title="-0001-12-31" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:-0001-12-31","function":"formatdate"},"params":{"1":{"wt":"mdy"}},"i":0}}]}'>December 31, 2 BC</span> <span class="mw-formatted-date" title="0000-12-31" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:0000-12-31","function":"formatdate"},"params":{"1":{"wt":"mdy"}},"i":0}}]}'>December 31, 1 BC</span> <span class="mw-formatted-date" title="0001-12-31" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#formatdate:0001-12-31","function":"formatdate"},"params":{"1":{"wt":"mdy"}},"i":0}}]}'>December 31, 1</span></p>
!! end

#
#
#

#
# Edit comments
#

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

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

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

!! test
Edit comment with section link (non-local, eg in history list)
!! options
comment title=[[Main Page]]
!! wikitext
/* External links */ removed bogus entries
!! html/php
<span class="autocomment"><a href="/wiki/Main_Page#External_links" title="Main Page">→<bdi dir="ltr">External links</bdi></a>: </span> removed bogus entries
!!end

!! test
Edit comment with section link and text before it (non-local, eg in history list)
!! options
comment title=[[Main Page]]
!! wikitext
pre-comment text /* External links */ removed bogus entries
!! html/php
pre-comment text <span class="autocomment"><a href="/wiki/Main_Page#External_links" title="Main Page">→<bdi dir="ltr">External links</bdi></a>: </span> removed bogus entries
!!end

!! test
Edit comment with section link (local, eg in diff view)
!! options
comment local title=[[Main Page]]
!! wikitext
/* External links */ removed bogus entries
!! html/php
<span class="autocomment"><a href="#External_links">→<bdi dir="ltr">External links</bdi></a>: </span> removed bogus entries
!!end

!! test
Edit comment with section link that has a link in it
!! options
comment local title=[[Main Page]]
!! wikitext
/* [[A link]] */
!! html/php
<span class="autocomment"><a href="#A_link">→<bdi dir="ltr">&#91;[A link]]</bdi></a></span>
!! end

!! test
Edit comment with section link that has a template in it
!! options
comment local title=[[Main Page]]
!! wikitext
/* {{foobar|param}} */
!! html/php
<span class="autocomment"><a href="#.7B.7Bfoobar.7Cparam.7D.7D">→<bdi dir="ltr">{{foobar|param}}</bdi></a></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" class="mw-selflink-fragment" data-parsoid='{"stx":"piped","a":{"href":"./Foo#_ref"},"sa":{"href":"#_ref"}}'>One</a></p>
!! end

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

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

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

!! test
Space normalisation on autocomment (T24784)
!! options
comment
title=[[Main Page]]
!! wikitext
/* __hello__world__ */
!! html/php
<span class="autocomment"><a href="/wiki/Main_Page#hello_world" title="Main Page">→<bdi dir="ltr">__hello__world__</bdi></a></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

!! test
Verify that displaytitle works (T24501) no displaytitle
!! options
showtitle
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! wikitext
this is not the title
!! metadata
<span class="mw-page-title-main">Parser test</span>
!! html
<p>this is not the title
</p>
!! end

!! test
Verify that displaytitle works (T24501) RestrictDisplayTitle=false
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=false
!! wikitext
this is not the title
{{DISPLAYTITLE:whatever}}
!! metadata
whatever
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:whatever","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

!! test
Verify that displaytitle works (T24501) RestrictDisplayTitle=true mismatch
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:whatever}}
!! metadata
<span class="mw-page-title-main">Screen</span>
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:whatever","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

!! test
Verify that displaytitle works (T24501) RestrictDisplayTitle=true matching
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:screen}}
!! metadata
screen
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:screen","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

!! test
Verify that displaytitle works (T24501) AllowDisplayTitle=false
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=false
!! wikitext
this is not the title
{{DISPLAYTITLE:screen}}
!! metadata
<span class="mw-page-title-main">Screen</span>
!! html/php
<p>this is not the title
<a href="/index.php?title=Template:DISPLAYTITLE:screen&amp;action=edit&amp;redlink=1" class="new" title="Template:DISPLAYTITLE:screen (page does not exist)">Template:DISPLAYTITLE:screen</a>
</p>
!! html/parsoid+integrated
<p>this is not the title <a rel="mw:WikiLink" href="./Template:DISPLAYTITLE:screen?action=edit&amp;redlink=1" title="Template:DISPLAYTITLE:screen" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:screen","href":"./Template:DISPLAYTITLE:screen"},"params":{},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:DISPLAYTITLE:screen"]}}'>Template:DISPLAYTITLE:screen</a></p>
!! end

!! test
Verify that displaytitle works (T24501) AllowDisplayTitle=false no DISPLAYTITLE
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=false
!! wikitext
this is not the title
!! metadata
<span class="mw-page-title-main">Screen</span>
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
!! end

!! test
Verify that displaytitle handles inline CSS styles (T28547) - rejected value
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:<span style="display: none;">s</span>creen}}
!! metadata
<span style="/* attempt to bypass $wgRestrictDisplayTitle */">s</span>creen
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:&lt;span style=\"display: none;\">s&lt;/span>creen","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

!! test
Verify that displaytitle handles inline CSS styles (T28547) - accepted value
!! options
showtitle
title=[[Screen]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:<span style="color: red;">s</span>creen}}
!! metadata
<span style="color: red;">s</span>creen
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:&lt;span style=\"color: red;\">s&lt;/span>creen","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

!! test
Verify that displaytitle encodes & to &amp; (T291985)
!! options
showtitle
title=[[Art&copy]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:art&copy}}
!! metadata
art&amp;copy
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:art&amp;copy","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

!! test
Verify that displaytitle encodes &amp; to &amp; (T291985)
!! options
showtitle
title=[[Art&copy]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
{{DISPLAYTITLE:art&amp;copy}}
!! metadata
art&amp;copy
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"DISPLAYTITLE:art&amp;amp;copy","function":"displaytitle"},"params":{},"i":0}}]}'></span>
!! end

!! test
Verify that without displaytitle the title encodes & to &amp; (T291985)
!! options
showtitle
title=[[Art&copy]]
!! config
wgAllowDisplayTitle=true
wgRestrictDisplayTitle=true
!! wikitext
this is not the title
!! metadata
<span class="mw-page-title-main">Art&amp;copy</span>
!! html/php
<p>this is not the title
</p>
!! html/parsoid+integrated
<p>this is not the title</p>
!! end

!! test
preload: check <noinclude> and <includeonly>
!! options
preload
!! wikitext
Hello <noinclude>cruel</noinclude><includeonly>kind</includeonly> world.
!! html/php
Hello kind world.
!! end

!! test
preload: check <onlyinclude>
!! options
preload
!! wikitext
Goodbye <onlyinclude>Hello world</onlyinclude>
!! html/php
Hello world
!! end

!! test
preload: can pass tags through if we want to
!! options
preload
!! wikitext
<includeonly><</includeonly>includeonly>Hello world<includeonly><</includeonly>/includeonly>
!! html/php
<includeonly>Hello world</includeonly>
!! end

!! test
preload: check that it doesn't try to do tricks
!! options
preload
!! wikitext
* <!-- Hello --> ''{{world}}'' {{<includeonly>subst:</includeonly>How are you}}{{ {{{|safesubst:}}} #if:1|2|3}}
!! html/php
* <!-- Hello --> ''{{world}}'' {{subst:How are you}}{{ {{{|safesubst:}}} #if:1|2|3}}
!! end

!! test
Play a bit with r67090 and T5158
!! wikitext
<div style="width:50% !important">&nbsp;</div>
<div style="width:50%&nbsp;!important">&nbsp;</div>
<div style="width:50%&#160;!important">&nbsp;</div>
<div style="border : solid;">&nbsp;</div>
!! html/php
<div style="width:50% !important">&#160;</div>
<div style="width:50%&#160;!important">&#160;</div>
<div style="width:50%&#160;!important">&#160;</div>
<div style="border : solid;">&#160;</div>
!! html/parsoid
<div style="width:50% !important" data-parsoid='{"stx":"html"}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
<div style="width:50% !important" data-parsoid='{"stx":"html","a":{"style":"width:50% !important"},"sa":{"style":"width:50%&amp;nbsp;!important"}}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
<div style="width:50% !important" data-parsoid='{"stx":"html","a":{"style":"width:50% !important"},"sa":{"style":"width:50%&amp;#160;!important"}}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
<div style="border : solid;" data-parsoid='{"stx":"html"}'><span typeof="mw:Entity" data-parsoid='{"srcContent":" "}'> </span></div>
!! end

!! test
French spaces in wikitext
!! wikitext
foo ! bar ? bat 50 % is less than 75 %.

Hello : this ; is « something ‹ else › again »
!! html/php
<p>foo&#160;! bar&#160;? bat 50&#160;% is less than 75&#160;%.
</p><p>Hello&#160;: this&#160;; is «&#160;something ‹&#160;else&#160;› again&#160;»
</p>
!! html/parsoid
<p>foo<span typeof="mw:DisplaySpace"> </span>! bar<span typeof="mw:DisplaySpace"> </span>? bat 50<span typeof="mw:DisplaySpace"> </span>% is less than 75<span typeof="mw:DisplaySpace"> </span>%.</p>

<p>Hello<span typeof="mw:DisplaySpace"> </span>: this<span typeof="mw:DisplaySpace"> </span>; is «<span typeof="mw:DisplaySpace"> </span>something ‹<span typeof="mw:DisplaySpace"> </span>else<span typeof="mw:DisplaySpace"> </span>› again<span typeof="mw:DisplaySpace"> </span>»</p>
!! end

!! test
Corner case: french spaces in definition list
!! options
parsoid=wt2html,html2html
!! wikitext
;foo : bar
!! html
<dl><dt>foo</dt>
<dd>bar</dd></dl>
!! end

!! test
T5158: Test for French spaces in attributes
!! wikitext
<br style=" clear : both ; " />
!! html/php
<p><br style="clear : both ;" />
</p>
!! end

# This test relies on the fact that image captions are processed
# as independent document fragments.
!! test
Displayspace processing on embedded fragments
!! options
parsoid=wt2html
!! wikitext
[[File:Foobar.jpg|« test »]]
!! html/parsoid
<p><span class="mw-default-size" typeof="mw:File" data-parsoid='{"optList":[{"ck":"caption","ak":"« test »"}]}' data-mw='{"caption":"«&lt;span typeof=\"mw:DisplaySpace\" data-parsoid=&apos;{\"dsr\":[null,null,null,null]}&apos;> &lt;/span>test&lt;span typeof=\"mw:DisplaySpace\" data-parsoid=&apos;{\"dsr\":[null,null,null,null]}&apos;> &lt;/span>»"}'><a href="./File:Foobar.jpg" class="mw-file-description" title="« test »" data-parsoid="{}"><img alt="« test »" resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" class="mw-file-element" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"File:Foobar.jpg"}}'/></a></span></p>
!! end

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

!! test
Strip reserved data attributes
!! wikitext
<div data-mw="foo" data-parsoid="bar" data-mw-someext="baz" data-ok="fred" data-object-id="123" data-ooui="xyzzy" data-bad:ns="ns">d</div>
!! html/php
<div data-ok="fred" data-object-id="123">d</div>
!! html/parsoid
<div data-x-data-mw="foo" data-x-data-parsoid="bar" data-x-data-mw-someext="baz" data-ok="fred" data-x-data-object-id="123" data-parsoid='{"stx":"html","a":{"data-ooui":null,"data-bad:ns":null},"sa":{"data-ooui":"xyzzy","data-bad:ns":"ns"}}'>d</div>
!! end

!! test
percent-encoding and + signs in internal links (T28410)
!! config
wgParserEnableLegacyMediaDOM=false
!! wikitext
[[User:+%]] [[Page+title%]]
[[%+]] [[%+|%20]] [[%+ ]] [[%+r]]
[[%]] [[+]] [[File:%+abc%39|foo|[[bar]]]]
[[%33%45]] [[%33%45+]]
!! html/php
<p><a href="/index.php?title=User:%2B%25&amp;action=edit&amp;redlink=1" class="new" title="User:+% (page does not exist)">User:+%</a> <a href="/index.php?title=Page%2Btitle%25&amp;action=edit&amp;redlink=1" class="new" title="Page+title% (page does not exist)">Page+title%</a>
<a href="/index.php?title=%25%2B&amp;action=edit&amp;redlink=1" class="new" title="%+ (page does not exist)">%+</a> <a href="/index.php?title=%25%2B&amp;action=edit&amp;redlink=1" class="new" title="%+ (page does not exist)">%20</a> <a href="/index.php?title=%25%2B&amp;action=edit&amp;redlink=1" class="new" title="%+ (page does not exist)">%+ </a> <a href="/index.php?title=%25%2Br&amp;action=edit&amp;redlink=1" class="new" title="%+r (page does not exist)">%+r</a>
<a href="/index.php?title=%25&amp;action=edit&amp;redlink=1" class="new" title="% (page does not exist)">%</a> <a href="/index.php?title=%2B&amp;action=edit&amp;redlink=1" class="new" title="+ (page does not exist)">+</a> <span class="mw-default-size" typeof="mw:Error mw:File"><a href="/index.php?title=Special:Upload&amp;wpDestFile=%25%2Babc9" class="new" title="File:%+abc9"><span class="mw-file-element mw-broken-media">bar</span></a></span>
<a href="/index.php?title=3E&amp;action=edit&amp;redlink=1" class="new" title="3E (page does not exist)">3E</a> <a href="/index.php?title=3E%2B&amp;action=edit&amp;redlink=1" class="new" title="3E+ (page does not exist)">3E+</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./User:+%25?action=edit&amp;redlink=1" title="User:+%" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./User:+%25"},"sa":{"href":"User:+%"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["User:+%"]}}'>User:+%</a> <a rel="mw:WikiLink" href="./Page+title%25?action=edit&amp;redlink=1" title="Page+title%" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./Page+title%25"},"sa":{"href":"Page+title%"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Page+title%"]}}'>Page+title%</a>
<a rel="mw:WikiLink" href="./%25+?action=edit&amp;redlink=1" title="%+" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./%25+"},"sa":{"href":"%+"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["%+"]}}'>%+</a> <a rel="mw:WikiLink" href="./%25+?action=edit&amp;redlink=1" title="%+" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"piped","a":{"href":"./%25+"},"sa":{"href":"%+"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["%+"]}}'>%20</a> <a rel="mw:WikiLink" href="./%25+?action=edit&amp;redlink=1" title="%+" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./%25+"},"sa":{"href":"%+ "}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["%+"]}}'>%+ </a> <a rel="mw:WikiLink" href="./%25+r?action=edit&amp;redlink=1" title="%+r" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./%25+r"},"sa":{"href":"%+r"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["%+r"]}}'>%+r</a>
<a rel="mw:WikiLink" href="./%25?action=edit&amp;redlink=1" title="%" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./%25"},"sa":{"href":"%"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["%"]}}'>%</a> <a rel="mw:WikiLink" href="./+?action=edit&amp;redlink=1" title="+" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./+"},"sa":{"href":"+"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["+"]}}'>+</a> <span class="mw-default-size" typeof="mw:Error mw:File" data-parsoid='{"optList":[{"ck":"bogus","ak":"foo"},{"ck":"caption","ak":"[[bar]]"}]}' data-mw='{"caption":"&lt;a rel=\"mw:WikiLink\" href=\"./Bar\" title=\"Bar\" data-parsoid=&apos;{\"stx\":\"simple\",\"a\":{\"href\":\"./Bar\"},\"sa\":{\"href\":\"bar\"},\"dsr\":[94,101,2,2]}&apos;>bar&lt;/a>","errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}]}'><a href="./Special:FilePath/%25+abc9"><span class="mw-file-element mw-broken-media" resource="./File:%25+abc9" data-parsoid='{"a":{"resource":"./File:%25+abc9"},"sa":{"resource":"File:%+abc%39"}}'>bar</span></a></span>
<a rel="mw:WikiLink" href="./3E?action=edit&amp;redlink=1" title="3E" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./3E"},"sa":{"href":"%33%45"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["3E"]}}'>3E</a> <a rel="mw:WikiLink" href="./3E+?action=edit&amp;redlink=1" title="3E+" class="new" typeof="mw:LocalizedAttrs" data-parsoid='{"stx":"simple","a":{"href":"./3E+"},"sa":{"href":"%33%45+"}}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["3E+"]}}'>3E+</a></p>
!! end

!! test
Confirm that 'apos' named character reference doesn't make it to output (not legal in HTML 4)
!! wikitext
Text&apos;s been normalized?
!! html
<p>Text&#39;s been normalized?
</p>
!! end

!! test
T21052 U+3000 IDEOGRAPHIC SPACE should terminate free external links
!! wikitext
http://www.example.org/　<-- U+3000 (vim: ^Vu3000)
!! html
<p><a rel="nofollow" class="external free" href="http://www.example.org/">http://www.example.org/</a>　&lt;-- U+3000 (vim: ^Vu3000)
</p>
!! end

!! test
T21052 U+3000 IDEOGRAPHIC SPACE should terminate bracketed external links
!! wikitext
[http://www.example.org/　ideograms]
!! html
<p><a rel="nofollow" class="external text" href="http://www.example.org/">ideograms</a>
</p>
!! end

!! test
T21052 U+3000 IDEOGRAPHIC SPACE should terminate external images links
!! wikitext
http://www.example.org/pic.png　<-- U+3000 (vim: ^Vu3000)
!! html
<p><img src="http://www.example.org/pic.png" alt="pic.png" />　&lt;-- U+3000 (vim: ^Vu3000)
</p>
!! end

!! article
MediaWiki:loop1
!! text
{{Identical|A}}
!! endarticle

!! article
MediaWiki:loop2
!! text
{{Identical|B}}
!! endarticle

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

!! test
T33098 Template which includes system messages which includes the template
!! wikitext
{{Identical}}
!! html/php
<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>
!! html/parsoid+integrated
<p><span class="error" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"Identical","href":"./Template:Identical"},"params":{},"i":0}}]}'>Template loop detected: <a rel="mw:WikiLink" href="./Template:Identical" title="Template:Identical">Template:Identical</a></span><span about="#mwt1">
</span><span class="error" about="#mwt1" data-parsoid='{"stx":"html"}'>Template loop detected: <a rel="mw:WikiLink" href="./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/php
<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>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Şablon:Ucfırst:blah?action=edit&amp;redlink=1" title="Şablon:Ucfırst:blah" about="#mwt1" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./Şablon:Ucfırst:blah"},"sa":{"href":"Şablon:Ucfırst:blah"},"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"ucfırst:blah","href":"./Şablon:Ucfırst:blah"},"params":{},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Şablon:Ucfırst:blah"]}}'>Ş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/php
<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>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Template:Ucfırst:blah?action=edit&amp;redlink=1" title="Template:Ucfırst:blah" about="#mwt1" typeof="mw:Transclusion mw:LocalizedAttrs" class="new" data-parsoid='{"stx":"simple","a":{"href":"./Template:Ucfırst:blah"},"sa":{"href":"Template:Ucfırst:blah"},"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"ucfırst:blah","href":"./Template:Ucfırst:blah"},"params":{},"i":0}}]}' data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Template:Ucfırst:blah"]}}'>Template:Ucfırst:blah</a></p>
!! end

!! article
MediaWiki:T34057
!! text
== {{int:ok}} ==
!! endarticle

!! test
T34057: Title needed when expanding <h> nodes.
!! options
title=[[Main Page]]
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{int:T34057}}
!! html/php
<div class="mw-heading mw-heading2"><h2 id="OK">OK</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Main_Page&amp;action=edit&amp;section=1" title="Edit section: OK">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid+integrated
<h2 about="#mwt1" typeof="mw:Transclusion" id="OK" data-mw='{"parts":[{"template":{"target":{"wt":"int:T34057","function":"int"},"params":{},"i":0}}]}'>OK</h2>
!! end

!! test
Title needed when expanding templates.
!! options
title=[[Main Page]]
!! wikitext
{{Template with pagename}}
!! html/php
<p>This is Main Page.
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"Template with pagename","href":"./Template:Template_with_pagename"},"params":{},"i":0}}]}'>This is Main Page.</span></p>
!! end

!! test
Strip marker in urlencode
!! wikitext
{{urlencode:x<nowiki/>y}}
{{urlencode:x<nowiki/>y|wiki}}
{{urlencode:x<nowiki/>y|path}}
{{urlencode:x<pre id="one">two</pre>y}}
!! html/php
<p>xy
xy
xy
xy
</p>
!! end

!! test
Strip marker in lc
!! wikitext
{{lc:x<nowiki/>y}}
!! html/php
<p>xy
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"lc:x&lt;nowiki/>y","function":"lc"},"params":{},"i":0}}]}'>x</span><span>y</span></p>
!! end

!! test
Strip marker in uc
!! wikitext
{{uc:x<nowiki/>y}}
!! html/php
<p>XY
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"uc:x&lt;nowiki/>y","function":"uc"},"params":{},"i":0}}]}'>X</span><span>Y</span></p>
!! end

!! test
Strip marker in formatNum
!! wikitext
{{formatnum:1<nowiki/>2}}
{{formatnum:1<nowiki/>2|R}}
!! html/php
<p>12
12
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:1&lt;nowiki/>2","function":"formatnum"},"params":{},"i":0}}]}'>1</span><span about="#mwt1">2</span> <span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:1&lt;nowiki/>2","function":"formatnum"},"params":{"1":{"wt":"R"}},"i":0}}]}'>1</span><span about="#mwt2">2</span></p>
!! end

!! test
Check noCommafy in formatNum
!! options
language=be-tarask
!! wikitext
{{formatnum:123456.78}}
{{formatnum:123456.78|NOSEP}}
!! html/php
<p>123&#160;456,78
123456.78
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:123456.78","function":"formatnum"},"params":{},"i":0}}]}'>123 456,78</span>
<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:123456.78","function":"formatnum"},"params":{"1":{"wt":"NOSEP"}},"i":0}}]}'>123456.78</span></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/php
<p>1,234.56
1,234.56
1,234.56
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:1,234.56","function":"formatnum"},"params":{"1":{"wt":"Random"}},"i":0}}]}'>1,234.56</span>
<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:1,234.56","function":"formatnum"},"params":{"1":{"wt":"EVERYTHING"}},"i":0}}]}'>1,234.56</span>
<span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:1234.56","function":"formatnum"},"params":{"1":{"wt":"any argument that has the string &apos;NOSEP&apos;"}},"i":0}}]}'>1,234.56</span></p>
!! end

!! test
Strip marker in grammar
!! options
language=fi
!! wikitext
{{grammar:elative|foo<nowiki/>bar}}
!! html/php
<p>foobarista
</p>
!! html/parsoid+integrated
<p><span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"grammar:elative","function":"grammar"},"params":{"1":{"wt":"foo&lt;nowiki/>bar"}},"i":0}}]}'>foobarista</span></p>
!! end

!! test
Strip marker in padleft
!! wikitext
{{padleft:|2|x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
Strip marker in padright
!! wikitext
{{padright:|2|x<nowiki/>y}}
!! html
<p>xy
</p>
!! end

!! test
Strip marker in anchorencode
!! wikitext
{{anchorencode:x<nowiki/>y}}
!! html/php
<p>xy
</p>
!! html/parsoid
<p><span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode:x&lt;nowiki/>y","function":"anchorencode"},"params":{},"i":0}}]}'>xy</span></p>
!! end

!! test
new support for bdi element (T33817)
!! wikitext
<p dir="rtl" lang="he">ולדימיר לנין (ברוסית: <bdi lang="ru">Владимир Ленин</bdi>, 24 באפריל 1870–22 בינואר 1924) הוא מנהיג פוליטי קומוניסטי רוסי.</p>
!! html
<p dir="rtl" lang="he">ולדימיר לנין (ברוסית: <bdi lang="ru">Владимир Ленин</bdi>, 24 באפריל 1870–22 בינואר 1924) הוא מנהיג פוליטי קומוניסטי רוסי.</p>
!! end

!! test
Ignore pipe between table row attributes
!! wikitext
{|
|quux
|- id=foo | style='color: red'
|bar
|}
!! html
<table>
<tbody><tr>
<td>quux
</td></tr>
<tr id="foo" style="color: red">
<td>bar
</td></tr></tbody></table>
!! end

!! test
Language parser function (autonym)
!! wikitext
{{#language:ar}}
!! html/php
<p>العربية
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language:ar","function":"language"},"params":{},"i":0}}]}'>العربية</span></p>
!! end

!! test
Language parser function (case-insensitive)
!! wikitext
{{#language:AR}}
!! html/php
<p>العربية
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language:AR","function":"language"},"params":{},"i":0}}]}'>العربية</span></p>
!! end

!! test
Language parser function (non-autonym)
!! wikitext
{{#language:aR|En}}
!! html/php
<p>Arabic
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language:aR","function":"language"},"params":{"1":{"wt":"En"}},"i":0}}]}'>Arabic</span></p>
!! end

!! test
Language parser function (bcp-47 codes)
!! wikitext
{{#language:de-x-formal|en-simple}}
!! html/php
<p>German (formal address)
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language:de-x-formal","function":"language"},"params":{"1":{"wt":"en-simple"}},"i":0}}]}'>German (formal address)</span></p>
!! end

!! test
Language parser function (target language)
!! options
language=ar
!! wikitext
{{#language}} / {{#language:}}
!! html/php
<p>العربية / العربية
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language","function":"language"},"params":{},"i":0}}]}'>العربية</span> / <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language:","function":"language"},"params":{},"i":0}}]}'>العربية</span></p>
!! end

!! test
Language parser function (target language, non-autonym)
!! options
language=ar
!! wikitext
{{#language:|en}}
!! html/php
<p>Arabic
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language:","function":"language"},"params":{"1":{"wt":"en"}},"i":0}}]}'>Arabic</span></p>
!! end

!! test
Dir parser function (valid codes)
!! wikitext
Persian: {{#dir:fa}}

English: {{#dir:en}}

Persian (with space): {{#dir: fa}}

Tajik: {{#dir:tg}}

The string 'egl' is a valid internal code; however when used as a
BCP-47 code it refers to the internal code 'eml'.  Unfortunately,
both of these have ltr directionality which makes this test case
less useful than it could be.

Ambiguous BCP-47 code:
;Directionality of internal code 'egl':{{#dir:egl}}
;Directionality of internal code 'eml':{{#dir:egl|bcp47}} == {{#dir:eml}}
!! html/php
<p>Persian: rtl
</p><p>English: ltr
</p><p>Persian (with space): rtl
</p><p>Tajik: ltr
</p><p>The string 'egl' is a valid internal code; however when used as a
BCP-47 code it refers to the internal code 'eml'.  Unfortunately,
both of these have ltr directionality which makes this test case
less useful than it could be.
</p><p>Ambiguous BCP-47 code:
</p>
<dl><dt>Directionality of internal code 'egl'</dt>
<dd>ltr</dd>
<dt>Directionality of internal code 'eml'</dt>
<dd>ltr == ltr</dd></dl>
!! html/parsoid+integrated
<p>Persian: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:fa","function":"dir"},"params":{},"i":0}}]}'>rtl</span></p>
<p>English: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:en","function":"dir"},"params":{},"i":0}}]}'>ltr</span></p>
<p>Persian (with space): <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir: fa","function":"dir"},"params":{},"i":0}}]}'>rtl</span></p>
<p>Tajik: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:tg","function":"dir"},"params":{},"i":0}}]}'>ltr</span></p>
<p>The string 'egl' is a valid internal code; however when used as a BCP-47 code it refers to the internal code 'eml'. Unfortunately, both of these have ltr directionality which makes this test case less useful than it could be.</p>
<p>Ambiguous BCP-47 code:</p>
<dl>
<dt>Directionality of internal code 'egl'</dt>
<dd><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:egl","function":"dir"},"params":{},"i":0}}]}'>ltr</span></dd>
<dt>Directionality of internal code 'eml'</dt>
<dd><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:egl","function":"dir"},"params":{"1":{"wt":"bcp47"}},"i":0}}]}'>ltr</span> == <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:eml","function":"dir"},"params":{},"i":0}}]}'>ltr</span></dd>
</dl>
!! end

!! test
Dir parser function (target language)
!! options
language=fa
cat
!! metadata
!! wikitext
These are all equivalent:

{{#dir}} / {{#dir:}} / {{#dir:{{PAGELANGUAGE}}}}
!! html/php
<p>These are all equivalent:
</p><p>rtl / rtl / rtl
</p>
!! html/parsoid+integrated
<p>These are all equivalent:</p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir","function":"dir"},"params":{},"i":0}}]}'>rtl</span> / <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:","function":"dir"},"params":{},"i":0}}]}'>rtl</span> / <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:{{PAGELANGUAGE}}","function":"dir"},"params":{},"i":0}}]}'>rtl</span></p>
!! end

!! test
Dir parser function (invalid code)
!! options
cat
!! wikitext
{{#dir:blah<blah}}
!! metadata
cat=Pages_with_invalid_language_codes sort=
!! html/php
<p>ltr
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#dir:blah&lt;blah","function":"dir"},"params":{},"i":0}}]}'>ltr</span></p>
!! end

!! test
Bcp47 parser function (valid codes)
!! wikitext
Serbian: {{#bcp47:sr-ec}}

Cantonese: {{#bcp47:zh-yue}}

Formal German (with space): {{#bcp47: de-formal}}

Simple English: {{#bcp47:simple}}

The string 'egl' is a valid internal code, distinct from the
internal code 'eml'; however both map to the BCP-47 code 'egl'.

Ambiguous BCP-47 code:
;Internal code 'eml':{{#bcp47:eml}} == egl
;Internal code 'egl':{{#bcp47:egl}} == egl
!! html/php
<p>Serbian: sr-Cyrl
</p><p>Cantonese: yue
</p><p>Formal German (with space): de-x-formal
</p><p>Simple English: en-simple
</p><p>The string 'egl' is a valid internal code, distinct from the
internal code 'eml'; however both map to the BCP-47 code 'egl'.
</p><p>Ambiguous BCP-47 code:
</p>
<dl><dt>Internal code 'eml'</dt>
<dd>egl == egl</dd>
<dt>Internal code 'egl'</dt>
<dd>egl == egl</dd></dl>
!! html/parsoid+integrated
<p>Serbian: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:sr-ec","function":"bcp47"},"params":{},"i":0}}]}'>sr-Cyrl</span></p>
<p>Cantonese: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:zh-yue","function":"bcp47"},"params":{},"i":0}}]}'>yue</span></p>
<p>Formal German (with space): <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47: de-formal","function":"bcp47"},"params":{},"i":0}}]}'>de-x-formal</span></p>
<p>Simple English: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:simple","function":"bcp47"},"params":{},"i":0}}]}'>en-simple</span></p>
<p>The string 'egl' is a valid internal code, distinct from the internal code 'eml'; however both map to the BCP-47 code 'egl'.</p>
<p>Ambiguous BCP-47 code:</p>
<dl>
<dt>Internal code 'eml'</dt>
<dd><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:eml","function":"bcp47"},"params":{},"i":0}}]}'>egl</span> == egl</dd>
<dt>Internal code 'egl'</dt>
<dd><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:egl","function":"bcp47"},"params":{},"i":0}}]}'>egl</span> == egl</dd>
</dl>
!! end

!! test
Bcp47 parser function (target language)
!! options
language=sr-ec
!! wikitext
These are all equivalent:

{{#bcp47}} / {{#bcp47:}} / {{#bcp47:{{PAGELANGUAGE}}}}
!! html/php
<p>These are all equivalent:
</p><p>sr-Cyrl / sr-Cyrl / sr-Cyrl
</p>
!! html/parsoid+integrated
<p>These are all equivalent:</p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47","function":"bcp47"},"params":{},"i":0}}]}'>sr-Cyrl</span> / <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:","function":"bcp47"},"params":{},"i":0}}]}'>sr-Cyrl</span> / <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:{{PAGELANGUAGE}}","function":"bcp47"},"params":{},"i":0}}]}'>sr-Cyrl</span></p>
!! end

# from https://commons.wikimedia.org/w/index.php?title=Template:BCP47&oldid=597081406
!! test
Bcp47 parser function (examples from Template:BCP47)
!! wikitext
Unaffected codes, for example:
*{{#bcp47:en}} returns: "en"
Changes required by BCP47, using standard codes:
*{{#bcp47:als}} returns: "gsw"
*{{#bcp47:fiu-vro}} returns: "vro"
*{{#bcp47:simple}} returns: "en"
*{{#bcp47:zh-classical}} returns: "lzh"
*{{#bcp47:roa-rup}} returns: "rup"
Changes required by BCP47, currently using private-use extensions:
*{{#bcp47:nrm}} returns: "nrf"
*{{#bcp47:roa-tara}} returns: "it-x-tara"
Changes preferable with BCP47 for improved interoperability (not really violations):
*{{#bcp47:be-x-old}} returns: "be-tarask"
!! html/php
<p>Unaffected codes, for example:
</p>
<ul><li>en returns: "en"</li></ul>
<p>Changes required by BCP47, using standard codes:
</p>
<ul><li>gsw returns: "gsw"</li>
<li>vro returns: "vro"</li>
<li>en-simple returns: "en"</li>
<li>lzh returns: "lzh"</li>
<li>rup returns: "rup"</li></ul>
<p>Changes required by BCP47, currently using private-use extensions:
</p>
<ul><li>nrf returns: "nrf"</li>
<li>nap-x-tara returns: "it-x-tara"</li></ul>
<p>Changes preferable with BCP47 for improved interoperability (not really violations):
</p>
<ul><li>be-tarask returns: "be-tarask"</li></ul>
!! html/parsoid+integrated
<p>Unaffected codes, for example:</p>
<ul>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:en","function":"bcp47"},"params":{},"i":0}}]}'>en</span> returns: "en"</li>
</ul>
<p>Changes required by BCP47, using standard codes:</p>
<ul>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:als","function":"bcp47"},"params":{},"i":0}}]}'>gsw</span> returns: "gsw"</li>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:fiu-vro","function":"bcp47"},"params":{},"i":0}}]}'>vro</span> returns: "vro"</li>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:simple","function":"bcp47"},"params":{},"i":0}}]}'>en-simple</span> returns: "en"</li>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:zh-classical","function":"bcp47"},"params":{},"i":0}}]}'>lzh</span> returns: "lzh"</li>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:roa-rup","function":"bcp47"},"params":{},"i":0}}]}'>rup</span> returns: "rup"</li>
</ul>
<p>Changes required by BCP47, currently using private-use extensions:</p>
<ul>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:nrm","function":"bcp47"},"params":{},"i":0}}]}'>nrf</span> returns: "nrf"</li>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:roa-tara","function":"bcp47"},"params":{},"i":0}}]}'>nap-x-tara</span> returns: "it-x-tara"</li>
</ul>
<p>Changes preferable with BCP47 for improved interoperability (not really violations):</p>
<ul>
<li><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#bcp47:be-x-old","function":"bcp47"},"params":{},"i":0}}]}'>be-tarask</span> returns: "be-tarask"</li>
</ul>
!! end

!!test
Padleft and padright (default 0-padding)
!! wikitext
{{padleft:xyz|5}}
{{padright:xyz|5}}
!! html/php
<p>00xyz
xyz00
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padleft:xyz","function":"padleft"},"params":{"1":{"wt":"5"}},"i":0}}]}'>00xyz</span>
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:xyz","function":"padright"},"params":{"1":{"wt":"5"}},"i":0}}]}'>xyz00</span></p>
!! end

!!test
Padleft and padright (partial fill)
!! wikitext
{{padleft:xyz|6|ab}}
{{padright:xyz|6|ab}}
!! html/php
<p>abaxyz
xyzaba
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padleft:xyz","function":"padleft"},"params":{"1":{"wt":"6"},"2":{"wt":"ab"}},"i":0}}]}'>abaxyz</span>
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:xyz","function":"padright"},"params":{"1":{"wt":"6"},"2":{"wt":"ab"}},"i":0}}]}'>xyzaba</span></p>
!! end

!!test
Padleft and padright as substr
!! wikitext
{{padleft:|3|abcde}}
{{padright:|3|abcde}}
!! html/php
<p>abc
abc
</p>
!! html/parsoid
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padleft:","function":"padleft"},"params":{"1":{"wt":"3"},"2":{"wt":"abcde"}},"i":0}}]}'>abc</span>
<span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"padright:","function":"padright"},"params":{"1":{"wt":"3"},"2":{"wt":"abcde"}},"i":0}}]}'>abc</span></p>
!! end

!! test
Padleft and padright with non-numerical length (T180403)
!! wikitext
{{padleft:abcdef|junk}}
{{padright:abcdef|junk}}
!! html/php
<p>abcdef
abcdef
</p>
!! end

!!test
Special parser function
!! wikitext
{{#special:RandomPage}}
{{#special:BaDtItLe}}
{{#special:Foobar}}
!! html/php
<p>Special:Random
Special:Badtitle
Special:Foobar
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#special:RandomPage","function":"special"},"params":{},"i":0}}]}'>Special:Random</span>
<span about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#special:BaDtItLe","function":"special"},"params":{},"i":0}}]}'>Special:Badtitle</span>
<span about="#mwt3" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#special:Foobar","function":"special"},"params":{},"i":0}}]}'>Special:Foobar</span></p>
!! end

# {{=}} will be converted to a parser function which expands to `=`
# If you have it defined as a Template that expands to `=` that's ok;
# and using it explicitly as {{Template:=}} (regardless of what it
# expands to) is also ok and will not generate a tracking category.
# T91154
#
# FIXME: Parsoid doesn't yet support this magic word natively, so standalone
# mode will fail this test.
!! test
Using {{=}} when it expands to "=" should not create a tracking category
!! wikitext
This uses {{=}} and {{Template:=}}.
!! html/php
<p>This uses = and =.
</p>
!! html/parsoid
<p>This uses <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"=","function":"="},"params":{},"i":0}}]}'>=</span> and <span typeof="mw:Nowiki mw:Transclusion" about="#mwt2" data-mw='{"parts":[{"template":{"target":{"wt":"Template:=","href":"./Template:="},"params":{},"i":0}}]}'>=</span>.</p>
!! end

# Repeat the test, looking at categories.  Note: none should be emitted!
!! test
Using {{=}} when it expands to "=" should not create a tracking category (cat)
!! options
cat
!! wikitext
This uses {{=}} and {{Template:=}}.
!! html/php
<p>This uses = and =.
</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/" class="external autonumber"></a></p>
!! end

!!test
T36939 - Case insensitive link parsing ([HttP:// title])
!! wikitext
[HttP://MediaWiki.Org/ MediaWiki]
!! html
<p><a rel="nofollow" class="external text" href="HttP://MediaWiki.Org/">MediaWiki</a>
</p>
!! end

!!test
T36939 - Case insensitive link parsing (HttP://)
!! wikitext
HttP://MediaWiki.Org/
!! html/php
<p><a rel="nofollow" class="external free" href="HttP://MediaWiki.Org/">HttP://MediaWiki.Org/</a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="HttP://MediaWiki.Org/" class="external free">HttP://MediaWiki.Org/</a></p>
!! end


###
### Parsoid-specific tests
### Parsoid-PHP parser incompatibilities
###
!!test
1. SOL-sensitive wikitext tokens as template-args
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{1x|*a}}
{{1x|#a}}
{{1x|:a}}
!! html/php
<ul><li>a</li></ul>
<ol><li>a</li></ol>
<dl><dd>a</dd></dl>
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"*a"}},"i":0}}]}'><li>a</li></ul>
<ol about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"#a"}},"i":0}}]}'><li>a</li></ol>
<dl about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":":a"}},"i":0}}]}'><dd>a</dd></dl>
!!end

#### -----------------------------------------------------------------
#### Parsoid-specific functionality tests
#### -----------------------------------------------------------------

## Just a regression test
!! test
Wikilink with only closing tag in target
!! options
parsoid=wt2html
!! wikitext
[[Test|</span>]]
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Test" title="Test" data-parsoid='{"stx":"piped","a":{"href":"./Test"},"sa":{"href":"Test"}}'></a></p>
!! end

#### ----------------------------------------------------------------
#### Parsoid-only testing of Parsoid's impl of LST
#### Not implemented yet, see
#### https://www.mediawiki.org/wiki/Parsoid/HTML_based_LST
#### ----------------------------------------------------------------

## We still need to support serializing the older format while content is stored.
!! test
LST Sections: Backwards compatibility
!! options
parsoid={
  "suppressErrors": true,
  "modes": ["html2wt"]
}
!! wikitext
<section begin="2011-05-16" />
<section end="2014-04-10 (MW 1.23wmf22)" />
!! html/parsoid
<p><meta typeof="mw:Extension/LabeledSectionTransclusion/begin" content="2011-05-16"/>
<meta typeof="mw:Extension/LabeledSectionTransclusion/end" content="2014-04-10 (MW 1.23wmf22)"/></p>
!! end

!! test
LST Sections: Newfangled approach
!! wikitext
<section begin="2011-05-16" />
<section end="2014-04-10 (MW 1.23wmf22)" />
!! html/parsoid
<p><link typeof="mw:Extension/section" about="#mwt4" data-mw='{"name":"section","attrs":{"begin":"2011-05-16"}}' />
<link typeof="mw:Extension/section" about="#mwt6" data-mw='{"name":"section","attrs":{"end":"2014-04-10 (MW 1.23wmf22)"}}' /></p>
!! html/parsoid+integrated
<p>&lt;section begin="2011-05-16" /> &lt;section end="2014-04-10 (MW 1.23wmf22)" /></p>
!! end

!! test
LST Sections: Fostering
!! options
parsoid=wt2html
!! wikitext
{|
<section name="testing"/>
| 123
|}
!! html/parsoid
<link typeof="mw:Extension/section" about="#mwt2" data-parsoid='{"fostered":true}' data-mw='{"name":"section","attrs":{"name":"testing"}}'/><table>

<tbody><tr><td>123
</td></tr></tbody></table>
!! html/parsoid+integrated
<p>&lt;section name="testing"/></p>
<table>
<tbody>
<tr>
<td>123</td>
</tr>
</tbody>
</table>
!! end

#--------- Test stripping of empty nodes in template content ----------

!! test
Empty LI and TR nodes should be stripped from template content
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{EmptyLITest}}
{{EmptyTRTest}}
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"EmptyLITest","href":"./Template:EmptyLITest"},"params":{},"i":0}}]}'><li>a</li>


<li>b</li></ul>
<table about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"EmptyTRTest","href":"./Template:EmptyTRTest"},"params":{},"i":0}}]}'>
<tbody>
<tr>
<td>foo</td></tr>

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

!! test
Empty LI and TR nodes should not be stripped from top-level content
!! wikitext
*a
*
*b

{|
|-
|-
|foo
|}
!! html/parsoid
<ul>
<li>a</li>
<li class='mw-empty-elt'></li>
<li>b</li>
</ul>
<table>
<tbody>
<tr class='mw-empty-elt'></tr>
<tr>
<td>foo</td>
</tr>
</tbody>
</table>
!! end

!! test
Empty TR nodes should not be stripped if they have any attributes set
!! wikitext
{{EmptyTRWithHTMLAttrTest}}
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"EmptyTRWithHTMLAttrTest","href":"./Template:EmptyTRWithHTMLAttrTest"},"params":{},"i":0}}]}'>
<tr align='center'></tr>
<tr><td>foo</td></tr>
<tr align='center'></tr>
<tr><td>bar</td></tr>
</table>
!! end

!! 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
<div title="Hello world">Foo</div>
!! end

!! test
Table with broken attribute value quoting
!! options
parsoid=wt2html,html2html
!! wikitext
{|
| title="Hello world|Foo
|}
!! html/php
<table>
<tbody><tr>
<td title="Hello world">Foo
</td></tr></tbody></table>
!! html/parsoid
<table>
<tr>
<td title="Hello world">Foo
</td></tr></table>
!! end

!! test
Table with broken attribute value quoting on consecutive lines
!! options
parsoid=wt2html,html2html
!! wikitext
{|
| title="Hello world|Foo
| style="color:red|Bar
|}
!! html/php
<table>
<tbody><tr>
<td title="Hello world">Foo
</td>
<td style="color:red">Bar
</td></tr></tbody></table>
!! html/parsoid
<table><tbody>
<tr>
<td title="Hello world">Foo
</td><td style="color:red">Bar
</td></tr></tbody></table>
!! end

!!test
Accept empty td cell attribute
!! wikitext
{|
| align="center" |foo||  |
|}
!! html
<table>
<tbody><tr>
<td align="center">foo</td>
<td>
</td></tr></tbody></table>
!! end

!!test
Non-empty attributes in th-cells
!! wikitext
{|
!Foo!! style="color: red" |Bar
|}
!! html
<table>
<tbody><tr>
<th>Foo</th>
<th style="color: red">Bar
</th></tr></tbody></table>
!! end

!!test
Accept empty attributes in th-cells
!! wikitext
{|
!|foo!!|bar
|}
!! html
<table>
<tbody><tr>
<th>foo</th>
<th>bar
</th></tr></tbody></table>
!! end

!!test
Empty table rows go away
!! wikitext
{|
|Hello
|there
|- class="foo"
|-
|}
!! html
<table>
<tbody><tr>
<td>Hello
</td>
<td>there
</td></tr>

</tbody></table>
!! end

###
### Parsoid-centric tests for testing RTing of inter-element separators
### Edge cases not tested by existing parser tests and specific to
### Parsoid-specific serialization strategies.
###

!!test
RT-ed inter-element separators should be valid separators
!! wikitext
{|
|- [[foo]]
|}
!! html/php
<table>

</table>
!! html/parsoid
<table>
<tbody><tr class='mw-empty-elt' data-parsoid='{"startTagSrc":"|-","a":{"[[foo]]":null},"sa":{"[[foo]]":""}}'></tr>
</tbody></table>
!!end

# Parsoid-only test of a DOM pass
!!test
Trailing newlines in a deep dom-subtree that ends a wikitext line should be migrated out
!! wikitext
{|
|<small>foo
bar
|}

{|
|<small>foo<small>
|}
!! html/parsoid
<table>
<tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{}'><small data-parsoid='{"stx":"html","autoInsertedEnd":true}'>foo
<p>bar</p></small></td></tr>
</tbody></table>

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

# Note that the "style" attribute is really a template parameter here.
# The = would have to be {{=}} if you wanted the literal.
!!test
Empty TD followed by TD with tpl-generated attribute
!! wikitext
{|
|-
|
|{{1x|style='color:red'}}|foo
|}
!! html
<table>

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

!!test
Indented table with an empty td
!! wikitext
 {|
 |-
 |
 |foo
 |}
!! html
<table>

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

!! test
Indented table with blank lines in between (T85627)
!! wikitext
 {|
 |foo
 
 
 |}
!! html/php
<table>
<tbody><tr>
<td>foo
<p><br /> 
</p>
</td></tr></tbody></table>
!! html/parsoid
 <table>
 <tbody><tr><td>foo
 <p>
 <br /></p></td></tr>
 </tbody></table>
!! end

!!test
Indented block & table
!! wikitext
 <div>foo</div>
 {|
 |foo
 |}
!! html/php
 <div>foo</div>
<table>
<tbody><tr>
<td>foo
</td></tr></tbody></table>
!! html/parsoid
 <div data-parsoid='{"stx":"html"}'>foo</div>
 <table><tbody>
 <tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{}'>foo</td></tr>
 </tbody></table>
!!end

!! test
Indent and comment before table row
!! wikitext
{|
 <!--hi-->|-
 |there
|}
!! html/php
<table>

<tbody><tr>
<td>there
</td></tr></tbody></table>
!! html/parsoid
<table>
 <!--hi--><tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
 <td data-parsoid='{}'> there</td></tr>
</tbody></table>
!! end

# PHP parser omits empty TR
!!test
Empty TR followed by a template-generated TR
!! wikitext
{|
|-
{{1x|<tr><td>foo</td></tr>}}
|}
!! html/php
<table>

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

## PHP and parsoid output differ for this; as usual PHP omits empty
## elements, and since it strips the comments the TR is empty.
!!test
Empty TR followed by mixed-ws-comment line should RT correctly
!! wikitext
{|
|-
 <!--c-->
|-
<!--c--> <!--d-->
|}
!! html/php
<table>


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

!!test
Multi-line image caption generated by templates with/without trailing newlines
!! wikitext
[[File:Foobar.jpg|thumb|300x300px|foo\n{{1x|A}}\n{{1x|B}}\n{{1x|C}}]]
[[File:Foobar.jpg|thumb|300x300px|foo\n{{1x|A}}\n{{1x|B}}\n{{1x|C}}\n\n]]
!! html/parsoid
<figure typeof="mw:File/Thumb"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/450px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/600px-Foobar.jpg 2x" class="mw-file-element"/></a><figcaption>foo\n<span about="#mwt9" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"A"}},"i":0}}]}'>A</span>\n<span about="#mwt10" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"B"}},"i":0}}]}'>B</span>\n<span about="#mwt11" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"C"}},"i":0}}]}'>C</span></figcaption></figure>
<figure typeof="mw:File/Thumb"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/300px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="34" width="300" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/450px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/600px-Foobar.jpg 2x" class="mw-file-element"/></a><figcaption>foo\n<span about="#mwt12" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"A"}},"i":0}}]}'>A</span>\n<span about="#mwt13" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"B"}},"i":0}}]}'>B</span>\n<span about="#mwt14" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"C"}},"i":0}}]}'>C</span>\n\n</figcaption></figure>
!! end

!! test
New element inserted (without intervening newlines) after an old sol-transparent node should serialize correctly
!! options
parsoid=html2wt
!! html/parsoid
<meta typeof="mw:Includes/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>foo&lt;/includeonly>"}' data-mw='{"src":"&lt;includeonly>foo&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><p>new para</p>

<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{}'/><h1>new heading</h1>
!! wikitext
<includeonly>foo</includeonly>
new para

[[Category:Foo]]

= new heading =
!! end

## PHP emits broken html for this, and since this is primarily
## a Parsoid serializer test, marking this Parsoid only
!! test
Improperly nested inline or quotes tags with whitespace in between
!! options
parsoid=html2wt
!! html/parsoid
<p><span> <s>x</s></span><s> </s>
<b> <i>x</i></b><i> </i>
</p>
!! wikitext
<span> <s>x</s></span><s> </s>
''' ''x'''''
!! end

!!test
Encapsulate protected attributes from wt
!! wikitext
<div typeof="mw:placeholder stuff" data-mw="whoo" data-parsoid="weird" data-parsoid-other="no" about="time" rel="mw:true">foo</div>

{| typeof="mw:placeholder stuff" data-mw="whoo" data-parsoid="weird" data-parsoid-other="no" about="time" rel="mw:true"
|ok
|}
!! html/parsoid
<div data-x-typeof="mw:placeholder stuff" data-x-data-mw="whoo" data-x-data-parsoid="weird" data-x-data-parsoid-other="no" data-x-about="time" data-x-rel="mw:true">foo</div>

<table data-x-typeof="mw:placeholder stuff" data-x-data-mw="whoo" data-x-data-parsoid="weird" data-x-data-parsoid-other="no" data-x-about="time" data-x-rel="mw:true">
<tbody><tr><td data-parsoid='{}'>ok</td></tr>
</tbody></table>
!!end

## Currently the p-wrapper is fragile in how it adds / removes transformations.
## Having nested or stray pre tags results in the attempt to add duplicates,
## causing an assertion fail. This test tries to prevent that situation.
!! test
Ensure ParagraphWrapper can deal with stray closing pre tags
!! options
parsoid=wt2html
!! wikitext
plain text</pre>
!! html/parsoid
<p>plain text</p>
!! end

## Remex doesn't account for fostered content.
!! test
1. Ensure fostered text content is wrapped in element nodes
!! options
parsoid=wt2html
!! wikitext
<table>hi</table><table>ho</table>
!! html/php
hi<table></table>ho<table></table>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>hi</p><table data-parsoid='{"stx":"html"}'></table><p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'>ho</p><table data-parsoid='{"stx":"html"}'></table>
!! end

## Remex doesn't account for fostered content.
!! test
2. Ensure fostered text content is wrapped in element nodes (traps regressions around fostered marker on the element getting lost)
!! options
parsoid=wt2html,wt2wt
!! wikitext
<table>
<tr> || ||
<td> a
</table>
!! html/php
 || ||
<table>
<tbody><tr><td> a
</td></tr></tbody></table>
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true}'> || ||</p>
<table data-parsoid='{"stx":"html"}'>
<tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'> a
</td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
Encapsulation properly handles null DSR information from foster box
!! options
parsoid=wt2html,wt2wt
!! wikitext
{{1x|<table>foo<tr><td>bar</td></tr></table>}}
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>foo&lt;tr>&lt;td>bar&lt;/td>&lt;/tr>&lt;/table>"}},"i":0}}]}'>foo</p><table about="#mwt1" data-parsoid='{"stx":"html"}'><tbody><tr><td>bar</td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
1. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{1x|foo<tr><td>bar</td></tr>}}</table>
!! html/php
foo<table><tbody><tr><td>bar</td></tr></tbody></table>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;tr>&lt;td>bar&lt;/td>&lt;/tr>"}},"i":0}},"&lt;/table>"]}'>foo</p><table about="#mwt2" data-parsoid='{"stx":"html"}'><tbody><tr><td>bar</td></tr></tbody></table>
!! end

!! test
2. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table><div>{{1x|foo}}</div><tr><td>bar</td></tr></table>
!! html/parsoid
<div typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><div>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo&quot;}},&quot;i&quot;:0}},&quot;</div><tr><td>bar</td></tr></table>&quot;]}">foo</div>
<table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

!! test
3. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table><div><p>{{1x|foo</p></div><tr><td>}}bar</td></tr></table>
!! html/parsoid
<div typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><div><p>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo</p></div><tr><td>&quot;}},&quot;i&quot;:0}},&quot;bar</td></tr></table>&quot;]}">
<p>foo</p>
</div>
<table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

!! test
4. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table><div><p>{{1x|foo</p></div><tr><td>}}bar</td></tr></table>
!! html/parsoid
<div typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table><div><p>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;foo</p></div><tr><td>&quot;}},&quot;i&quot;:0}},&quot;bar</td></tr></table>&quot;]}">
<p>foo</p>
</div>
<table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

## Remex doesn't account for fostered content.
!! test
5. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table><tr><td><div><p>{{1x|foo</p></div></td>foo}}</tr></table>
!! html/php
foo<table><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;tr>&lt;td>&lt;div>&lt;p>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;/p>&lt;/div>&lt;/td>foo"}},"i":0}},"&lt;/tr>&lt;/table>"]}'>foo</p><table about="#mwt2" data-parsoid='{"stx":"html"}'><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
6. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
<table><tr><td><div><p>{{1x|foo</p></div></td>foo</tr></table>}}<p>ok</p>
!! html/php
foo<table><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table><p>ok</p>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;tr>&lt;td>&lt;div>&lt;p>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo&lt;/p>&lt;/div>&lt;/td>foo&lt;/tr>&lt;/table>"}},"i":0}}]}'>foo</p><table about="#mwt2" data-parsoid='{"stx":"html"}'><tbody><tr><td><div><p>foo</p></div></td></tr></tbody></table><p data-parsoid='{"stx":"html"}'>ok</p>
!! end

!! test
7. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{1x|<p>foo</p>}}<td>bar</td></table>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw="{&quot;parts&quot;:[&quot;<table>&quot;,{&quot;template&quot;:{&quot;target&quot;:{&quot;wt&quot;:&quot;1x&quot;,&quot;href&quot;:&quot;./Template:1x&quot;},&quot;params&quot;:{&quot;1&quot;:{&quot;wt&quot;:&quot;<p>foo</p>&quot;}},&quot;i&quot;:0}},&quot;<td>bar</td></table>&quot;]}">foo</p>
<table>
<tbody>
<tr>
<td>bar</td>
</tr>
</tbody>
</table>
!! end

## Remex doesn't account for fostered content.
# Note that the wt is broken on purpose: the = should be {{=}} if you
# don't want it to be a template parameter key.
!! test
8. Encapsulate foster-parented transclusion content
!! options
parsoid=wt2wt,wt2html
!! wikitext
{{1x|a
}}{|{{1x|style='color:red'}}
|-
|b
|}
!! html/php
<p>a
</p>
<table>

<tbody><tr>
<td>b
</td></tr></tbody></table>
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a\n"}},"i":0}}]}'>a</p><span about="#mwt1">
</span><p about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"style","named":true}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"style":{"wt":"&apos;color:red&apos;"}},"i":0}},"\n|-\n|b\n|}"]}'>{{{1}}}</p><table about="#mwt3">
<tbody><tr>
<td>b
</td></tr></tbody></table>
!! end

## Remex doesn't account for fostered content.
!! test
9. Encapsulate foster-parented transclusion content
!!options
parsoid=wt2wt,wt2html
!! wikitext
<table>{{1x|hi</table>hello}}
!! html/php
hi<table></table><p>hello</p>
!! html/parsoid
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi&lt;/table>hello"}},"i":0}}]}'>hi</p><table about="#mwt2"></table><p about="#mwt2">hello</p>
!! end

!! test
Table in fosterable position
!!options
parsoid=wt2html
!! wikitext
{{OpenTable}}
<div>
{|
|}
</div>
|}
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"OpenTable","href":"./Template:OpenTable"},"params":{},"i":0}},"\n&lt;div>\n"]}' data-parsoid='{"stx":"html","autoInsertedEnd":true,"pi":[[]]}'>
</div><span about="#mwt1">
</span>
<table about="#mwt1" data-parsoid='{"autoInsertedEnd":true}'></table>

<table>
</table>
!! end

# Parsoid only for T66747
# (Also core doesn't define {{#if}} in default install)
!! test
Properly encapsulate empty-content transclusions in fosterable positions
!! wikitext
<table>
{{#if:|
<td>foo</td>
}}
</table>
!! html/parsoid
<table about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["&lt;table>\n",{"template":{"target":{"wt":"#if:","function":"if"},"params":{"1":{"wt":"\n&lt;td>foo&lt;/td>\n"}},"i":0}},"\n&lt;/table>"]}' data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}'>

</table>
!! end

## No longer captures its original intention
!! test
Always encapsulate foster box when template range is expanded to table
!! options
disabled
parsoid=wt2wt
!! wikitext
{|
hello
{{OpenTable}}
|}
!! html/parsoid
!! end

!! test
T115289: Unclosed table
!! wikitext
{{1x|<table>}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Two" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:Two"},"sa":{"href":"Category:Two"},"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'/><table about="#mwt1" data-parsoid='{"stx":"html","autoInsertedEnd":true}'><!--c--></table>
!! end

!! test
T115289: Don't migrate newlines out of tables with fostered content
!! wikitext
<table><td></td>{{1x|<tr>[[Category:One]]}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:One" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./Category:One"},"sa":{"href":"Category:One"},"fostered":true,"pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>&lt;td>&lt;/td>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tr>[[Category:One]]"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'/><link rel="mw:PageProp/Category" href="./Category:Two" about="#mwt2"/><table about="#mwt2" data-parsoid='{"stx":"html","autoInsertedEnd":true}'><tbody><tr><td></td></tr><!--c--></tbody></table>
!! end

!! test
T73074: More fostering fun
!! wikitext
<table><td></td>{{1x|<tr>}}<!--c-->[[Category:Two]]
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Two" data-parsoid='{"stx":"simple","a":{"href":"./Category:Two"},"sa":{"href":"Category:Two"},"fostered":true}'/><table data-parsoid='{"stx":"html","autoInsertedEnd":true}'><tbody><tr data-parsoid='{"autoInsertedStart":true}'><td data-parsoid='{"stx":"html"}'></td></tr><tr about="#mwt1" typeof="mw:Transclusion" class='mw-empty-elt' data-parsoid='{"autoInsertedEnd":true,"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tr>"}},"i":0}}]}'></tr><!--c--></tbody></table>
!! end

## Regression test for Parsoid's template wrapping of fostered content
!! test
Fostered content with a dom fragment token starting with a transclusion
!! options
parsoid=wt2html
!! wikitext
{|
[[File:Foobar.jpg|right|{{1x|<div>123</div>}}]]
|}
!! html/parsoid
<figure class="mw-default-size mw-halign-right" typeof="mw:File" data-parsoid='{"fostered":true}'><a href="./File:Foobar.jpg" class="mw-file-description" title="123"><img alt="123" resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" class="mw-file-element"/></a><figcaption><div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>123&lt;/div>"}},"i":0}}]}'>123</div></figcaption></figure><table>

</table>
!! end

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

!! test
1. Template wrapping shouldn't ignore fostered content
!! options
parsoid=wt2wt
!! wikitext
{|
{{tr}}
{{1x|
}}

hiho
!! html/parsoid
!! end

!! test
2. Template wrapping shouldn't ignore fostered content
!! options
parsoid=wt2wt
!! wikitext
{|
{{tr}}
{{1x|
 }}

hiho
!! html/parsoid
!! end

!!test
Support <object> element with .data attribute
!!options
parsoid=html2wt
!! html/parsoid
<object data="test.swf"></object>
!! wikitext
<object data="test.swf"></object>
!!end

!! test
T72867: Don't block XML namespace declaration
!! wikitext
<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">MediaWiki</span>
!! html/php
<p><span xmlns:dct="http&#58;//purl.org/dc/terms/" property="dct:title">MediaWiki</span>
</p>
!! html/parsoid
<p><span xmlns:dct="http://purl.org/dc/terms/" data-x-property="dct:title" data-parsoid='{"stx":"html"}'>MediaWiki</span></p>
!! end

# -----------------------------------------------------------------
# The following section of tests are primarily to spec requirements
# around Parsoid's serialization (old, new, edited content)
#
# All these tests are marked Parsoid html2wt and html2html only
# ----------------------------------------------------------------

!! test
Ignore rel attribute in a-tags during serialization to url-links
!! options
parsoid=html2wt
!! html/parsoid
<a href='http://en.wikipedia.org/wiki/Foobar'>http://en.wikipedia.org/wiki/Foobar</a>
<a href='http://en.wikipedia.org/wiki/Foobar' rel='mw:ExtLink'>http://en.wikipedia.org/wiki/Foobar</a>
<a href='http://en.wikipedia.org/wiki/Foobar' rel='mw:WikiLink'>http://en.wikipedia.org/wiki/Foobar</a>
!! wikitext
http://en.wikipedia.org/wiki/Foobar
http://en.wikipedia.org/wiki/Foobar
http://en.wikipedia.org/wiki/Foobar
!! end

# 'mi' is a localinterwiki prefix as well as a language
!! test
Serialize interwiki links pointing to the current wiki as plain wiki links (T67869)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.org/wiki/Foo">Foo</a></p>
!! wikitext
[[Foo]]
!! end

!! test
Parsoid should accept interwiki shortcuts
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel='mw:WikiLink' href='./fr:Foo'>Foo</a>
<a rel='mw:ExtLink' href='./fr:Foo'>Foo</a>
<a href='./fr:Foo'>Foo</a></p>
<p><a rel='mw:WikiLink' href='fr%3AFoo'>Foo</a>
<a rel='mw:ExtLink' href='fr%3AFoo'>Foo</a>
<a href='fr%3AFoo'>Foo</a></p>
<p><a href='FR%3AFoo'>Foo</a>
<a href='./FR:Foo'>Foo</a></p>
!! wikitext
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]

[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]

[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
!! end

!! test
Parsoid should not accept invalid interwiki shortcuts
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel='mw:WikiLink' href='news:Foo'>Foo</a>
<a rel='mw:ExtLink' href='news:Foo'>Foo</a>
<a href='news:Foo'>Foo</a></p>
!! wikitext
[news:Foo Foo]
[news:Foo Foo]
[news:Foo Foo]
!! end

# See T93839
!! test
New wikilinks should be serialized properly
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{}'>Foo</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a>
<a href="//en.wikipedia.org/wiki/Foo">//en.wikipedia.org/wiki/Foo</a>
<a href="http://en.wikipedia.org/wiki/Foo">http://en.wikipedia.org/wiki/Foo</a>
<a href="//en.wikipedia.org/wiki/Foo_bar">//en.wikipedia.org/wiki/Foo bar</a>
!! wikitext
[[Foo]]
[[Foo]]
[[:en:Foo|//en.wikipedia.org/wiki/Foo]]
http://en.wikipedia.org/wiki/Foo
[[:en:Foo_bar|//en.wikipedia.org/wiki/Foo bar]]
!! end

!! test
New wiki links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="Foo bar">Foo_bar</a>
<a rel="mw:WikiLink" href="./Toxine_bact%C3%A9rienne">Toxine bactérienne</a>
!! wikitext
[[Foo_bar]]
[[Foo_bar]]
[[Foo_bar]]
[[Toxine bactérienne]]
!! end

!! test
New wiki links (content string variations)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="./Foo_bar">Foo bar</a>
<a rel="mw:WikiLink" href="./Foo_bar">./Foo_bar</a>
!! wikitext
[[Foo_bar]]
[[Foo bar]]
[[Foo_bar|./Foo_bar]]
!! end

!! test
New category links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Toxine_bactérienne" />
<link rel="mw:PageProp/Category" href="./Category:Toxine_bact%C3%A9rienne" />
<link rel="mw:PageProp/Category" href="Category:Toxine_bact%C3%A9rienne" />
!! wikitext
[[Category:Toxine bactérienne]]
[[Category:Toxine bactérienne]]
[[Category:Toxine bactérienne]]
!! end

!! test
New sol transparent links don't need indent-pre nowiki protection
!! options
parsoid=html2wt
language=de
!! html/parsoid
         <link rel="mw:PageProp/redirect" href="./Main_Page">
<!-- this is good  -->    <link rel="mw:PageProp/Category" href="./Category:Good" />
<!-- this is great -->    <link rel="mw:PageProp/Category" href="./Kategorie:Great" />
!! wikitext
         #WEITERLEITUNG [[Main Page]]
<!-- this is good  -->    [[Category:Good]]
<!-- this is great -->    [[Kategorie:Great]]
!! end

!! test
New interlanguage links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine bactérienne" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine_bactérienne" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine_bact%C3%A9rienne" />
!! wikitext
[[es:Toxine bactérienne]]
[[es:Toxine_bactérienne]]
[[es:Toxine_bactérienne]]
!! end

# Regression test for T219023
!! test
Emit simple non-piped link where possible
!! options
parsoid=html2wt
!! html/parsoid
<a rel='mw:WikiLink' href='./VisualEditor'>VisualEditor</a>
<a rel='mw:WikiLink' href='./VisualEditor'>visualEditor</a>
<a rel='mw:WikiLink' href='./VisualEditor link'>VisualEditor link</a>
<a rel='mw:WikiLink' href='./VisualEditor link'>visualEditor link</a>
!! wikitext
[[VisualEditor]]
[[visualEditor]]
[[VisualEditor link]]
[[visualEditor link]]
!! end

!! test
Lists: Serialize correctly even when list content is wrapped in p-tags (like VE does)
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li><p>foo</p></li>
</ul>
!! wikitext
* foo
!! end

!! test
Lists: Serialize correctly even when list tags has unneeded whitespace between tags
!! options
parsoid=html2wt
!! html/parsoid
<ul> <li>foo</li></ul>
!! wikitext
* foo
!! end

!! test
Don't strip leading whitespace when handling indent-pre suppressing tags
!! options
parsoid=html2wt
!! html/parsoid
<table>
  <tr><td> indented row</td></tr>
</table>
<blockquote><p>
 <b>This is very bold of you!</b>
</p>
<table><tr><td>
 indented cell (no pre-wrapping!)
</td></tr></table>
</blockquote>
<p>foo</p>
 <div>bar</div>
!! wikitext
{|
  | indented row
|}
<blockquote>
 '''This is very bold of you!'''

{|
|
 indented cell (no pre-wrapping!)
|}
</blockquote>
foo
 <div>bar</div>
!! end

!! test
Strip 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
</span>bar2

<div>foo</div>
<span>bar</span>

<div>
<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
Headings: Force sol-transparent links and behavior switches to serialize before/after
!! options
parsoid={
  "modes": ["html2wt"]
}
!! 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"]
}
!! html/parsoid
<h2><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo [[Category:Foo]]"}},"i":0}}]}'>foo </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" /></h2>
!! wikitext
== {{1x|foo [[Category:Foo]]}} ==
!! end

!! test
Parsoid: Serialize positional parameters with = in them as named parameter
!! options
parsoid=html2wt
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"}},"i":0}}]}'>foo</p>

<p about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"}, "2":{"wt":"bar"}},"i":0}}]}'>foo</p>

<!--Orig params with data-parsoid has heuristics for handling = chars-->
<!--FIXME: But maybe the heuristic needs fixing to apply to new params as well-->
<p data-parsoid='{"pi":[[{"k":"1"},{"k":"2"}]]}' about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"},"2":{"wt":"bar"}},"i":0}}]}'>foo</p>
!! wikitext
{{1x|1=f=oo}}

{{1x|1=f=oo|2=bar}}

<!--Orig params with data-parsoid has heuristics for handling = chars-->
<!--FIXME: But maybe the heuristic needs fixing to apply to new params as well-->
{{1x|<nowiki>f=oo</nowiki>|bar}}
!! end

!! test
Parsoid: Serialize positional parameters with = in extlink as named parameter
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://stuff?is=ok" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"http://stuff?is=ok"}},"i":0}}]}'>http://stuff?is=ok</a></p>
!! wikitext
{{1x|1=http://stuff?is=ok}}
!! end

!! test
Parsoid: Correctly serialize block-node children when they are a combination of text and p-nodes
!! options
parsoid=html2wt
!! html/parsoid
<div>a<p>b</p></div>
<div>a
<p>b</p></div>
<div>
a
<p>b</p></div>
!! wikitext
<div>a
b
</div>
<div>a
b
</div>
<div>
a

b
</div>
!! end

!! test
Substrings resembling wikitext in hrefs should not get nowiki escapes
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo''bar''baz">Foo''bar''baz</a>
!! wikitext
[[Foo''bar''baz]]
!! end

!! test
Enforce single-line context in the serializer
!! options
parsoid=html2wt
!! html/parsoid
<h2>testing
123</h2>

<h2> hi <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bogus","href":"./Template:Bogus"},"params":{"1":{"wt":"there\nyou"}},"i":0}}]}'>there</span><span about="#mwt1">
</span><span about="#mwt1">you</span> </h2>

<h2> foo <span about="#mwt2" typeof="mw:Extension/spantag" data-mw='{"name":"spantag","body":{"extsrc":"hello\nthere"},"attrs":{}}'>hello
there</span> </h2>

<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 <spantag>hello
there</spantag> ==

* asd sdf

* foo bar baz
* foo '''bar''' baz

; hi ho : hi ho

: {|
| ha
ha
ha
|}
!! end

# Note that core parser doesn't like newlines in wikilinks in headings.
# But, Parsoid handles it just fine. We'll consider this acceptable divergence.
# We can change behavior if this becomes a real problem (ex: VE users start
# adding newlines in links in headings which then breaks rendering when rendered
# outside of Parsoid, or breaks section editing code). Eventually Parsoid will
# core parser everywhere and this inconsistency will go away.
!! test
Ignore single-line context for wikilinks
!! options
parsoid=html2wt
!! html/parsoid
<ul><li><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">
bar</a></li></ul>
<h2><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">
bar</a></h2>
<ul><li><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">bar
<span style="background-color:green;
color:blue" data-parsoid='{"stx":"html"}'>x</span></a></li></ul>
!! wikitext
* [[Foo|
bar]]

== [[Foo|
bar]] ==

* [[Foo|bar
<span style="background-color:green;
color:blue">x</span>]]
!! end

!! test
Selser: Ignore single-line context for wikilinks
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
     [ "ul > li ", "append", "<ul><li>foo</li></ul>" ]
  ]
}
!! wikitext
* [[Foo|
bar]]
!! wikitext/edited
* [[Foo|
bar]]
** foo
!! end

!! test
Serialize new displayspace spans
!! options
parsoid=html2wt
!! html/parsoid
<p>foo<span typeof="mw:DisplaySpace"> </span>: bar</p>

<p>foo<span typeof="mw:DisplaySpace"> </span>: bar</p>

<p><span typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"foo : bar"}}'>foo<span typeof="mw:DisplaySpace"> </span>: bar</span>ok</p>

<a href="http://example.com">«<span typeof="mw:DisplaySpace">&nsbp;</span>Tour Eiffel<span typeof="mw:DisplaySpace">&nsbp;</span>»</a>

Hello<span typeof="mw:DisplaySpace">&nbsp;</span>World!

<ul>
<li><span typeof="mw:DisplaySpace">&nbsp;</span>Foo</li>
</ul>
!! wikitext
foo : bar

foo : bar

<spantag>foo : bar</spantag>ok

[http://example.com « Tour Eiffel »]

Hello World!

*  Foo
!! end


#-----------------------
# Tag minimization tests
#-----------------------

!! test
1. I/B quote minimization: wikitext-only tags should be combined
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i>B</i></p>
<p><b>A</b><b>B</b></p>
<p><i>A</i><b><i>B</i></b></p>
<p><b>A</b><i><b>B</b></i></p>
<p><b>A</b><i><b>B</b><b>C</b></i><b>D</b></p>
<p><i><b>A</b></i><i><b>B</b></i></p>
<p><i><b>A</b></i><b><i>B</i></b></p>
<p><b><i>A</i></b><i><b>B</b></i></p>
!! wikitext
''AB''

'''AB'''

''A'''B'''''

'''A''B'''''

'''A''BC''D'''

'''''AB'''''

'''''AB'''''

'''''AB'''''
!! end

!! test
2. I/B quote minimization: wikitext and html tags should not be combined
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i data-parsoid='{"stx":"html"}'>B</i></p>
<p><i>A</i><b><i data-parsoid='{"stx":"html"}'>B</i></b></p>
!! wikitext
''A''<i>B</i>

''A''<nowiki/>'''<i>B</i>'''
!! end

!! test
3. I/B quote minimization: templated content stops minimization
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&#39;&#39;B&#39;&#39;"}},"i":0}}]}'>B</i>
<p><i>A</i><b about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&#39;&#39;&#39;&#39;&#39;B&#39;&#39;&#39;&#39;&#39;"}},"i":0}}]}'><i>B</i></b>
!! wikitext
''A''{{1x|''B''}}

''A''{{1x|'''''B'''''}}
!! end

!! test
4. I/B quote minimization: new content should be mimimized with adjacent old content
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i>B</i></p>
<p><b>A</b><b>B</b></p>
<p><i>A</i><b><i>B</i></b></p>
!! wikitext
''AB''

'''AB'''

''A'''B'''''
!! end

!! test
5a. Merge adjacent quote nodes if they've been edited
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["p", "contents", "remove", ":contains('b')"]
  ]
}
!! wikitext
''a''b''c''
!! wikitext/edited
''ac''
!! end

!! test
5b. Merge adjacent quote nodes if they've been edited
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["#x", "remove"]
  ]
}
!! wikitext
''a''<span id="x">b</span>''c''
!! wikitext/edited
''ac''
!! end

!! test
1. Merge adjacent link nodes as long as at least one element is new
!! options
parsoid={
  "modes": ["html2wt"]
}
!! 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"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i>Foot</i></a><a rel="mw:WikiLink" href="./Football"><i>ball</i></a>
!! wikitext
''[[Football]]''
!! end

!! test
1. Move format tags outside of WikiLink
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i>Football</i></a>
<a rel="mw:WikiLink" href="./Football"><i><b>Football</b></i></a>
<a rel="mw:WikiLink" href="./Football"><u><i><b>Football</b></i></u></a>
!! wikitext
''[[Football]]''
'''''[[Football]]'''''
<u>'''''[[Football]]'''''</u>
!! end

!! test
2. Move format tags outside of WikiLink with mergable A tags
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i><b>Foot</b></i></a><a rel="mw:WikiLink" href="./Football"><i><b>ball</b></i></a>
!! wikitext
'''''[[Football]]'''''
!! end

!! test
3. Move format tags outside of WikiLink while preserving formats already outside WikiLink
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<font color="red"><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><u><b>Foo</b></u></a></font>
!! wikitext
<font color="red"><u>'''[[Foo]]'''</u></font>
!! end

!! test
4. Do not move format tags outside of WikiLink which includes attributes color, style and class
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><font color="red">Foo</font></a>
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><span style="color: blue; font-size: 46px;">Foo></span></a>
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><span class="Bar">Foo</span></a>
!! wikitext
[[Foo|<font color="red">Foo</font>]]
[[Foo|<span style="color: blue; font-size: 46px;">Foo></span>]]
[[Foo|<span class="Bar">Foo</span>]]
!! end

!! test
5. T194083 Regression test: Manual edit test to move format tags outside wikilinks
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["a", "html", "<i>Foo</i>"]
  ]
}
!! wikitext
[[Foo]]
!! wikitext/edited
''[[Foo]]''
!! end

!! test
6. Regression test: Manual edit test to ensure diff markers are not lost
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["i", "wrap", "<a href='./Foo' rel='mw:WikiLink'></a>"]
  ]
}
!! wikitext
''Foo''
!! wikitext/edited
''[[Foo]]''
!! end

!! test
7. T194083 Regression test: Manual edit test to ensure nested diff markers aren't inserted
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["div", "after", "\n<p><a href='./Foo' rel='mw:WikiLink'>Foo </a>, placeholder</p>"]
  ]
}
!! wikitext
<div>placeholder</div>
!! wikitext/edited
<div>placeholder</div>
[[Foo]] , placeholder
!! end

## No sort-key or templated sort-key
!! test
T192913 Regression test: 1. html2wt of links should not trip on parser functions found in target
!! options
parsoid
!! wikitext
[[Category:Bugs-{{#if:blah|Regression|None}}]]
[[Category:Bugs-{{#if:blah|Regression|None}}|{{#if:blah|2020|None}}-#fragment]]
!! html/parsoid
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}]]}'/>
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression#2020-%23fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}],[{"txt":"mw:sortKey"},{"html":"&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"2020\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>2020&lt;/span>-#fragment"}]]}'/>
!! end

## Untemplated sort-key (wt2html data-mw is missing sort-key information!)
!! test
T192913 Regression test: 2. html2wt of links should not trip on parser functions found in target (2)
!! options
parsoid
!! wikitext
[[Category:Bugs-{{#if:blah|Regression|None}}|fragment]]
[[Category:Bugs-{{#if:blah|Regression|None}}-{{#if:blah|2020|None}}|fragment]]
!! html/parsoid
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression#fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}]]}'/>
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression-2020#fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"2020\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>2020&lt;/span>"}]]}'/>
!! end

#------------------------------
# End of tag minimization tests
#------------------------------

!!test
T56262: New entities
!! options
parsoid=html2wt
!! html/parsoid
<span typeof="mw:Entity">&nbsp;</span>
!! wikitext
&nbsp;
!! end

!! 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
WTS of autolinks with trailing/surrounding context
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="http://cscott.net">http://cscott.net</a><b>foo</b></p>
<p><a href="http://cscott.net">http://cscott.net</a><b data-parsoid='{"stx":"html"}'>foo</b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a></b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a> </b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a>x</b></p>
<p><a href="http://cscott.net">http://cscott.net</a>x</p>
!! wikitext
http://cscott.net'''foo'''

http://cscott.net<b>foo</b>

'''http://cscott.net'''

'''http://cscott.net '''

'''http://cscott.net<nowiki/>x'''

http://cscott.net<nowiki/>x
!! end

!! test
WTS of autolinks with nowikis (round-trip)
!! wikitext
x<nowiki/>http://cscott.net<nowiki/>x
!! html/parsoid
<p>x<a rel="mw:ExtLink" href="http://cscott.net" class="external free">http://cscott.net</a>x</p>
!! end

# this is the "easy" test because it leaves in place all the
# data-parsoid information indicating this is an autolink
!! test
WTS of autolinks with escapes (editing)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "span", "remove" ]
  ]
}
!! wikitext
x<nowiki/>http://cscott.net<nowiki/>x
!! wikitext/edited
x<nowiki/>http://cscott.net<nowiki/>x
!! end

!! test
WTS of edited autolink-like text (T103364)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "span[typeof]", "removeAttr", "typeof" ]
  ]
}
!! wikitext
Not a link: <nowiki>http://example.com</nowiki>.
!! wikitext/edited
Not a link: <span><nowiki>http://example.com</nowiki></span>.
!! end

!! test
WTS of newly-authored autolink-like text (T103364)
!! options
parsoid=html2wt
!! html/parsoid
<p>http://example.com is not a link.</p>
!! wikitext
<nowiki>http://example.com</nowiki> is not a link.
!! end

!! test
WTS of autolink-like text after an autolink (T108563)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a> http://example.com is not a link.</p>
!! wikitext
http://example.com <nowiki>http://example.com</nowiki> is not a link.
!! end

!! test
WTS of an autolink surrounded by square brackets (T220018)
!! options
parsoid=html2wt
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>]</p>
!! wikitext
<nowiki>[</nowiki>http://example.com]
!! end

!! test
WTS of edited autolink surrounded by square brackets (T220018)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "a", "before", "[" ],
    [ "a", "after", "]" ]
  ]
}
!! wikitext
http://example.com
!! wikitext/edited
<nowiki>[</nowiki>http://example.com]
!! end

!! test
WTS of an external link surrounded by square brackets (T220018)
!! options
parsoid=html2wt
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="http://example.com">foo</a>]</p>
!! wikitext
<nowiki>[</nowiki>[http://example.com foo]]
!! end

!! test
WTS of edited external link surrounded by square brackets (T220018)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "a", "before", "[" ],
    [ "a", "after", "]" ]
  ]
}
!! wikitext
[http://example.com foo]
!! wikitext/edited
<nowiki>[</nowiki>[http://example.com foo]]
!! end

!! test
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
<table>
<tbody><tr>
<th>-
</th>
<th>-
</th></tr>
<tr>
<td>-
</td>
<td>- 
</td></tr>
<tr>
<td><small>-</small>
</td>
<td><br />
<p>-
</p>
</td>
<td><br />-
</td></tr></tbody></table>
!! end

!! test
T149209: WTS: Handle newlines in table cells properly
!! options
parsoid=html2wt
!! html/parsoid
<table>
<tbody>
<tr><td>a
b
</td><td data-parsoid='{"stx":"row"}'>c</td></tr>
<tr><td><p>x</p>
</td><td data-parsoid='{"stx":"row", "startTagSrc": "{{!}}{{!}}"}'>y</td></tr>
</tbody></table>
<table>
<tbody>
<tr><th>a
b
</th><th data-parsoid='{"stx":"row"}'>c</th></tr>
<tr><th><p>x</h>
</th><th data-parsoid='{"stx":"row"}'>y</th></tr>
</tbody></table>
!! wikitext
{|
|a
b
|c
|-
|x
{{!}}y
|}
{|
!a
b
!c
|-
!x
!y
|}
!! end

!! test
T149209: Selser: Handle newlines in table cells properly
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#h1", "html", "a\nb\n" ],
    [ "#h2", "html", "a\nb\n" ],
    [ "#c1", "html", "a\nb\n" ],
    [ "#c2", "html", "<p>a</p>" ],
    [ "#c3", "html", "<p>a</p>" ],
    [ "#c4", "html", "edit-me<p>a</p>" ]
  ]
}
!! wikitext
{|
! id="h1" |edit-me!!1
|-
! id="h2" |edit-me||2
|-
| id="c1" |edit-me||3
|-
| id="c2" |edit-me||4
|-
| id="c3" |edit-me||p||q||r
|-
| id="c4" |edit-me||p||q||r
|}
!! wikitext/edited
{|
! id="h1" |a
b
!1
|-
! id="h2" |a
b
!2
|-
| id="c1" |a
b
|3
|-
| id="c2" |a
|4
|-
| id="c3" |a
|p||q||r
|-
| id="c4" |edit-me
a
|p||q||r
|}
!! end

!! test
HTML id attribute with Parsoid-like element ids should not be serialized to wikitext
!! options
parsoid=html2wt
!! html/parsoid
<table id='mwAb'>
<td id='mwAc'>foo</td>
<td id='serialize-this'>bar</td>
</table>
!! wikitext
{|
|foo
| id="serialize-this" |bar
|}
!! end

!! test
Parsoid-like element ids should not be serialized to wikitext unless shadowed
!! options
parsoid=html2wt
!! html/parsoid
<div id="mwAQ" data-parsoid='{"stx":"html","a":{"id":"mwAQ"},"sa":{"id":"hello"}}'>ok</div>
!! wikitext
<div id="hello">ok</div>
!! end

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

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

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

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

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

# Nested list should be inside <li>, that is
# <ul><li>foo<ul>..</ul></li></ul> instead of
# <ul><li>foo</li><ul>..</ul></ul>
# See https://stackoverflow.com/questions/5899337/proper-way-to-make-html-nested-list
!! test
Wikitext lists can be nested inside HTML lists
!! options
parsoid=html2wt
!! html/parsoid
<ul data-parsoid='{"stx": "html"}'>
<li data-parsoid='{"stx": "html"}'>a
<ul><li>b</li></ul>
</li>
</ul>

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

<ul>
<li>x
* y
</li>
</ul>
!! html/php
<ul>
<li>a
<ul><li>b</li></ul>
</li>
</ul>
<ul>
<li>x
<ul><li>y</li></ul>
</li>
</ul>
!! end

!! test
WTS change modes
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "#xyz", "before", "<b>before</b> stuff " ],
    [ "#xyz", "after", " stuff <i>after</i>" ],
    [ "#xyz", "html", "x <b>y</b> z" ]
  ]
}
!! wikitext
<span id="xyz">hello</span>
!! wikitext/edited
'''before''' stuff <span id="xyz">x '''y''' z</span> stuff ''after''
!! end

!! test
Never serialize a-tag as html, regardless of what data-parsoid has to say
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"html"}'>Foo</a>
!! wikitext
[[Foo]]
!! end

## SSS FIXME: This is broken output nevertheless.
## What might be a reasonable non-broken output for this?
## This is an edge case unlikely to be seen in production
## that I am not wasting more time on this right now.
!! test
Never serialize a-tag as html, no matter what attributes it has
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a bad='true' href='http://boo.org'><img src='http://boohoo.org' /></a>
!! wikitext
[http://boo.org http://boohoo.org]
!! end

# Misnested is an indication that selser can reuse the source but these have
# shown to sneak through on occasion. See T101768.
# The original wikitext here is: [http://test.com [[one]] two three]
!! test
Strip span tags added to mark misnested links
!! options
parsoid=html2wt
!! html/parsoid
<p data-parsoid='{}'><a rel="mw:ExtLink" href="http://test.com"></a><a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"simple","a":{"href":"./One"},"sa":{"href":"one"},"misnested":true}'>one</a><span data-parsoid='{"misnested":true}'> two three</span></p>
!! wikitext
[http://test.com][[one]] two three
!! end

!! test
Catch regression when unpacking misnested links
!! options
parsoid=wt2html
!! wikitext
{{1x|hi}}[http://example.com [[ho]]]
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"hi"}},"i":0}}]}'>hi</span><a rel="mw:ExtLink nofollow" href="http://example.com" class="external autonumber"></a><a rel="mw:WikiLink" href="./Ho" title="Ho" data-parsoid='{"stx":"simple","a":{"href":"./Ho"},"sa":{"href":"ho"},"misnested":true}'>ho</a></p>
!! end

!! test
Use data-parsoid.firstWikitextNode to compute newline constraints for template content
!! options
parsoid=html2wt
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span><table about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"a":{"{{1x|c\n{{!}}d\n}}":null},"sa":{"{{1x|c\n{{!}}d\n}}":""},"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"c\n{{!}}d\n"}},"i":0}},"\n|}"]}'>
<tbody><tr><td>d
</td></tr>
</tbody></table>
!! wikitext
{{1x|a}}
{|{{1x|c
{{!}}d
}}
|}
!! end

## This test verifies the presence and computation of this attribute indirectly
## by making an edit and ensuring that the serialization is correct (which it would be
## only if firstWikitextNode is properly set).
!! test
data-parsoid.firstWikitextNode should be computed properly in the presence of fostered content
!! options
parsoid= {
  "modes": ["wt2wt"],
  "changes": [
    [ "div#x", "remove" ],
    [ "div", "before", "<div>new</div>" ]
  ]
}
!! wikitext
<div id="x">foo</div>
{|
{{1x|<div>boo</div>
{{!}}b}}
|c
|}
!! wikitext/edited

<div>new</div>
{|
{{1x|<div>boo</div>
{{!}}b}}
|c
|}
!! end

# --------------------------------------------
# Tests spec'ing wikitext serialization norms |
# --------------------------------------------

!! test
Serialize multi-line indent-pre starting with wikitext syntax
!! options
parsoid=html2wt
!! html/parsoid
<pre>* 1
** 2
* 3</pre>
!! wikitext
 * 1
 ** 2
 * 3
!! end

!! test
1. Categories should always be serialized on their own line
!! options
parsoid=html2wt
!! html/parsoid
foo<link rel="mw:PageProp/Category" href="./Category:Foo">bar
!! wikitext
foo
[[Category:Foo]]
bar
!! end

!! test
2. Categories that are part of templates should not introduce a line break
!! wikitext
foo {{1x|<span>bar</span> [[Category:baz]]}} bar
!! html/parsoid
<p>foo <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;span>bar&lt;/span> [[Category:baz]]"}},"i":0}}]}'>bar</span><span about="#mwt1"> </span><link rel="mw:PageProp/Category" href="./Category:Baz" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:baz"}}'/> bar</p>
!! end

# Careful while editing these next 2 tests. There are \u200f characters
# before and after the <link> tags in the HTML and following some
# of the categories in wikitext
# Do not remove these characters in edits.
#
# As part of the serialization, these bidi characters will get stripped.
!! test
RTL (\u200f) and LTR (\u200e) markers around category tags should be stripped
!! options
parsoid={
  "modes": ["html2wt"]
}
!! 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"]
}
!! 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"]
}
!! 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"]
}
!! html/parsoid
<h2></h2>
!! wikitext
!! end

!! test
2. Headings: suppress empty headings on edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
==<span id="x">foo</span>==
!! wikitext/edited
!! end

!! test
Headings: Replace <br/> with a single whitespace char
!! options
parsoid={
  "modes": ["html2wt"]
}
!! 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
1. WT Quote Tags: suppress newly created empty style tags
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<i></i><b></b>
!! wikitext
!! end

!! test
2. WT Quote Tags: suppress empty style tags on edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
'''<span id="x">foo</span>'''
!! wikitext/edited
!! end

!! test
1. Anchors: suppress newly created empty anchors
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Test" title="Test"></a>
!! wikitext
!! end

!! test
2. Anchors: suppress empty anchors on edits
!! options
parsoid={
  "modes": ["selser"],
  "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"]
}
!! 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"],
  "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"],
  "changes": [
    [ "h1", "before", "<i></i>"]
  ]
}
!!wikitext
a
= =
b
!!wikitext/edited
a
= =
b
!!end

!! test
1. Multiple normalizations (html2wt)
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<h2><i></i></h2>
<p><a href='Foo' rel='mw:WikiLink'>foo<i></i>
 </a><b><i></i></b>x</p>
!! wikitext

[[foo]]
x
!! end

!! test
2. Multiple normalizations (selser)
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#x", "after", "<h1><i></i></h1>\n<p> bar<b></b></p>"]
  ]
}
!! wikitext
<div id="x">foo</div>
!! wikitext/edited
<div id="x">foo</div>
bar
!! end

!! test
1. Indent Pre Nowiki: suppress whitespace at the start of new paragraph
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<p> hi</p>
<p>    hello</p>
!! wikitext
hi

hello
!! end

!! test
2. Indent Pre Nowiki: suppress whitespace after newlines in new paragraph or table cell
!! options
parsoid={
  "modes": ["html2wt"]
}
!! 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
3. Indent Pre Nowiki: suppress leading whitespace in edited paragraphs
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "p", "html", " a\n b" ]
  ]
}
!! wikitext
xyz
!! wikitext/edited
a
b
!! end

!! test
New links that end in spaces
!! options
parsoid={
  "modes": ["html2wt"]
}
!! 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"]
}
!! html/parsoid
<table>
<tr><td>a</td></tr>
<tr><td>-</td></tr>
<tr><td>+</td></tr>
<tr><td>}</td></tr>
</table>
!! wikitext
{|
|a
|-
| -
|-
| +
|-
| }
|}
!! end

!! test
2a. Table cells with escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr:first-child td:first-child", "remove"]
  ]
}
!! wikitext
{|
|a||-
|}
!! wikitext/edited
{|
| -
|}
!! end

!! test
2b. Table cells with escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "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
3a. Table cells without escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "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
3b. Table cells without escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "td", "html", "-" ]
  ]
}
!! wikitext
{|
|a||b
|}
!! wikitext/edited
{|
| -||-
|}
!! end

## This tests normalizer's ability to not be tripped by
## comments (and whitespace)
!! test
3c. Table cells without escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "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
3d. Table cells without escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "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
4. font tags without attributes should be dropped
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<font>foo</font>
<font><font>bar</font></font>
<font class="x">boo</font>
!! wikitext
foo
bar
<font class="x">boo</font>
!! end

!! test
Normalize empty paragraphs to HTML form that html2wt expects
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<div>1</div>
<p>a</p><p></p><p>b</p>
<div>2</div>
<p>a</p>
<p></p>
<p>b</p>
<div>3</div>
<p>a</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p>b</p>
<div>4</div>
<p>a</p>
<p></p>
<div>foo</div>
!! wikitext
<div>1</div>
a


b
<div>2</div>
a


b
<div>3</div>
a





b
<div>4</div>
a

<div>foo</div>
!! html/php
<div>1</div>
<p>a
</p><p><br />
b
</p>
<div>2</div>
<p>a
</p><p><br />
b
</p>
<div>3</div>
<p>a
</p><p><br />
</p><p><br />
</p><p>b
</p>
<div>4</div>
<p>a
</p>
<div>foo</div>
!! end

!! test
Templated content should be skipped over by normalization
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SomeTemplate1","href":"./Template:SomeTemplate1"},"params":{"1":{"wt":"boo"}},"i":0}}]}'>foobar</p><p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SomeTemplate2","href":"./Template:SomeTemplate2"},"params":{"1":{"wt":"booboo"}},"i":0}}]}'>foobar</p><span about="#mwt2">
</span><p about="#mwt2"></p><span about="#mwt2">
</span>
!! wikitext
{{SomeTemplate1|boo}}{{SomeTemplate2|booboo}}
!! end

!! test
Escape DOM elements
!! options
parsoid=html2wt
!! html/parsoid
<nowiki><i>foo</i></nowiki>
<noinclude><i>foo</i></noinclude>
<includeonly><i>foo</i></includeonly>
!! wikitext
&lt;nowiki&gt;''foo''&lt;/nowiki&gt;
&lt;noinclude&gt;''foo''&lt;/noinclude&gt;
&lt;includeonly&gt;''foo''&lt;/includeonly&gt;
!! end

!! test
Don't escape pre elements that fail to parse as extension tags
!! wikitext
<pre>closed is extension tag, so everything is <span>text</span></pre>
<pre>unclosed is not, so these are <span>tags</span>
!! html/php
<pre>closed is extension tag, so everything is &lt;span&gt;text&lt;/span&gt;</pre>
<pre>unclosed is not, so these are <span>tags</span></pre>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt3" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"closed is extension tag, so everything is &lt;span>text&lt;/span>"}}'>closed is extension tag, so everything is &lt;span>text&lt;/span></pre>
<pre data-parsoid='{"stx":"html","autoInsertedEnd":true}'>unclosed is not, so these are <span>tags</span></pre>
!! end

!! test
New list is serialized on newlines
!! options
parsoid=html2wt
!! html/parsoid
<p>The quick brown fox jumps over the lazy dog.</p><ul>
<li>Yesterday</li>
<li>Today</li>
<li>Tomorrow</li>
</ul><p>The quick onyx goblin jumps over the lazy dwarf.</p>
!! wikitext
The quick brown fox jumps over the lazy dog.

* Yesterday
* Today
* Tomorrow

The quick onyx goblin jumps over the lazy dwarf.
!! end

!! test
New lists in formatting elements serialized w/o newlines
!! options
parsoid=html2wt
!! html/parsoid
<small>

<ul>
<li>123</li>
</ul>

</small>

<small><ul><li>hi</li></ul></small>
!! wikitext
<small>
* 123
</small>

<small>
* hi
</small>
!! end

!! test
New list in table doesn't need newlines
!! options
parsoid=html2wt
!! html/parsoid
<table><tr><td><ul><li>test</li><li>123</li></td></tr></table>
!! wikitext
{|
|
* test
* 123
|}
!! end

!! test
Newly inserted noinclude tags do not need newlines before/after
!! html/parsoid
<p>a<meta typeof="mw:Includes/NoInclude">b<meta typeof="mw:Includes/NoInclude/End">c</p>
!! wikitext
a<noinclude>b</noinclude>c
!! end

# ---------------------------------------------------
# End of tests spec'ing wikitext serialization norms |
# ---------------------------------------------------

# T104032
!! test
Bare inline nodes not wrapped inside p-tags should be treated as p-wrapped
!! options
parsoid=html2wt
!! html/parsoid
a<p>b</p>
<b>c</b><p>d</p>
<table><tr>
<td>a<p>b</p></td>
<td><b>c</b><p>d</p></td>
</tr></table>
!! wikitext
a

b

'''c'''

d
{|
|a
b
|'''c'''
d
|}
!! end

!! test
Anchor without href scenarios
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a class="bc"></a>
<a class="no">dice</a>
<a name="foo"></a>
!! wikitext

dice
<span name="foo"></span>
!! end

!! test
New transclusion added after a list should be serialized after the list
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>a</li></ul><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>
!! wikitext
* a
{{1x|foo}}
!! end

## FIXME: This test is less useful now that the leading space is normalized away
!! test
Only html p-tag is strong indent pre suppressing
!! options
parsoid=html2wt
!! html/parsoid
<p>test2<span>
 test3
</span></p>
!! wikitext
test2<span>
test3
</span>
!! end

# Clients like VE don't know about this property (T238721)
!! test
T238721: New transclusion without the "i" property for a template part should be handled properly
!! options
parsoid=html2wt
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"}}}]}'>foo</span>
!! wikitext
{{1x}}
!! 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
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
<ul><li>a</li>
<li class="mw-empty-elt"></li>
<li class="mw-empty-elt"></li>
<li>b</li></ul>
!! end

!! test
Empty list item with rendering transparent tag
!! wikitext
{{1x|*hmm
*[[category:123]]}}
!! html/php
<ul><li>hmm</li>
<li class="mw-empty-elt"></li></ul>
!! html/parsoid
<ul about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"*hmm\n*[[category:123]]"}},"i":0}}]}'><li>hmm</li>
<li class="mw-empty-elt"><link rel="mw:PageProp/Category" href="./Category:123"/></li></ul>
!! end

!! test
unclosed internal link XSS (T137264)
!! wikitext
[[#%3Cscript%3Ealert(1)%3C/script%3E|
!! html/php
<p>[[#&lt;script&gt;alert(1)&lt;/script&gt;|
</p>
!! html/parsoid
<p>[[#%3Cscript%3Ealert(1)%3C/script%3E|</p>
!! end

!! test
Validating that <style> isn't eaten by tidy (T167349)
!! options
styletag=1
!! wikitext
<div class="foo">
<style>.foo::before { content: "<foo>"; }</style>
<style data-mw-foobar="baz">.foo::after { content: "<bar>"; }</style>
</div>
!! html/php
<div class="foo">
<style>.foo::before { content: "<foo>"; }</style>
<style data-mw-foobar="baz">.foo::after { content: "<bar>"; }</style>
</div>
!! html/parsoid
<div class="foo">
<style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style>
<style data-x-data-mw-foobar="baz" typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{"data-x-data-mw-foobar":"baz"},"body":{"extsrc":".foo::after { content: \"&lt;bar>\"; }"}}'>.foo::after { content: "<bar>"; }</style>
</div>
!! end

## Right now, Parsoid doesn't de-duplicate style tags.
## So, we shouldn't see link tags that need to bypass the sanitizer.
## In a followup patch, when we de-duplicate style tags and
## introduce link tags, we'll add a hook for link tags in
## the parser test runner script.
!! test
Validating that <style> isn't wrapped in a paragraph (T186965)
!! options
styletag=1
!! wikitext
A style tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph

<style>.foo::before { content: "<foo>"; }</style>

<style>.foo::before { content: "<foo>"; }</style> <link rel="foo" href="bar"/><style>.foo::before { content: "<foo>"; }</style>

But if it's on a line with other content, let it be wrapped.

<style>.foo::before { content: "<foo>"; }</style> bar

foo <style>.foo::before { content: "<foo>"; }</style>

foo <style>.foo::before { content: "<foo>"; }</style> bar

And the same if we have non-paragraph-breaking whitespace

foo
<style>.foo::before { content: "<foo>"; }</style>
bar
!! html/php
<p>A style tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph
</p>
<style>.foo::before { content: "<foo>"; }</style>
<style>.foo::before { content: "<foo>"; }</style> <link rel="foo" href="bar" /><style>.foo::before { content: "<foo>"; }</style>
<p>But if it's on a line with other content, let it be wrapped.
</p><p><style>.foo::before { content: "<foo>"; }</style> bar
</p><p>foo <style>.foo::before { content: "<foo>"; }</style>
</p><p>foo <style>.foo::before { content: "<foo>"; }</style> bar
</p><p>And the same if we have non-paragraph-breaking whitespace
</p><p>foo
<style>.foo::before { content: "<foo>"; }</style>
bar
</p>
!! html/parsoid
<p>A style tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph</p>

<style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style>

<p><style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style> &lt;link rel="foo" href="bar"/><style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style></p>

<p>But if it's on a line with other content, let it be wrapped.</p>

<p><style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style> bar</p>

<p>foo <style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style></p>

<p>foo <style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style> bar</p>

<p>And the same if we have non-paragraph-breaking whitespace</p>

<p>foo
<style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo::before { content: \"&lt;foo>\"; }"}}'>.foo::before { content: "<foo>"; }</style>
bar</p>
!! end

!! test
Validating that <link> isn't wrapped in a paragraph (T186965)
!! options
styletag=1
!! wikitext
A link tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph

<link rel="foo" href="bar"/>

<link rel="foo" href="bar"/> <style>.foo::before { content: "<foo>"; }</style><link rel="foo" href="bar"/>

But if it's on a line with other content, let it be wrapped.

<link rel="foo" href="bar"/> bar

foo <link rel="foo" href="bar"/>

foo <link rel="foo" href="bar"/> bar

And the same if we have non-paragraph-breaking whitespace

foo
<link rel="foo" href="bar"/>
bar
!! html/php
<p>A link tag, by itself or with other style/link tags, shouldn't be wrapped in a paragraph
</p>
<link rel="foo" href="bar" />
<link rel="foo" href="bar" /> <style>.foo::before { content: "<foo>"; }</style><link rel="foo" href="bar" />
<p>But if it's on a line with other content, let it be wrapped.
</p><p><link rel="foo" href="bar" /> bar
</p><p>foo <link rel="foo" href="bar" />
</p><p>foo <link rel="foo" href="bar" /> bar
</p><p>And the same if we have non-paragraph-breaking whitespace
</p><p>foo
<link rel="foo" href="bar" />
bar
</p>
!! end

!! test
Extension returning multiple nodes starting with a style tag roundtrips
!! options
wgRawHtml=1
!! wikitext
<table>
{{1x|<html><style>.hi { color: red; }</style>
</html>}}
<tr><td class="hi">ho</td></tr>
</table>
!! html/parsoid
<p about="#mwt5" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedEnd":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE_html","pi":[[{"k":"1"}]]}' data-mw='{"parts":["&lt;table>\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;html>&lt;style>.hi { color: red; }&lt;/style>\n&lt;/html>"}},"i":0}},"\n&lt;tr>&lt;td class=\"hi\">ho&lt;/td>&lt;/tr>\n&lt;/table>"]}'><style typeof="mw:Extension/html" about="#mwt4" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;style>.hi { color: red; }&lt;/style>\n"}}'>.hi { color: red; }</style><span about="#mwt4">
</span></p><table about="#mwt5" data-parsoid='{"stx":"html"}'>

<tbody><tr><td class="hi">ho</td></tr>
</tbody></table>
!! end

!! test
Decoding of HTML entities in embedded HTML tags
!! wikitext
<table class="1&2&amp;3&amp;amp;4&amp;amp;amp;5"><tr><td>x</td></tr></table>
!! html/php
<table class="1&amp;2&amp;3&amp;amp;4&amp;amp;amp;5"><tbody><tr><td>x</td></tr></tbody></table>
!! html/parsoid
<table class="1&amp;2&amp;3&amp;amp;4&amp;amp;amp;5" data-parsoid='{"stx":"html","a":{"class":"1&amp;2&amp;3&amp;amp;4&amp;amp;amp;5"},"sa":{"class":"1&amp;2&amp;amp;3&amp;amp;amp;4&amp;amp;amp;amp;5"}}'><tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'>x</td></tr></tbody></table>
!! end

!! test
T51672: Test for brackets in attributes of elements in external link texts
!! wikitext
[http://example.com/ link <span title="title with [brackets]">span</span>]
[http://example.com/ link <span title="title with &#91;brackets&#93;">span</span>]

!! html/php
<p><a rel="nofollow" class="external text" href="http://example.com/">link <span title="title with &#91;brackets&#93;">span</span></a>
<a rel="nofollow" class="external text" href="http://example.com/">link <span title="title with &#91;brackets&#93;">span</span></a>
</p>
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com/" class="external text">link <span title="title with [brackets]">span</span></a>
<a rel="mw:ExtLink" href="http://example.com/" class="external text">link <span title="title with [brackets]" data-parsoid='{"stx":"html","a":{"title":"title with [brackets]"},"sa":{"title":"title with &amp;#91;brackets&amp;#93;"}}'>span</span></a></p>
!! end

!! test
T72875: Test for brackets in attributes of elements in internal link texts
!! wikitext
[[Foo|link <span title="title with [[double brackets]]">span</span>]]
[[Foo|link <span title="title with &#91;&#91;double brackets&#93;&#93;">span</span>]]

!! html/php
<p><a href="/wiki/Foo" title="Foo">link <span title="title with &#91;&#91;double brackets&#93;&#93;">span</span></a>
<a href="/wiki/Foo" title="Foo">link <span title="title with &#91;&#91;double brackets&#93;&#93;">span</span></a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo" title="Foo">link <span title="title with [[double brackets]]">span</span></a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">link <span title="title with [[double brackets]]" data-parsoid='{"stx":"html","a":{"title":"title with [[double brackets]]"},"sa":{"title":"title with &amp;#91;&amp;#91;double brackets&amp;#93;&amp;#93;"}}'>span</span></a></p>
!! end

!! test
T199926: html arrow wt: Parsoid sometimes trips up on verticalbar chars in hrefs
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a href="https://stats.wikimedia.org/v2/#/fr.wikipedia.org/reading/page-views-by-country/normal|map|2-Year~2016060100~2018071100|~total">9</a>
<a href="https://stats.wikimedia.org/v2/#/fr.wikipedia.org/reading/page-views-by-country/normal%7Cmap%7C2-Year~2016060100~2018071100%7C~total">10</a>
!! wikitext
[https://stats.wikimedia.org/v2/#/fr.wikipedia.org/reading/page-views-by-country/normal|map|2-Year~2016060100~2018071100|~total 9]
[[stats:v2/#/fr.wikipedia.org/reading/page-views-by-country/normal%7Cmap%7C2-Year~2016060100~2018071100%7C~total|10]]
!! end

!! test
T199926: Hash only interwiki link
!! config
wgFragmentMode=[ "html5" ]
!! wikitext
[[meatball:Test#1/2]]
[[gerrit:#/q/project:mediawiki/services/parsoid|Gerrit]]
!! html/php
<p><a href="http://www.usemod.com/cgi-bin/mb.pl?Test#1.2F2" class="extiw" title="meatball:Test">meatball:Test#1/2</a>
<a href="https://gerrit.wikimedia.org/#/q/project:mediawiki/services/parsoid" class="extiw" title="gerrit:">Gerrit</a>
</p>
!! html/parsoid
<p><a rel="mw:WikiLink/Interwiki" href="http://www.usemod.com/cgi-bin/mb.pl?Test#1.2F2" title="meatball:Test" class="extiw" data-parsoid='{"stx":"simple","a":{"href":"http://www.usemod.com/cgi-bin/mb.pl?Test#1.2F2"},"sa":{"href":"meatball:Test#1/2"},"isIW":true}'>meatball:Test#1/2</a>
<a rel="mw:WikiLink/Interwiki" href="https://gerrit.wikimedia.org/#/q/project:mediawiki/services/parsoid" class="extiw">Gerrit</a></p>
!! end

!! test
T179544: {{anchorencode:}} output should be always usable in links
!! config
wgFragmentMode=[ "html5" ]
!! wikitext
<span id="{{anchorencode:[foo]}}"></span>[[#{{anchorencode:[foo]}}]]
!! html/php
<p><span id="&#91;foo&#93;"></span><a href="#[foo]">#&#91;foo&#93;</a>
</p>
!! html/parsoid
<p><span id="[foo]" about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"id":"[foo]"},"sa":{"id":"{{anchorencode:[foo]}}"}}' data-mw='{"attribs":[[{"txt":"id"},{"html":"&lt;span typeof=\"mw:Transclusion mw:Entity\" about=\"#mwt1\" data-parsoid=&apos;{\"srcContent\":\"[\",\"dsr\":[10,32,null,null],\"pi\":[[]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"anchorencode:[foo]\",\"function\":\"anchorencode\"},\"params\":{},\"i\":0}}]}&apos;>[&lt;/span>&lt;span about=\"#mwt1\" data-parsoid=\"{}\">foo&lt;/span>&lt;span typeof=\"mw:Entity\" about=\"#mwt1\" data-parsoid=&apos;{\"src\":\"&amp;amp;#x5D;\",\"srcContent\":\"]\"}&apos;>]&lt;/span>"}]]}'></span><a typeof="mw:ExpandedAttrs" about="#mwt4" rel="mw:WikiLink" href="./Parser_test#[foo]" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#[foo]"},"sa":{"href":"#{{anchorencode:[foo]}}"}}' data-mw='{"attribs":[[{"txt":"href"},{"html":"#&lt;span typeof=\"mw:Transclusion mw:Entity\" about=\"#mwt3\" data-parsoid=&apos;{\"srcContent\":\"[\",\"dsr\":[44,66,null,null],\"pi\":[[]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"anchorencode:[foo]\",\"function\":\"anchorencode\"},\"params\":{},\"i\":0}}]}&apos;>[&lt;/span>&lt;span about=\"#mwt3\" data-parsoid=\"{}\">foo&lt;/span>&lt;span typeof=\"mw:Entity\" about=\"#mwt3\" data-parsoid=&apos;{\"src\":\"&amp;amp;#x5D;\",\"srcContent\":\"]\"}&apos;>]&lt;/span>"}]]}'>#[foo]</a></p>
!! end
##########################################################################
# Tests demonstrating white-space insensitivity in input wikitext
# for wikitext headings, wikitext list items, and wikitext table captions,
# headings, and cells. HTML versions of the same should preserve whitespace.
##########################################################################
!! test
Trim whitespace in wikitext headings, list items, table captions, headings, and cells
!! options
parsoid={
	"modes": ["wt2html"],
	"preserveIEW": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__NOTOC__
==    <!--c1-->  <!--c2--> Spaces   <!--c3--> <!--c4-->  ==
==		<!--c1-->	<!--c2--> Tabs		<!--c3--><!--c4-->	==
== <!--Headings with fallback ids--> Личная жизнь ==
*     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->
; <!--term to define--> term : <!--term's definition--> definition
{|
|+ <!--c1--> <!--c2--> Table Caption <!--c3--> <!--c4-->
|-
!  <!--c1--> <!--c2--> Table Heading 1 <!--c3--> <!--c4--> !!   Table Heading 2 <!--c5-->
|-
| <!--c1--> <!--c2--> Table Cell 1 <!--c3--> <!--c4--> ||   Table Cell 2 <!--c5-->
|-
| class="foo" || <!--c1--> <!--c2--> Table Cell 3 <!--c3--> <!--c4-->
|-
| <!--c1--> testing [[one|two]] <!--c2--> | <!--c3--> some content
|}
: {|
  |  <!--c1--> <!--c2--> Table Cell 1 <!--c3--> <!--c4--> ||   Table Cell 2 <!--c5-->
  |} foo   <!--c1-->
!! html/php
<div class="mw-heading mw-heading2"><h2 id="Spaces">Spaces</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Spaces">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Tabs">Tabs</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Tabs">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id=".D0.9B.D0.B8.D1.87.D0.BD.D0.B0.D1.8F_.D0.B6.D0.B8.D0.B7.D0.BD.D1.8C">Личная жизнь</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Личная жизнь">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<ul><li>List item</li></ul>
<dl><dt>term</dt>
<dd>definition</dd></dl>
<table>
<caption>Table Caption
</caption>
<tbody><tr>
<th>Table Heading 1</th>
<th>Table Heading 2
</th></tr>
<tr>
<td>Table Cell 1</td>
<td>Table Cell 2
</td></tr>
<tr>
<td>class="foo"</td>
<td>Table Cell 3
</td></tr>
<tr>
<td>testing <a href="/wiki/One" title="One">two</a>  |  some content
</td></tr></tbody></table>
<dl><dd><table>
<tbody><tr>
<td>Table Cell 1</td>
<td>Table Cell 2
</td></tr></tbody></table> foo</dd></dl>
!! html/parsoid
<meta property="mw:PageProp/notoc" data-parsoid='{"src":"__NOTOC__","magicSrc":"__NOTOC__"}'/>
<h2 id="Spaces"><!--c1--><!--c2-->Spaces<!--c3--><!--c4--></h2>
<h2 id="Tabs"><!--c1--><!--c2-->Tabs<!--c3--><!--c4--></h2>
<h2 id="Личная_жизнь"><span id=".D0.9B.D0.B8.D1.87.D0.BD.D0.B0.D1.8F_.D0.B6.D0.B8.D0.B7.D0.BD.D1.8C" typeof="mw:FallbackId"></span><!--Headings with fallback ids-->Личная жизнь</h2>
<ul><li><!--c1--><!--c2-->List item<!--c3--><!--c4--></li></ul>
<dl><dt><!--term to define-->term</dt><dd data-parsoid='{"stx":"row"}'><!--term's definition-->definition</dd></dl>
<table>
<caption><!--c1--><!--c2-->Table Caption<!--c3--><!--c4--></caption>
<tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
<th><!--c1--><!--c2-->Table Heading 1<!--c3--><!--c4--></th><th data-parsoid='{"stx":"row"}'>Table Heading 2<!--c5--></th></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td><!--c1--><!--c2-->Table Cell 1<!--c3--><!--c4--></td><td data-parsoid='{"stx":"row"}'>Table Cell 2<!--c5--></td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td>class="foo"</td><td data-parsoid='{"stx":"row"}'><!--c1--><!--c2-->Table Cell 3<!--c3--><!--c4--></td></tr>
<tr data-parsoid='{"startTagSrc":"|-"}'>
<td><!--c1-->testing <a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"piped","a":{"href":"./One"},"sa":{"href":"one"}}'>two</a> <!--c2--> | <!--c3--> some content</td></tr>
</tbody></table>
<dl><dd><table>
  <tbody><tr data-parsoid='{"autoInsertedStart":true}'><td><!--c1--><!--c2-->Table Cell 1<!--c3--><!--c4--></td><td data-parsoid='{"stx":"row"}'>Table Cell 2 <!--c5-->
  </td></tr></tbody></table> foo<!--c1--></dd></dl>
!! end

# Looks like <caption> is not accepted in HTML
!! test
Do not trim whitespace in HTML headings, list items, table captions, headings, and cells
!! options
parsoid={
	"modes": ["wt2html"],
	"preserveIEW": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__NOTOC__
<h2>    <!--c1-->   <!--c2--> Heading    <!--c3--> <!--c4-->  </h2>
<ul><li>     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->  </li></ul>
<table>
<tr><th> <!--c1--> <!--c2--> Table Heading <!--c3--> <!--c4--> <th></tr>
<tr><td> <!--c1--> <!--c2--> Table Cell <!--c3--> <!--c4--> <th></tr>
</table>
!! html/php
<div class="mw-heading mw-heading2"><h2 id="Heading">        Heading       </h2></div>
<ul><li>          List item    </li></ul>
<table>
<tbody><tr><th>   Table Heading   </th><th></th></tr>
<tr><td>   Table Cell   </td><th></th></tr>
</tbody></table>
!! html/parsoid
<meta property="mw:PageProp/notoc"/>
<h2 id="Heading">    <!--c1-->   <!--c2--> Heading    <!--c3--> <!--c4-->  </h2>
<ul><li>     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->  </li></ul>
<table>
<tbody><tr><th> <!--c1--> <!--c2--> Table Heading <!--c3--> <!--c4--> </th><th></th></tr>
<tr><td> <!--c1--> <!--c2--> Table Cell <!--c3--> <!--c4--> </td><th></th></tr>
</tbody></table>
!! end

!! test
Do not trim whitespace in links and quotes
!! options
parsoid={
	"modes": ["wt2html"],
	"preserveIEW": true
}
!! wikitext
foo ''  <!--c1--> italic <!--c2-->   '' and '''  <!--c3-->  bold  <!--c4-->  '''
[[Foo|  some text  ]]
!! html/php
<p>foo <i>   italic    </i> and <b>    bold    </b>
<a href="/wiki/Foo" title="Foo">  some text  </a>
</p>
!! html/parsoid
<p>foo <i>  <!--c1--> italic <!--c2-->   </i> and <b>  <!--c3-->  bold  <!--c4-->  </b>
<a rel="mw:WikiLink" href="./Foo" title="Foo">  some text  </a></p>
!! end

!! test
Remove p tags surrounding a single element in a figcaption
!! options
parsoid=html2wt
!! wikitext
[[File:Foobar.jpg|right|200x200px|Caption]]
!! html/parsoid
<figure class="mw-halign-right" typeof="mw:File"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="23" width="200"/></a><figcaption><p>Caption</p></figcaption></figure>
!! end

!! test
Selser preserves lack of newline before list and allows newline after the list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "ul", "after", "<p>footer</p>" ]
  ]
}
!! wikitext
header
*foo
*bar
!! wikitext/edited
header
*foo
*bar
footer
!! end

!! test
Selser does not introduce newlines between unedited paragraph preceding the list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr td p:last-child", "empty" ]
  ]
}
!! wikitext
{|
|
header
*foo
*bar
footer
|}
!! wikitext/edited
{|
|
header
*foo
*bar

|}
!! end

!! test
Selser does not introduce newlines between unedited paragraph following the list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr td p:first-child", "empty" ]
  ]
}
!! wikitext
{|
|
header
*foo
*bar
footer
|}
!! wikitext/edited
{|
|
*foo
*bar
footer
|}
!! end

!! test
Remove a list item but do not insert newline above list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
     [ "ul li:last-child", "remove" ]
  ]
}
!! wikitext
header
*foo
*bar
footer
!! wikitext/edited
header
*foo
footer
!! end

!! test
Spaced heading with element
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["#x", "attr", "class", "y"]
  ]
}
!! wikitext
=== hi <span id="x">hi</span> hi ho ===
!! wikitext/edited
=== hi <span id="x" class="y">hi</span> hi ho ===
!! end

!! test
Allow tabindex 0
!! wikitext
<div tabindex="0">A</div>
!! html
<div tabindex="0">A</div>
!! end

!! test
Don't allow tabindex -1
!! options
parsoid=wt2html
!! wikitext
<div tabindex="-1">A</div>
!! html
<div>A</div>
!! end

!! test
Don't Allow tabindex > 0
!! options
parsoid=wt2html
!! wikitext
<div tabindex="3">A</div>
!! html
<div>A</div>
!! end

!! test
aside tag in extension HTML is not p-wrapped (T278565)
!! wikitext
<asidetag></asidetag>This is some article content.
!! html/php
<aside>Some aside content</aside><p>This is some article content.</p>
!! html/parsoid
<aside typeof="mw:Extension/asidetag" data-mw='{"name":"asidetag","attrs":{},"body":{"extsrc":""}}'>Some aside content</aside><p>This is some article content.</p>
!! end

!! test
aside tag is not allowed directly in wikitext (T278565)
!! wikitext
<aside>This aside tag in wikitext should be escaped</aside>
!! html
<p>&lt;aside&gt;This aside tag in wikitext should be escaped&lt;/aside&gt;
</p>
!! end

!! test
Stripped tag in list
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
    ["dd", "append", "ho"]
  ]
}
!! wikitext
:<i>hi</i></b>
!! wikitext/edited
:<i>hi</i></b>ho
!! end

!! test
Misnested link nested in span
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
    ["dd", "append", " ho"]
  ]
}
!! wikitext
: [http://google.com <span>[[Lala]]:</span>ok]-hi
!! wikitext/edited
: [http://google.com <span>[[Lala]]:</span>ok]-hi ho
!! end

## From T290938, wrapper unmodified was prevented due to the auto-inserted end
!! test
Preserve the order invalid attributes
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
    ["div", "append", "ho"]
  ]
}
!! wikitext
<div width="95%" style="border: 3px solid darkblue">hi
!! wikitext/edited
<div width="95%" style="border: 3px solid darkblue">hiho
!! end
