# We don't need to run these tests in integrated mode as well.
!! options
version=2
!! end

!!article
Bar
!!text
abcd
!!endarticle

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

# We need the span in the wikilink so that the link text is
# processed as a DOMFragment which then triggers the regression
# we are testing in this file
!!article
Template:RegressionTest
!!text
[[Bar|<span>bar</span>]]
!!endarticle

# Regression test -- ensure that nested pipeline TSR information
# doesn't leak onto the top-level pipeline during DSR computation.
# We verify this indirectly via passing selser tests.
!!test
Regression Test: Ensure nested pipeline TSR doesn't impact top-level DSR values
!!wikitext
{{RegressionTest}}

Bar
!!html/parsoid
<p><a rel="mw:WikiLink" href="./Bar" title="Bar" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"RegressionTest","href":"./Template:RegressionTest"},"params":{},"i":0}}]}'><span>bar</span></a></p>

<p>Bar</p>
!!end

# As seen in T334957#9026561
!! test
Ensure proper DSR offsets are computed
!! options
parsoid=wt2html,selser
!! wikitext
{|
|-

é

''x''

* {{1x|
{{{!}}
{{!}}-
}}
!! html/parsoid
<p data-parsoid='{"fostered":true,"autoInsertedStart":true}'>

é

<i>x</i></p><ul data-parsoid='{"fostered":true}'><li class="mw-empty-elt"></li></ul><table about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"autoInsertedEnd":true}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n{{{!}}\n{{!}}-\n"}},"i":0}},"{|\n|-\n\né\n\n&apos;&apos;x&apos;&apos;\n\n* {{1x|\n{{{!}}\n{{!}}-\n}}"]}'>
</table><table about="#mwt1">
</table>
!! end

# This is just a regression test to ensure code can handle tables with fosterable content
# in DOM fragment position (Ex: image captions). This is an edge case and didn't feel it
# belonged in media.txt which already has a number of tests with tables in captions.
!! test
Images with captions containing tables with fosterable content shouldn't crash Parsoid
!! options
parsoid=wt2html
!! wikitext
[[File:Foobar.jpg|thumb|50px|
{|
{{1x|<span>foo</span>}}
|}
]]
!! html/parsoid
<figure typeof="mw:File/Thumb" data-parsoid='{"optList":[{"ck":"thumbnail","ak":"thumb"},{"ck":"width","ak":"50px"},{"ck":"caption","ak":"\n{|\n{{1x|&lt;span>foo&lt;/span>}}\n|}\n"}]}'><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/50px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="6" width="50" srcset="http://example.com/images/thumb/3/3a/Foobar.jpg/75px-Foobar.jpg 1.5x, http://example.com/images/thumb/3/3a/Foobar.jpg/100px-Foobar.jpg 2x" class="mw-file-element" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"6","width":"50"},"sa":{"resource":"File:Foobar.jpg"}}'/></a><figcaption>
<p about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"fostered":true,"autoInsertedStart":true,"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;span>foo&lt;/span>"}},"i":0}},"\n|}"]}'><span>foo</span></p><table about="#mwt2">

</table>
</figcaption></figure>
!! end

!! test
Unpacking fostered content
!! options
parsoid=wt2html
!! wikitext
[http://google.com <table>hi</table> ho]
!! html/parsoid
<a rel="mw:ExtLink nofollow" href="http://google.com" class="external text"><p data-parsoid='{"fostered":true,"autoInsertedStart":true}'>hi</p><table data-parsoid='{"stx":"html"}'></table> ho</a>
!! end

!! test
Pipe magic word in bailing wikilink
!! options
parsoid=wt2html
!! wikitext
{|
| [[{{!}}]] [[{{!}}]]
|}
!! html/php
<table>
<tbody><tr>
<td>[[|]] [[|]]
</td></tr></tbody></table>
!! html/parsoid
<table>
<tbody><tr><td>[[|]] [[|]]</td></tr>
</tbody></table>
!! end

!! test
SOL whitespace and newlines after lists should not be swallowed into ListTk compound token
!! options
parsoid=wt2html
!! wikitext
*a
  
   
<div>b</div>
!! html/parsoid
<ul><li>a</li></ul>
  <p>
   <br></p>
<div data-parsoid='{"stx":"html"}'>b</div>
!! end

# Edge case in p-wrapping handling IndentPreTk
!! test
Unbalanced i-tags shouldn't leak out of blockquote containing leading whitespace
!! options
parsoid=wt2html
!! wikitext
<blockquote>
    foo ''bar
</blockquote>

baz
!! html/parsoid
<blockquote data-parsoid='{"stx":"html"}'>
 <p>   foo <i data-parsoid='{"autoInsertedEnd":true}'>bar</i></p>
</blockquote>

<p>baz</p>
!! end

!! test
Ensure ListHandler properly handles other compound tokens
!! options
parsoid=wt2html
!! wikitext
:{|
|
 a
|}
!! html/parsoid
<dl><dd><table>
<tbody><tr><td>
<pre>a</pre></td></tr>
</tbody></table></dd></dl>
!! end

!! test
Ensure WikiLink caching handles embedded fragments properly
!! options
parsoid=wt2html
!! wikitext
1. [[Foo|<spantag>a</spantag>]]
2. [[Foo|<spantag>a</spantag>]]
3. [[Foo|<spantag>a</spantag>]]
4. [[Foo|<spantag>a</spantag>]]
5. [[Foo|<spantag>a</spantag>]]
!! html/parsoid
<p>1. <a rel="mw:WikiLink" href="./Foo?action=edit&amp;redlink=1" title="Foo" class="new" typeof="mw:LocalizedAttrs" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Foo"]}}'><span typeof="mw:Extension/spantag" about="#mwt1" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"a"}}'>a</span></a>
2. <a rel="mw:WikiLink" href="./Foo?action=edit&amp;redlink=1" title="Foo" class="new" typeof="mw:LocalizedAttrs" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Foo"]}}'><span typeof="mw:Extension/spantag" about="#mwt2" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"a"}}'>a</span></a>
3. <a rel="mw:WikiLink" href="./Foo?action=edit&amp;redlink=1" title="Foo" class="new" typeof="mw:LocalizedAttrs" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Foo"]}}'><span typeof="mw:Extension/spantag" about="#mwt3" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"a"}}'>a</span></a>
4. <a rel="mw:WikiLink" href="./Foo?action=edit&amp;redlink=1" title="Foo" class="new" typeof="mw:LocalizedAttrs" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Foo"]}}'><span typeof="mw:Extension/spantag" about="#mwt4" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"a"}}'>a</span></a>
5. <a rel="mw:WikiLink" href="./Foo?action=edit&amp;redlink=1" title="Foo" class="new" typeof="mw:LocalizedAttrs" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Foo"]}}'><span typeof="mw:Extension/spantag" about="#mwt5" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"a"}}'>a</span></a></p>
!! end

# The integrity of empty-line-tk should not get compromised
# because of QuoteHandler's onCompoundTk handling of compound tokens
!! test
QuoteHandler::onCompoundTk should not corrupt EmptyLineTk tokens
!! options
parsoid=wt2html
!! wikitext
<table><tr><td>''a''</td><td title="&amp;">b</td></tr></table>
[[Category:C]]
!! html/parsoid
<table data-parsoid='{"stx":"html"}'><tbody><tr data-parsoid='{"stx":"html"}'><td data-parsoid='{"stx":"html"}'><i>a</i></td><td title="&amp;" data-parsoid='{"stx":"html","a":{"title":"&amp;"},"sa":{"title":"&amp;amp;"}}'>b</td></tr></tbody></table>
<link rel="mw:PageProp/Category" href="./Category:C" />
!! end

!! test
Ensure source offsets are reset when reprocessing
!! options
parsoid=wt2wt
!! wikitext
| dir="{{#dir:hu}}" | [[mail:{{{1}}}|123]]
!! html/parsoid
-- unused in wt2wt --
!! end

!! test
T378906: Drop template-emitted leading/trailing newlines adjacent to <div>s produced by the same template
!! wikitext
{{1x|<div>foo</div>
}}{{1x|<div>bar</div>}}

{{1x|<div>foo</div>
}}<span>bar</span>

{{1x|<div>foo</div>}}{{1x|
<div>bar</div>}}

<span>foo</span>{{1x|
<div>bar</div>}}
!! html/parsoid
<div 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;div>foo&lt;/div>\n"}},"i":0}}]}'>foo</div><div about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>bar&lt;/div>"}},"i":0}}]}'>bar</div>

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

<div about="#mwt4" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>foo&lt;/div>"}},"i":0}}]}'>foo</div><div about="#mwt5" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n&lt;div>bar&lt;/div>"}},"i":0}}]}'>bar</div>

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

!! test
T378906: Migrate trailing category tags into preceding div
!! wikitext
{{1x|<div>foo</div>
[[Category:Foo]]
[[Category:Bar]]
}}{{1x|<div>bar</div>}}
!! html/parsoid
<div 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;div>foo&lt;/div>\n[[Category:Foo]]\n[[Category:Bar]]\n"}},"i":0}}]}'>foo<link rel="mw:PageProp/Category" href="./Category:Foo"/><link rel="mw:PageProp/Category" href="./Category:Bar"/></div><div about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>bar&lt;/div>"}},"i":0}}]}'>bar</div>
!! end

!! test
T407798: Strip newlines between category link tags in templates
!! wikitext
{{1x|something
[[Category:Foo]]
[[es:Foo]]}}
!! html/php
<p>something
</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":"something\n[[Category:Foo]]\n[[es:Foo]]"}},"i":0}}]}'>something
</span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1"/><link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Foo" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"http://es.wikipedia.org/wiki/Foo"},"sa":{"href":"es:Foo"}}'/></p>
!! end

!! test
Migrate leading category into following div
!! wikitext
{{1x|<div>foo</div>
}}{{1x|[[Category:Foo]]<div>bar</div>}}
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]],"dsr":[0,22,null,null]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>foo&lt;/div>\n"}},"i":0}}]}'>foo</div><div about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"html","pi":[[{"k":"1"}]],"dsr":[22,59,null,null]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"[[Category:Foo]]&lt;div>bar&lt;/div>"}},"i":0}}]}'><link rel="mw:PageProp/Category" href="./Category:Foo"/>bar</div>
!! end

!! test
Migrate leading empty extension into following div
!! wikitext
{{1x|<div>foo</div>
}}{{1x|<section begin="2011-05-16" /><div>bar</div>}}
!! html/parsoid
<div about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"stx":"html"}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>foo&lt;/div>\n"}},"i":0}}]}'>foo</div><div about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"html"}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;section begin=\"2011-05-16\" />&lt;div>bar&lt;/div>"}},"i":0}}]}'><link typeof="mw:Extension/section" about="#mwt3" data-mw='{"name":"section","attrs":{"begin":"2011-05-16"}}'/>bar</div>
!! end
