# 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. The test parser
# expects end-of-line markers to be \n and not \r\n.
#
# 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
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

!! article
Foo bar baz
!! text
boo
!! endarticle

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

###
### Basic tests
###

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

!! test
Self-closed tag hooks
!! options
showindicators
!! wikitext
<pre />
<gallery />
<indicator name="something" />
!! html/php
<pre></pre>
<ul class="gallery mw-gallery-traditional">
</ul>
!! metadata
something=
!! 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"}}'/>
!! 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"}]]}' 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
T408631: Invalid templates inside template parameters
!! wikitext
{{1x|{{|foo}}}}
!! 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}}"}},"i":0}}]}'>{{|foo}}</span></p>
!! 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

## We should get rid of this test - it is unclear if this
## is the right thing to do. See discussion in T255007.
!! test
Nowiki and french spacing
!! wikitext
<nowiki>test : 123</nowiki>
!! html/php
<p>test&#160;: 123
</p>
!! html/parsoid
<p><span typeof="mw:Nowiki">test<span typeof="mw:DisplaySpace"> </span>: 123</span></p>
!! end

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

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

!! test
T406391: HTML entities in raw text elements
!! options
wgRawHtml=1
!! wikitext
<html>
<script>console.log("&");</script>
<style>a::before { content: "&"; }</style>
</html>
A normal & should be encoded
!! html/php
<p>
<script>console.log("&");</script>
<style>a::before { content: "&"; }</style>

A normal &amp; should be encoded
</p>
!! html/parsoid
<p><span typeof="mw:Extension/html" about="#mwt2" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"\n&lt;script>console.log(\"&amp;\");&lt;/script>\n&lt;style>a::before { content: \"&amp;\"; }&lt;/style>\n"}}'>
</span><script about="#mwt2">console.log("&");</script><span about="#mwt2">
</span><style about="#mwt2">a::before { content: "&"; }</style><span about="#mwt2">
</span>
A normal &amp; should be encoded</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

# Parsoid differs from core here, but this is expected to be resolved
# by a core-side patch.
!! test
T378404: Don't armor inward-pointing French quotes
!! wikitext
French: These « quotes » should be protected.

Croatian: These »quotes« shouldn't be armored.

Test accented characters: »čć« »žđ« »šç«
!! html/php
<p>French: These «&#160;quotes&#160;» should be protected.
</p><p>Croatian: These »quotes« shouldn't be armored.
</p><p>Test accented characters: »čć« »žđ« »šç«
</p>
!! html/parsoid
<p>French: These «<span typeof="mw:DisplaySpace"> </span>quotes<span typeof="mw:DisplaySpace"> </span>» should be protected.</p>
<p>Croatian: These »quotes« shouldn't be armored.</p>
<p>Test accented characters: »čć« »žđ« »šç«</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-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

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

<span 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}}]}'>
</span><ul about="#mwt8"><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 nofollow" href="http://example.com" about="#mwt1" 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 nofollow" 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|b</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 nofollow" href="http://example.org/index.php?title=Parser_test&amp;action=edit" about="#mwt1" 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

!! 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 nofollow" href="http://example.com" class="external text">text<i data-parsoid='{"autoInsertedEnd":true}'></i></a></i>
<a rel="mw:ExtLink nofollow" 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 nofollow" href="http://example.com" class="external text">in italic<i data-parsoid='{"autoInsertedEnd":true}'></i></a></i>
<i>Something <a rel="mw:ExtLink nofollow" 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 nofollow" 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
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

!! 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
Incorrectly 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-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><li about="#mwt3" 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>
!! end

!! test
List interrupted by empty line or heading
!! wikitext
*foo

**bar
==A heading==
*Another list item
!! html
<ul><li>foo</li></ul>
<ul><li><ul><li>bar</li></ul></li></ul>
<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
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><li about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bullet","href":"./Template:Bullet"},"params":{},"i":0}}]}'>Bar</li></ul>
!! end

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

!! test
Unbalanced closing block tags break a list
!! wikitext
<div>
*a</div><div>
*b</div>
!! html/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

# T390629: category used to be moved outside of the <body>!
!! test
4. Category at the end of a bare <li> list item
!! options
parsoid=wt2html
!! wikitext
<li>Broken list
== Section ==
* Proper list

[[Category:Foo]]
!! html/php
<li>Broken list
<div class="mw-heading mw-heading2"><h2 id="Section">Section</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: Section">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<ul><li>Proper list</li></ul></li>
!! html/parsoid
<li>Broken list
<h2 id="Section">Section</h2>
<ul>
<li>Proper list</li>
</ul>
<link rel="mw:PageProp/Category" href="./Category:Foo"/></li>
!! 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

!! 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+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!
!! 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
<p>{{1{{2<span about="#mwt5" typeof="mw:Param" data-mw='{"parts":[{"templatearg":{"target":{"wt":"3"},"params":{},"i":0}}]}'>{{{3}}}</span>|4=5}}}}</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><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>
!! 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/php
<table>

<tbody><tr>
<td>A
</td></tr>
</tbody></table>
!! html/parsoid
<table about="#mwt1" typeof="mw:ExpandedAttrs" data-parsoid='{"a":{"&lt;noinclude>":null},"sa":{"&lt;noinclude>":""}}' data-mw='{"attribs":[[{"txt":"","html":"&lt;meta typeof=\"mw:Includes/NoInclude\" data-parsoid=&apos;{\"src\":\"&amp;lt;noinclude>\"}&apos;/>"},{"html":""}]]}'>
<tbody><tr about="#mwt2" typeof="mw:ExpandedAttrs" data-parsoid='{"startTagSrc":"|-","a":{"&lt;noinclude>":null},"sa":{"&lt;noinclude>":""}}' data-mw='{"attribs":[[{"txt":"","html":"&lt;meta typeof=\"mw:Includes/NoInclude\" data-parsoid=&apos;{\"src\":\"&amp;lt;noinclude>\"}&apos;/>"},{"html":""}]]}'>
<td>A</td></tr>
<tr class="mw-empty-elt" data-parsoid='{"startTagSrc":"|-","a":{"&lt;/noinclude>":null},"sa":{"&lt;/noinclude>":""}}'></tr>
</tbody></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
!! 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
!! 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

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

###
### 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 class="mw-empty-elt" 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
<span class="mw-empty-elt" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;tr>&lt;/tr>"}},"i":0}}]}'></span>
!! 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" loading="lazy" 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
<span class="mw-empty-elt" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[]]}' 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|}"]}'><link rel="mw:PageProp/Category" href="./Category:Fostered_Content"/></span><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\":[[]]}&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
<span class="mw-empty-elt" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"autoInsertedStart":true,"autoInsertedEnd":true,"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"UnclosedTableEndsWithTR","href":"./Template:UnclosedTableEndsWithTR"},"params":{},"i":0}},"\n&lt;onlyinclude>\n|foo\n&lt;/onlyinclude>\n|}"]}'><meta typeof="mw:Includes/OnlyInclude"/></span><table about="#mwt1">
<tbody><tr>

<td>foo
<span class="mw-empty-elt"><meta typeof="mw:Includes/OnlyInclude/End"/></span></td></tr>
</tbody></table>

<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/>
<span class="mw-empty-elt" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"autoInsertedStart":true,"autoInsertedEnd":true,"pi":[[]]}' data-mw='{"parts":[{"template":{"target":{"wt":"UnclosedTableEndsWithTR","href":"./Template:UnclosedTableEndsWithTR"},"params":{},"i":0}},"\n&lt;/noinclude>\n|foo\n|}"]}'><meta typeof="mw:Includes/NoInclude/End"/></span><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/php
<p><br />
</p>
!! html/parsoid
<span class="mw-empty-elt" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n"}},"i":0}}]}'></span>
!! 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><table about="#mwt1" data-parsoid='{"stx":"html"}'>
</table>
!! end

# T66017 -- ugly wikitext with fostered content generates two template ranges
# that are "identical" and generate nesting cycles in the algorithm
!! test
Templates: Ugly templates: 6. Template encapsulation test: Cyclical nesting of template ranges is properly handled
!! wikitext
{{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="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' 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 typeof="mw:Extension/spantag" about="#mwt3" data-parsoid='{"src":"&lt;spantag>[[ho|{{1x|hi}}]]&lt;/spantag>"}' data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"[[ho|{{1x|hi}}]]"}}'><a rel="mw:WikiLink" href="./Ho" title="Ho" data-parsoid='{"stx":"piped","a":{"href":"./Ho"},"sa":{"href":"ho"}}'>hi</a></span>
<span about="#mwt6" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' 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 typeof="mw:Extension/spantag" about="#mwt6" data-parsoid='{"src":"&lt;spantag>[http://test.com?q={{1x|ho}}]&lt;/spantag>"}' data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"[http://test.com?q={{1x|ho}}]"}}'><a rel="mw:ExtLink nofollow" href="http://test.com?q=ho" class="external autonumber"></a></span>
<span about="#mwt9" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' 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 typeof="mw:Extension/spantag" about="#mwt9" data-parsoid='{"src":"&lt;spantag>-{ho|{{1x|hi}}}-&lt;/spantag>"}' data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"-{ho|{{1x|hi}}}-"}}'><span typeof="mw:LanguageVariant" data-mw-variant='{"filter":{"l":["ho"],"t":"hi"}}' data-parsoid='{"fl":["ho"],"src":"-{ho|{{1x|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

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

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

[[:File:Foo.png]]
[[:File:Foo.png|Bar]]
!! metadata
flags=
!! 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

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

# See also T391062 for parsoid-native default sort.
!! 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

# 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
Single-line or multiline-comments can follow headings
!! options
parsoid=wt2html,wt2wt
!! 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-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 millennium started</time>
<mark>This highlighted text</mark>
!! html
<p><data value="5">five</data>
<time datetime="2000-01-01T00:00Z">The new millennium 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

!! 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
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: #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\"}]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"#00FF00\"}},\"i\":0}}]}&apos;>#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: #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\"}]]}&apos; data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:1\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"#00FF00\"},\"2\":{\"wt\":\"#FF00FF\"}},\"i\":0}}]}&apos;>#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

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

!! 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 nofollow" href="http://first/" class="external autonumber"></a> <a rel="mw:ExtLink nofollow" href="http://second" class="external autonumber"></a> <a rel="mw:ExtLink nofollow" href="ftp://ftp" class="external autonumber"></a></p>

<p><a rel="mw:ExtLink nofollow" href="ftp://inlineftp" class="external free">ftp://inlineftp</a></p>

<p><a rel="mw:ExtLink nofollow" href="mailto:enclosed@mail.tld" class="external text">With target</a></p>

<p><a rel="mw:ExtLink nofollow" href="mailto:enclosed@mail.tld" class="external autonumber"></a></p>

<p><a rel="mw:ExtLink nofollow" href="mailto:inline@mail.tld" class="external free">mailto:inline@mail.tld</a></p>
!! 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

!! article
Template:Nested special
!! text
{{Special:Prefixindex/Xyzzyx}}
!! endarticle

!! test
Nested special page transclusion
!! wikitext
{{nested special}}
!! 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":"nested special","href":"./Template:Nested_special"},"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 nofollow" href="irc://%0Aa" class="external free" data-parsoid='{"stx":"url","a":{"href":"irc://%0Aa"},"sa":{"href":"irc://&amp;#x0A;a"}}'>irc://a</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 nofollow" 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 rel="mw:WikiLink" href="./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

!! 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 class="mw-empty-elt"><link typeof="mw:Extension/html" about="#mwt2" data-mw='{"name":"html","attrs":{}}'/></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" ]
!! 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" ]
!! 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
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><li about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bullet","href":"./Template:Bullet"},"params":{},"i":0}}]}'>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><li about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bullet","href":"./Template:Bullet"},"params":{},"i":0}}]}'>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><li about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"lc:{{bullet}} ","function":"lc"},"params":{},"i":0}}]}'>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
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 nofollow" 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;&#91;A link&#93;&#93;</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

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

!! 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
Id starting with underscore
!! wikitext
<div id="_ref"></div>
!! html/*
<div id="&#95;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 lang="en" dir="ltr"><span class="mw-page-title-main">Parser test</span></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 lang="en" dir="ltr"><span class="mw-page-title-main">Screen</span></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 lang="en" dir="ltr"><span class="mw-page-title-main">Screen</span></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 lang="en" dir="ltr"><span class="mw-page-title-main">Screen</span></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 lang="en" dir="ltr"><span class="mw-page-title-main">Art&amp;copy</span></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\"> &lt;/span>test&lt;span typeof=\"mw:DisplaySpace\"> &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" loading="lazy" 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>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
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
!! options
wgAllowExternalImages=true
!! 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]]
!! 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
Check lossless in formatNum
!! wikitext
{{formatnum:9999999999999999}}
{{formatnum:9999999999999999|LOSSLESS}}
!! html/php
<p>10,000,000,000,000,000
9999999999999999
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:9999999999999999","function":"formatnum"},"params":{},"i":0}}]}'>10,000,000,000,000,000</span>
<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:9999999999999999","function":"formatnum"},"params":{"1":{"wt":"LOSSLESS"}},"i":0}}]}'>9999999999999999</span></p>
!! end

!! test
Check bn lossless in formatNum
!! options
language=bn
!! wikitext
{{formatnum:9999999999999999}}
{{formatnum:9999999999999999|LOSSLESS}}
!! html/php
<p>১০,০০,০০,০০,০০,০০,০০,০০০
9999999999999999
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:9999999999999999","function":"formatnum"},"params":{},"i":0}}]}'>১০,০০,০০,০০,০০,০০,০০,০০০</span>
<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:9999999999999999","function":"formatnum"},"params":{"1":{"wt":"LOSSLESS"}},"i":0}}]}'>9999999999999999</span></p>
!! end

!! test
Check noCommafy + lossless in formatNum
!! wikitext
{{formatnum:999999999999999|NOSEP|LOSSLESS}}
{{formatnum:9999999999999999|NOSEP|LOSSLESS}}
!! html/php
<p>999999999999999
9999999999999999
</p>
!! html/parsoid+integrated
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:999999999999999","function":"formatnum"},"params":{"1":{"wt":"NOSEP"},"2":{"wt":"LOSSLESS"}},"i":0}}]}'>999999999999999</span>
<span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"formatnum:9999999999999999","function":"formatnum"},"params":{"1":{"wt":"NOSEP"},"2":{"wt":"LOSSLESS"}},"i":0}}]}'>9999999999999999</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
Language parser function (Japanese localization, double-wide hash & double-wide colon)
!! options
language=ja
!! wikitext
{{#language:ja}}

{{#言語:ja}}

{{＃言語:ja}}

{{＃言語：ja}}
!! html/php
<p>日本語
</p><p>日本語
</p><p>日本語
</p><p>日本語
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#language:ja","function":"language"},"params":{},"i":0}}]}'>日本語</span></p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#言語:ja","function":"language"},"params":{},"i":0}}]}'>日本語</span></p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"＃言語:ja","function":"language"},"params":{},"i":0}}]}'>日本語</span></p>
<p><span typeof="mw:Transclusion" data-parsoid='{"colon":"："}' data-mw='{"parts":[{"template":{"target":{"wt":"＃言語:ja","function":"language"},"params":{},"i":0}}]}'>日本語</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:=}}.
!! metadata
!! 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 nofollow" 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 nofollow" 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-only testing of Parsoid's impl of LST
#### Not implemented yet, see
#### https://www.mediawiki.org/wiki/Parsoid/HTML_based_LST
#### ----------------------------------------------------------------

!! test
LST Sections: Newfangled approach
!! wikitext
<section begin="2011-05-16" />
<section end="2014-04-10 (MW 1.23wmf22)" />
!! html/parsoid
<p class="mw-empty-elt"><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
!! options
parsoid=wt2html,html2wt
!! 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/php
<table>
<tbody><tr>
<td>Hello
</td>
<td>there
</td></tr>

</tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>Hello</td>
<td>there</td></tr>
<tr class="foo mw-empty-elt"></tr>
<tr class="mw-empty-elt"></tr>
!! 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 class='mw-empty-elt'>
<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" loading="lazy" 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/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" loading="lazy" 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/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
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

## 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><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
<span class="mw-empty-elt" about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;table>"}},"i":0}},"&lt;!--c-->[[Category:Two]]"]}'><link rel="mw:PageProp/Category" href="./Category:Two"/></span><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
<span class="mw-empty-elt" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"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:One"/><link rel="mw:PageProp/Category" href="./Category:Two"/></span><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" loading="lazy" 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
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

!! 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"><span class="mw-empty-elt"><link rel="mw:PageProp/Category" href="./Category:123"/></span></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

!! 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/php
<table>
<style>.hi { color: red; }</style>

<tbody><tr><td class="hi">ho</td></tr>
</tbody></table>
!! html/parsoid
<style typeof="mw:Extension/html mw:Transclusion" about="#mwt3" data-parsoid='{"fostered":true}' data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;style>.hi { color: red; }&lt;/style>\n"},"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>"]}'>.hi { color: red; }</style><span about="#mwt3">
</span><table about="#mwt3" data-parsoid='{"stx":"html","dsr":[0,104,7,8]}'>

<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
T222419: Section numbering after unclosed template/parser function
!! options
notoc
parsoid={
  "modes": ["wt2html"],
  "wrapSections": true
}
!! wikitext
== Foo ==
{{subst: a surname
== Bar ==
!! 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>
<p>{{subst: a surname
</p>
<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>
!! html/parsoid
<section data-mw-section-id="0"></section><section data-mw-section-id="1"><h2 id="Foo">Foo</h2>
<p>{{subst: a surname</p>
</section><section data-mw-section-id="2"><h2 id="Bar">Bar</h2></section>
!! end

##########################################################################
# Tests demonstrating white-space insensitivity in input wikitext
# for wikitext headings, wikitext list items, and wikitext table captions,
# headings, and cells. HTML versions of the same should preserve whitespace.
##########################################################################
!! test
Trim whitespace in wikitext headings, list items, table captions, headings, and cells
!! options
parsoid={
	"modes": ["wt2html"],
	"preserveIEW": true
}
!! wikitext
__NOTOC__
==    <!--c1-->  <!--c2--> Spaces   <!--c3--> <!--c4-->  ==
==		<!--c1-->	<!--c2--> Tabs		<!--c3--><!--c4-->	==
== <!--Headings with fallback ids--> Личная жизнь ==
*     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->
; <!--term to define--> term : <!--term's definition--> definition
{|
|+ <!--c1--> <!--c2--> Table Caption <!--c3--> <!--c4-->
|-
!  <!--c1--> <!--c2--> Table Heading 1 <!--c3--> <!--c4--> !!   Table Heading 2 <!--c5-->
|-
| <!--c1--> <!--c2--> Table Cell 1 <!--c3--> <!--c4--> ||   Table Cell 2 <!--c5-->
|-
| class="foo" || <!--c1--> <!--c2--> Table Cell 3 <!--c3--> <!--c4-->
|-
| <!--c1--> testing [[one|two]] <!--c2--> | <!--c3--> some content
|}
: {|
  |  <!--c1--> <!--c2--> Table Cell 1 <!--c3--> <!--c4--> ||   Table Cell 2 <!--c5-->
  |} foo   <!--c1-->
!! html/php
<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
}
!! 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
<h2 id="Heading" class="mw-html-heading">        Heading       </h2>
<ul><li>          List item    </li></ul>
<table>
<tbody><tr><th>   Table Heading   </th><th></th></tr>
<tr><td>   Table Cell   </td><th></th></tr>
</tbody></table>
!! html/parsoid
<meta property="mw:PageProp/notoc"/>
<h2 id="Heading">    <!--c1-->   <!--c2--> Heading    <!--c3--> <!--c4-->  </h2>
<ul><li>     <!--c1-->   <!--c2-->  List item <!--c3--> <!--c4-->  </li></ul>
<table>
<tbody><tr><th> <!--c1--> <!--c2--> Table Heading <!--c3--> <!--c4--> </th><th></th></tr>
<tr><td> <!--c1--> <!--c2--> Table Cell <!--c3--> <!--c4--> </td><th></th></tr>
</tbody></table>
!! end

!! test
Do not trim whitespace in links and quotes
!! options
parsoid={
	"modes": ["wt2html"],
	"preserveIEW": true
}
!! wikitext
foo ''  <!--c1--> italic <!--c2-->   '' and '''  <!--c3-->  bold  <!--c4-->  '''
[[Foo|  some text  ]]
!! html/php
<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
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
Extension tag with embedded html
!! wikitext
<embedtag>Content with a [[broken link]].</embedtag>
!! html/parsoid
<p><span typeof="mw:Extension/embedtag" about="#mwt1" data-mw='{"name":"embedtag","attrs":{},"body":{"html":"Content with a &lt;a rel=\"mw:WikiLink\" href=\"./Broken_link?action=edit&amp;amp;redlink=1\" title=\"Broken link\" class=\"new\" typeof=\"mw:LocalizedAttrs\" data-parsoid=&apos;{\"stx\":\"simple\",\"a\":{\"href\":\"./Broken_link\"},\"sa\":{\"href\":\"broken link\"},\"dsr\":[25,40,2,2]}&apos; data-mw-i18n=&apos;{\"title\":{\"lang\":\"x-page\",\"key\":\"red-link-title\",\"params\":[\"Broken link\"]}}&apos;>broken link&lt;/a>."}}'></span></p>
!! end

# standalone/integrated have slightly different wt2html output based on template-expansion & tokenization differences
!! test
Extension tag with td-like wikitext
!! options
parsoid=wt2html,wt2wt
!! wikitext
<embedtag>
{{1x|
{{!}} foo {{!}}
}}
| bar |
</embedtag>
!! html/parsoid+integrated
<p><span typeof="mw:Extension/embedtag" about="#mwt2" data-mw='{"name":"embedtag","attrs":{},"body":{"html":"\n&lt;span about=\"#mwt1\" typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"1x\",\"href\":\"./Template:1x\"},\"params\":{\"1\":{\"wt\":\"\\n{{!}} foo {{!}}\\n\"}},\"i\":0}}]}&apos;>\n| foo |\n&lt;/span>\n| bar |\n"}}'></span></p>
!! end

!! test
Cloned formatting element with extension tag that unpacks itself in attribute name position
!! options
parsoid=wt2html
!! wikitext
<i <sealtag>y</sealtag>>

z
!! html/parsoid
<p><i about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"&lt;sealtag>y&lt;/sealtag>":null},"sa":{"&lt;sealtag>y&lt;/sealtag>":""},"autoInsertedEnd":true}' data-mw='{"attribs":[[{"txt":"","html":"&lt;span about=\"#mwt2\" typeof=\"mw:Extension/sealtag\" data-parsoid=&apos;{\"src\":\"&amp;lt;sealtag>y&amp;lt;/sealtag>\"}&apos; data-mw=&apos;{\"name\":\"sealtag\",\"attrs\":{},\"body\":{\"extsrc\":\"y\"}}&apos;>&lt;/span>"},{"html":""}]]}'></i></p>

<p><i about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"&lt;sealtag>y&lt;/sealtag>":null},"sa":{"&lt;sealtag>y&lt;/sealtag>":""},"autoInsertedStart":true,"autoInsertedEnd":true}' data-mw='{"attribs":[[{"txt":"","html":""},{"html":""}]]}'>z</i></p>
!! end

!! test
Cloned formatting element with extension tag that unpacks itself in attribute value position
!! options
parsoid=wt2html
!! wikitext
<i title="<sealtag>y</sealtag>">a

z
!! html/parsoid
<p><i title="" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"title":""},"sa":{"title":"&lt;sealtag>y&lt;/sealtag>"},"autoInsertedEnd":true}' data-mw='{"attribs":[[{"txt":"title"},{"html":"&lt;span about=\"#mwt2\" typeof=\"mw:Extension/sealtag\" data-parsoid=&apos;{\"src\":\"&amp;lt;sealtag>y&amp;lt;/sealtag>\"}&apos; data-mw=&apos;{\"name\":\"sealtag\",\"attrs\":{},\"body\":{\"extsrc\":\"y\"}}&apos;>&lt;/span>"}]]}'>a</i></p>

<p><i title="" about="#mwt3" typeof="mw:ExpandedAttrs" data-parsoid='{"stx":"html","a":{"title":""},"sa":{"title":"&lt;sealtag>y&lt;/sealtag>"},"autoInsertedStart":true,"autoInsertedEnd":true}' data-mw='{"attribs":[[{"txt":"title"},{"html":""}]]}'>z</i></p>
!! end

!! test
Include directive string gluing
!! wikitext
<noinclude>{{1x|</noinclude>testing<noinclude>}}</noinclude>
!! html/php
<p>testing
</p>
!! html/parsoid+integrated
<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><p data-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":"&lt;/noinclude>testing&lt;noinclude>"}},"i":0}}]}'>testing</span></p><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>
!! html/parsoid+standalone
<meta typeof="mw:Includes/NoInclude" data-parsoid='{"src":"&lt;noinclude>"}'/><p data-parsoid='{}'><meta typeof="mw:Transclusion mw:Includes/NoInclude/End" about="#mwt1" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/noinclude>testing&lt;noinclude>"}},"i":0}}]}'/><span about="#mwt1">testing</span><meta typeof="mw:Includes/NoInclude" about="#mwt1"/></p><meta typeof="mw:Includes/NoInclude/End" data-parsoid='{"src":"&lt;/noinclude>"}'/>
!! end

!! test
1. Include directive in template target
!! wikitext
{{1x<noinclude>|123</noinclude>}}
!! html/php
<p>123
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x&lt;noinclude>","href":"./Template:1x"},"params":{"1":{"wt":"123&lt;/noinclude>"}},"i":0}}]}'>123</span></p>
!! html/parsoid+standalone
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x&lt;noinclude>","href":"./Template:1x"},"params":{"1":{"wt":"123&lt;/noinclude>"}},"i":0}}]}'>123</span><meta typeof="mw:Includes/NoInclude/End" about="#mwt1"/></p>
!! end

!! test
2. Include directive in template target
!! wikitext
{{1x<includeonly>|123</includeonly>|345}}
!! html/php
<p>345
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x&lt;includeonly>|123&lt;/includeonly>","href":"./Template:1x"},"params":{"1":{"wt":"345"}},"i":0}}]}'>345</span></p>
!! html/parsoid+standalone
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x&lt;includeonly>|123&lt;/includeonly>","href":"./Template:1x"},"params":{"1":{"wt":"345"}},"i":0}}]}'>345</span></p>
!! end

!! test
3. Include directive in template target
!! wikitext
{{1x<onlyinclude>|123</onlyinclude>}}
!! html/php
<p>123
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x&lt;onlyinclude>","href":"./Template:1x"},"params":{"1":{"wt":"123&lt;/onlyinclude>"}},"i":0}}]}'>123</span></p>
!! html/parsoid+standalone
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x&lt;onlyinclude>","href":"./Template:1x"},"params":{"1":{"wt":"123&lt;/onlyinclude>"}},"i":0}}]}'>123</span><meta typeof="mw:Includes/OnlyInclude/End" about="#mwt1"/></p>
!! end

!! test
4. Include directive in template target
!! wikitext
{{{{{1<noinclude>|1x</noinclude>}}}|123}}
!! html/php
<p>123
</p>
!! html/parsoid
<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"{{{1&lt;noinclude>|1x&lt;/noinclude>}}}","href":"./Template:1x"},"params":{"1":{"wt":"123"}},"i":0}}]}'>123</span></p>
!! end

## Testing various return value types for parser functions
## This uses the <spantag>/<divtag> hooks, specially defined for parser tests

# Parsoid has same output for isHTML and isRawHTML (known difference)
!! test
Extension tag contents using isRawHTML flag
!! options
language=zh
!! wikitext
DoBlockLevels and LanguageConverter still run on isHTML content:
<divtag raw="true" ishtml="true"><!--protect newline-->
:foo -{raw}- <b>bold</b>
</divtag>

But with isRawHTML the result is left alone:
<divtag raw="true" israwhtml="true"><!--protect newline-->
:foo -{raw}- <b>bold</b>
</divtag>
!! html/php
<p>DoBlockLevels and LanguageConverter still run on isHTML content:
</p>
<div><!--protect newline-->
<dl><dd>foo raw <b>bold</b></dd></dl>
</div>
<p>But with isRawHTML the result is left alone:
</p><div><!--protect newline-->
:foo -{raw}- <b>bold</b>
</div>
<p class="mw-empty-elt"></p>
!! html/parsoid+integrated
<p>DoBlockLevels and LanguageConverter still run on isHTML content:</p>
<div typeof="mw:Extension/divtag" data-mw='{"name":"divtag","attrs":{"raw":"true","ishtml":"true"},"body":{"extsrc":"&lt;!--protect newline-->\n:foo -{raw}- &lt;b>bold&lt;/b>\n"}}'><!--protect newline--> :foo -{raw}- <b>bold</b></div>
<p>But with isRawHTML the result is left alone:</p>
<div typeof="mw:Extension/divtag" data-mw='{"name":"divtag","attrs":{"raw":"true","israwhtml":"true"},"body":{"extsrc":"&lt;!--protect newline-->\n:foo -{raw}- &lt;b>bold&lt;/b>\n"}}'><!--protect newline--> :foo -{raw}- <b>bold</b></div>
!! end

# Parsoid has same output for isHTML and isRawHTML (known difference)
!! test
Parser function contents using isRawHTML flag
!! options
language=zh
!! wikitext
DoBlockLevels and LanguageConverter still run on isHTML content:
{{#divtag:<!--protect newline-->
:foo -{raw}- <b>bold</b>
|raw|isHTML}}

But with isRawHTML the result is left alone:
{{#divtag:<!--protect newline-->
:foo -{raw}- <b>bold</b>
|raw|isRawHTML}}
!! html/php
<p>DoBlockLevels and LanguageConverter still run on isHTML content:
</p>
<div>:foo raw <b>bold</b></div>
<p>But with isRawHTML the result is left alone:
</p><div>:foo -{raw}- <b>bold</b></div>
<p class="mw-empty-elt"></p>
!! html/parsoid+integrated
<p>DoBlockLevels and LanguageConverter still run on isHTML content:</p>
<div typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#divtag:&lt;!--protect newline-->\n:foo -{raw}- &lt;b>bold&lt;/b>\n","function":"divtagpf"},"params":{"1":{"wt":"raw"},"2":{"wt":"isHTML"}},"i":0}}]}'>:foo -{raw}- <b>bold</b></div>
<p>But with isRawHTML the result is left alone:</p>
<div typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#divtag:&lt;!--protect newline-->\n:foo -{raw}- &lt;b>bold&lt;/b>\n","function":"divtagpf"},"params":{"1":{"wt":"raw"},"2":{"wt":"isRawHTML"}},"i":0}}]}'>:foo -{raw}- <b>bold</b></div>
!! end

!! test
Handling of numeric extension tag arguments
!! options
parsoid=wt2html
!! wikitext
<spantag name=Round of 16>test</spantag>
!! html/parsoid
<p><span typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{"name":"Round","of":"","16":""},"body":{"extsrc":"test"}}'>test</span></p>
!! end

!! test
Handling of nowiki strip markers in Parsoid fragments
!! options
parsoid=wt2html
!! wikitext
Extension tag: <spantag><nowiki>a &amp;amp; <b>c</b></nowiki></spantag>

Parser function: {{#spantag:<nowiki>a &amp;amp; <b>c</b></nowiki>}}
!! html/php
<p>Extension tag: <span>a &amp;amp; &lt;b&gt;c&lt;/b&gt;</span>
</p><p>Parser function: <span>a &amp;amp; &lt;b&gt;c&lt;/b&gt;</span>
</p>
!! html/parsoid+integrated
<p>Extension tag: <span typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"&lt;nowiki>a &amp;amp;amp; &lt;b>c&lt;/b>&lt;/nowiki>"}}'>a <span typeof="mw:Entity">&amp;</span>amp; &lt;b>c&lt;/b></span></p>
<p>Parser function: <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#spantag:&lt;nowiki>a &amp;amp;amp; &lt;b>c&lt;/b>&lt;/nowiki>","function":"spantagpf"},"params":{},"i":0}}]}'>a &amp;amp; &lt;b>c&lt;/b></span></p>
!! end

!! test
Handling of nested nowiki strip markers in Parsoid fragments (1)
!! wikitext
Text {{#spantag:text <spantag>more text</spantag>}}
!! html/php
<p>Text <span>text <span>more text</span></span>
</p>
!! html/parsoid+integrated
<p>Text <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#spantag:text &lt;spantag>more text&lt;/spantag>","function":"spantagpf"},"params":{},"i":0}}]}'>text <span typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"more text"}}'>more text</span></span></p>
!! end

!! test
Handling of nested nowiki strip markers in Parsoid fragments (2)
!! wikitext
Text {{#spantag:<nowiki><b></nowiki> {{#spantag:<nowiki><c></nowiki>}}}}
!! html/php
<p>Text <span>&lt;b&gt; <span>&lt;c&gt;</span></span>
</p>
!! html/parsoid+integrated
<p>Text <span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#spantag:&lt;nowiki>&lt;b>&lt;/nowiki> {{#spantag:&lt;nowiki>&lt;c>&lt;/nowiki>}}","function":"spantagpf"},"params":{},"i":0}}]}'>&lt;b> <span>&lt;c></span></span></p>
!! end

!! test
Handling of nowiki strip markers in {{#tag}}/legacy extensions (T432547)
!! wikitext
Text
{{#tag:spantaglegacy|<nowiki>test1</nowiki>}}
{{#tag:spantaglegacy||contents=<nowiki>test2</nowiki>}}
!! html/php
<p>Text
<span>test1</span>
<span>test2</span>
</p>
!! html/parsoid+integrated
<p>Text <span data-mw='{"name":"spantaglegacy","attrs":{},"body":{"extsrc":"{{#parsoid\u0000fragment}}"},"parts":[{"template":{"target":{"wt":"#tag:spantaglegacy","function":"tag"},"params":{"1":{"wt":"&lt;nowiki>test1&lt;/nowiki>"}},"i":0}}]}' typeof="mw:Extension/spantaglegacy mw:Transclusion">test1</span> <span data-mw='{"name":"spantaglegacy","attrs":{"contents":"test2"},"body":{"extsrc":""},"parts":[{"template":{"target":{"wt":"#tag:spantaglegacy","function":"tag"},"params":{"1":{"wt":""},"2":{"wt":"contents=&lt;nowiki>test2&lt;/nowiki>"}},"i":0}}]}' typeof="mw:Extension/spantaglegacy mw:Transclusion">test2</span></p>
!! end

!! test
{{#contentmodel}} parser function
!! wikitext
{{#contentmodel}}

{{#contentmodel:local}}

{{#contentmodel:canonical}}
!! html/php
<p>wikitext
</p><p>wikitext
</p><p>wikitext
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#contentmodel","function":"contentmodel"},"params":{},"i":0}}]}'>wikitext</span></p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#contentmodel:local","function":"contentmodel"},"params":{},"i":0}}]}'>wikitext</span></p>
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#contentmodel:canonical","function":"contentmodel"},"params":{},"i":0}}]}'>wikitext</span></p>
!! end

!! test
{{#contentmodel}} parser function on a CSS page
!! options
title=MediaWiki:Common.css
!! wikitext
{{#contentmodel}}
!! html/php
<p>CSS
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#contentmodel","function":"contentmodel"},"params":{},"i":0}}]}'>CSS</span></p>
!! end

!! test
{{#contentmodel}} parser function on a CSS page (canonical)
!! options
title=MediaWiki:Common.css
!! wikitext
{{#contentmodel: canonical}}
!! html/php
<p>css
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#contentmodel: canonical","function":"contentmodel"},"params":{},"i":0}}]}'>css</span></p>
!! end

!! test
{{#contentmodel}} parser function for a JS page using the title argument
!! wikitext
{{#contentmodel: canonical | MediaWiki:Common.js}}
!! html/php
<p>javascript
</p>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"#contentmodel: canonical ","function":"contentmodel"},"params":{"1":{"wt":" MediaWiki:Common.js"}},"i":0}}]}'>javascript</span></p>
!! end

!! test
1. T400845: Dom/Handlers/CleanUp.php: Added mw:DisplaySpace spaces removal
!! options
parsoid=wt2html
!! wikitext
{|
|%
|&nbsp;%
| %
| &nbsp;%
|&nbsp; %
|  %
|   %
|}

*%
*&nbsp;%
* %
* &nbsp;%
*&nbsp; %
*  %
*   %

   % pre 1

''' % BOLD '''
!! html/php
<table>
<tbody><tr>
<td>%
</td>
<td>&#160;%
</td>
<td>%
</td>
<td>&#160;%
</td>
<td>&#160;&#160;%
</td>
<td>%
</td>
<td>%
</td></tr></tbody></table>
<ul><li>%</li>
<li>&#160;%</li>
<li>%</li>
<li>&#160;%</li>
<li>&#160;&#160;%</li>
<li>%</li>
<li>%</li></ul>
<pre> &#160;% pre 1
</pre>
<p><b>&#160;% BOLD </b>
</p>
!! html/parsoid
<table>
<tbody><tr><td>%</td>
<td><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>%</td>
<td>%</td>
<td><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>%</td>
<td><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:DisplaySpace"> </span>%</td>
<td>%</td>
<td>%</td></tr>
</tbody></table>

<ul><li data-parsoid='{}'>%</li>
<li data-parsoid='{}'><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>%</li>
<li data-parsoid='{}'>%</li>
<li data-parsoid='{}'><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>%</li>
<li data-parsoid='{}'><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:DisplaySpace"> </span>%</li>
<li data-parsoid='{}'>%</li>
<li data-parsoid='{}'>%</li></ul>

<pre>  % pre 1</pre>

<p><b><span typeof="mw:DisplaySpace"> </span>% BOLD </b></p>
!! end

!! test
2. T400845: Dom/Handlers/CleanUp.php: Added mw:DisplaySpace spaces removal
!! wikitext
{|
|%
|&nbsp;%
|%
|&nbsp;%
|&nbsp; %
|%
|%
|}

*%
*&nbsp;%
*%
*&nbsp;%
*&nbsp; %
*%
*%

   % pre 1

''' % BOLD '''
!! html/php
<table>
<tbody><tr>
<td>%
</td>
<td>&#160;%
</td>
<td>%
</td>
<td>&#160;%
</td>
<td>&#160;&#160;%
</td>
<td>%
</td>
<td>%
</td></tr></tbody></table>
<ul><li>%</li>
<li>&#160;%</li>
<li>%</li>
<li>&#160;%</li>
<li>&#160;&#160;%</li>
<li>%</li>
<li>%</li></ul>
<pre> &#160;% pre 1
</pre>
<p><b>&#160;% BOLD </b>
</p>
!! html/parsoid
<table>
<tbody><tr><td>%</td>
<td><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>%</td>
<td>%</td>
<td><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>%</td>
<td><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:DisplaySpace"> </span>%</td>
<td>%</td>
<td>%</td></tr>
</tbody></table>

<ul><li data-parsoid='{}'>%</li>
<li data-parsoid='{}'><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>%</li>
<li data-parsoid='{}'>%</li>
<li data-parsoid='{}'><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>%</li>
<li data-parsoid='{}'><span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span><span typeof="mw:DisplaySpace"> </span>%</li>
<li data-parsoid='{}'>%</li>
<li data-parsoid='{}'>%</li></ul>

<pre>  % pre 1</pre>

<p><b><span typeof="mw:DisplaySpace"> </span>% BOLD </b></p>
!! end

!! article
Template:Tplrt
!! text
{{1x|{}}{1x|test}}
!! endarticle

!! test
Template returning template syntax in html attribute
!! wikitext
{{tplrt}}

<div class="{{tplrt}}">123</div>
!! html/php
<p>{{1x|test}}
</p>
<div class="&#123;&#123;1x&#124;test&#125;&#125;">123</div>
!! html/parsoid+integrated
<p><span typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"tplrt","href":"./Template:Tplrt"},"params":{},"i":0}}]}'>{{1x|test}}</span></p>
<div class="{{1x|test}}" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"class"},{"html":"&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"tplrt\",\"href\":\"./Template:Tplrt\"},\"params\":{},\"i\":0}}]}&apos;>{{1x|test}}&lt;/span>"}]]}'>123</div>
!! end

!! test
Nested extension tag using the #tag parser function
!! config
wgReturnExperimentalPFragmentTypes=[ "ExtTagPFragment" ]
!! wikitext
{{#tag:spantag|outer <spantag>inner</spantag>}}
!! html/php
<p><span>outer <span>inner</span></span>
</p>
!! html/parsoid+integrated
<p><span data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"outer {{#parsoid\u0000fragment}}"},"parts":[{"template":{"target":{"wt":"#tag:spantag","function":"tag"},"params":{"1":{"wt":"outer &lt;spantag>inner&lt;/spantag>"}},"i":0}}]}' typeof="mw:Extension/spantag mw:Transclusion">outer <span data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"inner"}}' typeof="mw:Extension/spantag">inner</span></span></p>
!! end

!! test
Nested nowiki tag using the #tag parser function
!! wikitext
{{#tag:nowiki|<nowiki>hi</nowiki>}}
!! html/php
<p>hi
</p>
!! html/parsoid+integrated
<p><span data-mw='{"parts":[{"template":{"target":{"wt":"#tag:nowiki","function":"tag"},"params":{"1":{"wt":"&lt;nowiki>hi&lt;/nowiki>"}},"i":0}}]}' typeof="mw:Nowiki mw:Transclusion">hi</span></p>
!! end

!! test
U+00A0 in extension attribute data-mw serializes as &nbsp;
!! html/parsoid
<pre typeof="mw:Extension/tag" about="#mwt1" data-parsoid='{"dsr":[0,35,25,6]}' data-mw='{"name":"tag","attrs":{"details":"S. 1"},"body":{"extsrc":"Test"}}'>'Test'
array (
  'details' => 'S. 1',
)
</pre>
!! wikitext
<tag details="S.&nbsp;1">Test</tag>
!! end
