# This test file has tests to spec requirements # around Parsoid's serialization
# (old, new, edited content), with and without selser, and for automatically generated
# as well as manually generated changes.

# 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

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

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

!! test
Serializer shouldn't blindly user dataParsoid.srcTagName
!! options
parsoid=html2wt
!! html/parsoid
<p><font class="x" data-parsoid='{"stx":"html","srcTagName":"FONT"}'>boo</font></p>
<p><span class="x" data-parsoid='{"stx":"html","srcTagName":"FONT"}'>boo</span></p>
!! wikitext
<FONT class="x">boo</FONT>

<span class="x">boo</span>
!! end

!! test
Ignore rel attribute in a-tags during serialization to url-links
!! options
parsoid=html2wt
!! html/parsoid
<a href='http://en.wikipedia.org/wiki/Foobar'>http://en.wikipedia.org/wiki/Foobar</a>
<a href='http://en.wikipedia.org/wiki/Foobar' rel='mw:ExtLink'>http://en.wikipedia.org/wiki/Foobar</a>
<a href='http://en.wikipedia.org/wiki/Foobar' rel='mw:WikiLink'>http://en.wikipedia.org/wiki/Foobar</a>
!! wikitext
http://en.wikipedia.org/wiki/Foobar
http://en.wikipedia.org/wiki/Foobar
http://en.wikipedia.org/wiki/Foobar
!! end

# 'mi' is a localinterwiki prefix as well as a language
!! test
Serialize interwiki links pointing to the current wiki as plain wiki links (T67869)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.org/wiki/Foo">Foo</a></p>
!! wikitext
[[Foo]]
!! end

!! test
Parsoid should accept interwiki shortcuts
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel='mw:WikiLink' href='./fr:Foo'>Foo</a>
<a rel='mw:ExtLink' href='./fr:Foo'>Foo</a>
<a href='./fr:Foo'>Foo</a></p>
<p><a rel='mw:WikiLink' href='fr%3AFoo'>Foo</a>
<a rel='mw:ExtLink' href='fr%3AFoo'>Foo</a>
<a href='fr%3AFoo'>Foo</a></p>
<p><a href='FR%3AFoo'>Foo</a>
<a href='./FR:Foo'>Foo</a></p>
!! wikitext
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]

[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]

[[:fr:Foo|Foo]]
[[:fr:Foo|Foo]]
!! end

!! test
Parsoid should not accept invalid interwiki shortcuts
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel='mw:WikiLink' href='news:Foo'>Foo</a>
<a rel='mw:ExtLink' href='news:Foo'>Foo</a>
<a href='news:Foo'>Foo</a></p>
!! wikitext
[news:Foo Foo]
[news:Foo Foo]
[news:Foo Foo]
!! end

# See T93839
!! test
New wikilinks should be serialized properly
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{}'>Foo</a>
<a rel="mw:WikiLink" href="./Foo" title="Foo">Foo</a>
<a href="//en.wikipedia.org/wiki/Foo">//en.wikipedia.org/wiki/Foo</a>
<a href="http://en.wikipedia.org/wiki/Foo">http://en.wikipedia.org/wiki/Foo</a>
<a href="//en.wikipedia.org/wiki/Foo_bar">//en.wikipedia.org/wiki/Foo bar</a>
!! wikitext
[[Foo]]
[[Foo]]
[[:en:Foo|//en.wikipedia.org/wiki/Foo]]
http://en.wikipedia.org/wiki/Foo
[[:en:Foo_bar|//en.wikipedia.org/wiki/Foo bar]]
!! end

!! test
New wiki links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="Foo bar">Foo_bar</a>
<a rel="mw:WikiLink" href="./Toxine_bact%C3%A9rienne">Toxine bactérienne</a>
!! wikitext
[[Foo_bar]]
[[Foo_bar]]
[[Foo_bar]]
[[Toxine bactérienne]]
!! end

!! test
New wiki links (content string variations)
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo_bar">Foo_bar</a>
<a rel="mw:WikiLink" href="./Foo_bar">Foo bar</a>
<a rel="mw:WikiLink" href="./Foo_bar">./Foo_bar</a>
!! wikitext
[[Foo_bar]]
[[Foo bar]]
[[Foo_bar|./Foo_bar]]
!! end

!! test
New category links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Category" href="./Category:Toxine_bactérienne" />
<link rel="mw:PageProp/Category" href="./Category:Toxine_bact%C3%A9rienne" />
<link rel="mw:PageProp/Category" href="Category:Toxine_bact%C3%A9rienne" />
!! wikitext
[[Category:Toxine bactérienne]]
[[Category:Toxine bactérienne]]
[[Category:Toxine bactérienne]]
!! end

!! test
New sol transparent links don't need indent-pre nowiki protection
!! options
parsoid=html2wt
language=de
!! html/parsoid
         <link rel="mw:PageProp/redirect" href="./Main_Page">
<!-- this is good  -->    <link rel="mw:PageProp/Category" href="./Category:Good" />
<!-- this is great -->    <link rel="mw:PageProp/Category" href="./Kategorie:Great" />
!! wikitext
         #WEITERLEITUNG [[Main Page]]
<!-- this is good  -->    [[Category:Good]]
<!-- this is great -->    [[Kategorie:Great]]
!! end

!! test
New interlanguage links (href variations)
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine bactérienne" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine_bactérienne" />
<link rel="mw:PageProp/Language" href="http://es.wikipedia.org/wiki/Toxine_bact%C3%A9rienne" />
!! wikitext
[[es:Toxine bactérienne]]
[[es:Toxine_bactérienne]]
[[es:Toxine_bactérienne]]
!! end

# Regression test for T219023
!! test
Emit simple non-piped link where possible
!! options
parsoid=html2wt
!! html/parsoid
<a rel='mw:WikiLink' href='./VisualEditor'>VisualEditor</a>
<a rel='mw:WikiLink' href='./VisualEditor'>visualEditor</a>
<a rel='mw:WikiLink' href='./VisualEditor link'>VisualEditor link</a>
<a rel='mw:WikiLink' href='./VisualEditor link'>visualEditor link</a>
!! wikitext
[[VisualEditor]]
[[visualEditor]]
[[VisualEditor link]]
[[visualEditor link]]
!! end

!! test
Lists: Serialize correctly even when list content is wrapped in p-tags (like VE does)
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li><p>foo</p></li>
</ul>
!! wikitext
* foo
!! end

!! test
Lists: Serialize correctly even when list tags has unneeded whitespace between tags
!! options
parsoid=html2wt
!! html/parsoid
<ul> <li>foo</li></ul>
!! wikitext
* foo
!! end

!! test
Don't strip leading whitespace when handling indent-pre suppressing tags
!! options
parsoid=html2wt
!! html/parsoid
<table>
  <tr><td> indented row</td></tr>
</table>
<blockquote><p>
 <b>This is very bold of you!</b>
</p>
<table><tr><td>
 indented cell (no pre-wrapping!)
</td></tr></table>
</blockquote>
<p>foo</p>
 <div>bar</div>
!! wikitext
{|
  | indented row
|}
<blockquote>
 '''This is very bold of you!'''

{|
|
 indented cell (no pre-wrapping!)
|}
</blockquote>
foo
 <div>bar</div>
!! end

!! test
Strip leading whitespace when handling indent-pre inducing tags
!! options
parsoid=html2wt
!! html/parsoid
<p>foo</p>
 <span>bar</span>

<span>foo2
 </span>bar2

<div>foo</div>
 <span>bar</span>

<div>
 <span>foo</span>
</div>
!! wikitext
foo
 
<span>bar</span>

<span>foo2
</span>bar2

<div>foo</div>
<span>bar</span>

<div>
<span>foo</span>
</div>
!! end

!! test
Lists: Dont insert newlines in a serialized list item.
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>a<br>b</li><li>c</li></ul>
!! wikitext
* a<br />b
* c
!! end

!! test
Headings: Force sol-transparent links and behavior switches to serialize before/after
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<h2>hello there<link href="./Category:A1" rel="mw:PageProp/Category" /></h2>
<h2><link href="./Category:A2" rel="mw:PageProp/Category" />hi pal</h2>

<h2><!--foo-->  <link href="./Category:A3" rel="mw:PageProp/Category" />   how goes it</h2>
<h2>it goes well   <link href="./Category:A4" rel="mw:PageProp/Category" />  <!--bar--></h2>

<h2><meta property="mw:PageProp/toc" /> ok</h2>
!! wikitext
== hello there ==
[[Category:A1]]
[[Category:A2]]

== hi pal ==

<!--foo-->  [[Category:A3]]

== how goes it ==

== it goes well ==
[[Category:A4]]  <!--bar-->

__TOC__

== ok ==
!! end

!! test
Headings: Don't hoist metas that come from templates
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<h2><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo [[Category:Foo]]"}},"i":0}}]}'>foo </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1" /></h2>
!! wikitext
== {{1x|foo [[Category:Foo]]}} ==
!! end

!! test
Serialize positional parameters with = in them as named parameter
!! options
parsoid=html2wt
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"}},"i":0}}]}'>foo</p>

<p about="#mwt1" typeof="mw:Transclusion"
data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"}, "2":{"wt":"bar"}},"i":0}}]}'>foo</p>

<!--Orig params with data-parsoid has heuristics for handling = chars-->
<!--FIXME: But maybe the heuristic needs fixing to apply to new params as well-->
<p data-parsoid='{"pi":[[{"k":"1"},{"k":"2"}]]}' about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"f=oo"},"2":{"wt":"bar"}},"i":0}}]}'>foo</p>
!! wikitext
{{1x|1=f=oo}}

{{1x|1=f=oo|2=bar}}

<!--Orig params with data-parsoid has heuristics for handling = chars-->
<!--FIXME: But maybe the heuristic needs fixing to apply to new params as well-->
{{1x|<nowiki>f=oo</nowiki>|bar}}
!! end

!! test
Serialize positional parameters with = in extlink as named parameter
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://stuff?is=ok" about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"http://stuff?is=ok"}},"i":0}}]}'>http://stuff?is=ok</a></p>
!! wikitext
{{1x|1=http://stuff?is=ok}}
!! end

!! test
Correctly serialize block-node children when they are a combination of text and p-nodes
!! options
parsoid=html2wt
!! html/parsoid
<div>a<p>b</p></div>
<div>a
<p>b</p></div>
<div>
a
<p>b</p></div>
!! wikitext
<div>a
b
</div>
<div>a
b
</div>
<div>
a

b
</div>
!! end

!! test
Substrings resembling wikitext in hrefs should not get nowiki escapes
!! options
parsoid=html2wt
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo''bar''baz">Foo''bar''baz</a>
!! wikitext
[[Foo''bar''baz]]
!! end

!! test
Enforce single-line context in the serializer
!! options
parsoid=html2wt
!! html/parsoid
<h2>testing
123</h2>

<h2> hi <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"bogus","href":"./Template:Bogus"},"params":{"1":{"wt":"there\nyou"}},"i":0}}]}'>there</span><span about="#mwt1">
</span><span about="#mwt1">you</span> </h2>

<h2> foo <span about="#mwt2" typeof="mw:Extension/spantag" data-mw='{"name":"spantag","body":{"extsrc":"hello\nthere"},"attrs":{}}'>hello
there</span> </h2>

<ul><li>asd
sdf</li></ul>

<ul><li>foo
bar
baz</li>
<li>foo <b>bar</b>
baz</li></ul>

<dl><dt>hi
ho </dt><dd data-parsoid='{"stx":"row"}'> hi
ho</dd></dl>

<dl><dd> <table>
<tbody><tr><td> ha
ha
ha</td></tr>
</tbody></table></dd></dl>
!! wikitext
== testing 123 ==

== hi {{bogus|there
you}} ==

== foo <spantag>hello
there</spantag> ==

* asd sdf

* foo bar baz
* foo '''bar''' baz

; hi ho : hi ho

: {|
| ha
ha
ha
|}
!! end

# Note that core parser doesn't like newlines in wikilinks in headings.
# But, Parsoid handles it just fine. We'll consider this acceptable divergence.
# We can change behavior if this becomes a real problem (ex: VE users start
# adding newlines in links in headings which then breaks rendering when rendered
# outside of Parsoid, or breaks section editing code). Eventually Parsoid will
# core parser everywhere and this inconsistency will go away.
!! test
Ignore single-line context for wikilinks
!! options
parsoid=html2wt
!! html/parsoid
<ul><li><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">
bar</a></li></ul>
<h2><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">
bar</a></h2>
<ul><li><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect">bar
<span style="background-color:green;
color:blue" data-parsoid='{"stx":"html"}'>x</span></a></li></ul>
!! wikitext
* [[Foo|
bar]]

== [[Foo|
bar]] ==

* [[Foo|bar
<span style="background-color:green;
color:blue">x</span>]]
!! end

!! test
Selser: Ignore single-line context for wikilinks
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
     [ "ul > li ", "append", "<ul><li>foo</li></ul>" ]
  ]
}
!! wikitext
* [[Foo|
bar]]
!! wikitext/edited
* [[Foo|
bar]]
** foo
!! end

!! test
Serialize new displayspace spans
!! options
parsoid=html2wt
!! html/parsoid
<p>foo<span typeof="mw:DisplaySpace"> </span>: bar</p>

<p>foo<span typeof="mw:DisplaySpace"> </span>: bar</p>

<p><span typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"foo : bar"}}'>foo<span typeof="mw:DisplaySpace"> </span>: bar</span>ok</p>

<a href="http://example.com">«<span typeof="mw:DisplaySpace">&nsbp;</span>Tour Eiffel<span typeof="mw:DisplaySpace">&nsbp;</span>»</a>

Hello<span typeof="mw:DisplaySpace">&nbsp;</span>World!

<ul>
<li><span typeof="mw:DisplaySpace">&nbsp;</span>Foo</li>
</ul>
!! wikitext
foo : bar

foo : bar

<spantag>foo : bar</spantag>ok

[http://example.com « Tour Eiffel »]

Hello World!

*  Foo
!! end

!!test
Support <object> element with .data attribute
!!options
parsoid=html2wt
!! html/parsoid
<object data="test.swf"></object>
!! wikitext
<object data="test.swf"></object>
!!end

#-----------------------
# Tag minimization tests
#-----------------------

!! test
1. I/B quote minimization: wikitext-only tags should be combined
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i>B</i></p>
<p><b>A</b><b>B</b></p>
<p><i>A</i><b><i>B</i></b></p>
<p><b>A</b><i><b>B</b></i></p>
<p><b>A</b><i><b>B</b><b>C</b></i><b>D</b></p>
<p><i><b>A</b></i><i><b>B</b></i></p>
<p><i><b>A</b></i><b><i>B</i></b></p>
<p><b><i>A</i></b><i><b>B</b></i></p>
!! wikitext
''AB''

'''AB'''

''A'''B'''''

'''A''B'''''

'''A''BC''D'''

'''''AB'''''

'''''AB'''''

'''''AB'''''
!! end

!! test
2. I/B quote minimization: wikitext and html tags should not be combined
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i data-parsoid='{"stx":"html"}'>B</i></p>
<p><i>A</i><b><i data-parsoid='{"stx":"html"}'>B</i></b></p>
!! wikitext
''A''<i>B</i>

''A''<nowiki/>'''<i>B</i>'''
!! end

!! test
3. I/B quote minimization: templated content stops minimization
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&#39;&#39;B&#39;&#39;"}},"i":0}}]}'>B</i>
<p><i>A</i><b about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&#39;&#39;&#39;&#39;&#39;B&#39;&#39;&#39;&#39;&#39;"}},"i":0}}]}'><i>B</i></b>
!! wikitext
''A''{{1x|''B''}}

''A''{{1x|'''''B'''''}}
!! end

!! test
4. I/B quote minimization: new content should be minimized with adjacent old content
!! options
parsoid=html2wt
!! html/parsoid
<p><i>A</i><i>B</i></p>
<p><b>A</b><b>B</b></p>
<p><i>A</i><b><i>B</i></b></p>
!! wikitext
''AB''

'''AB'''

''A'''B'''''
!! end

!! test
5a. Merge adjacent quote nodes if they've been edited
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["p", "contents", "remove", ":contains('b')"]
  ]
}
!! wikitext
''a''b''c''
!! wikitext/edited
''ac''
!! end

!! test
5b. Merge adjacent quote nodes if they've been edited
!! options
parsoid={
  "modes": ["wt2wt", "selser"],
  "changes": [
    ["#x", "remove"]
  ]
}
!! wikitext
''a''<span id="x">b</span>''c''
!! wikitext/edited
''ac''
!! end

!! test
1. Merge adjacent link nodes as long as at least one element is new
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football">Foot</a><a rel="mw:WikiLink" href="./Football">ball</a>
<a data-parsoid="{}" rel="mw:WikiLink" href="./Football">Foot</a><a rel="mw:WikiLink" href="./Football">ball</a>
<a data-parsoid="{}" rel="mw:WikiLink" href="./Football">Foot</a><a data-parsoid="{}" rel="mw:WikiLink" href="./Football">ball</a>
!! wikitext
[[Football]]
[[Football]]
[[Football|Foot]][[Football|ball]]
!! end

!! test
2. Merge adjacent link nodes and enable additional normalizations
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i>Foot</i></a><a rel="mw:WikiLink" href="./Football"><i>ball</i></a>
!! wikitext
''[[Football]]''
!! end

!! test
1. Move format tags outside of WikiLink
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i>Football</i></a>
<a rel="mw:WikiLink" href="./Football"><i><b>Football</b></i></a>
<a rel="mw:WikiLink" href="./Football"><u><i><b>Football</b></i></u></a>
!! wikitext
''[[Football]]''
'''''[[Football]]'''''
<u>'''''[[Football]]'''''</u>
!! end

!! test
2. Move format tags outside of WikiLink with mergeable A tags
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Football"><i><b>Foot</b></i></a><a rel="mw:WikiLink" href="./Football"><i><b>ball</b></i></a>
!! wikitext
'''''[[Football]]'''''
!! end

!! test
3. Move format tags outside of WikiLink while preserving formats already outside WikiLink
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<font color="red"><a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><u><b>Foo</b></u></a></font>
!! wikitext
<font color="red"><u>'''[[Foo]]'''</u></font>
!! end

!! test
4. Do not move format tags outside of WikiLink which includes attributes color, style and class
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><font color="red">Foo</font></a>
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><span style="color: blue; font-size: 46px;">Foo></span></a>
<a rel="mw:WikiLink" href="./Foo" title="Foo" class="mw-redirect"><span class="Bar">Foo</span></a>
!! wikitext
[[Foo|<font color="red">Foo</font>]]
[[Foo|<span style="color: blue; font-size: 46px;">Foo></span>]]
[[Foo|<span class="Bar">Foo</span>]]
!! end

!! test
5. T194083 Regression test: Manual edit test to move format tags outside wikilinks
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["a", "html", "<i>Foo</i>"]
  ]
}
!! wikitext
[[Foo]]
!! wikitext/edited
''[[Foo]]''
!! end

!! test
6. Regression test: Manual edit test to ensure diff markers are not lost
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["i", "wrap", "<a href='./Foo' rel='mw:WikiLink'></a>"]
  ]
}
!! wikitext
''Foo''
!! wikitext/edited
''[[Foo]]''
!! end

!! test
7. T194083 Regression test: Manual edit test to ensure nested diff markers aren't inserted
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["div", "after", "\n<p><a href='./Foo' rel='mw:WikiLink'>Foo </a>, placeholder</p>"]
  ]
}
!! wikitext
<div>placeholder</div>
!! wikitext/edited
<div>placeholder</div>
[[Foo]] , placeholder
!! end

!! test
8. T409669 Regression test: Manual edit test to move format tags outside wikilinks with spaces in target
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["a", "html", "<i>Foo bar baz</i>"]
  ]
}
!! wikitext
[[Foo bar baz]]
!! wikitext/edited
''[[Foo bar baz]]''
!! end

!! test
9. T409669 Regression test: Don't move out format tags when originating as piped
!! wikitext
[[Foo bar baz|''Foo bar baz'']]
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Foo_bar_baz" title="Foo bar baz" data-parsoid='{"stx":"piped"}'><i>Foo bar baz</i></a></p>
!! end

!! test
10. T409669 Regression test: Don't move out format tags when originating as piped unless in edited content
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["a", "html", "<i>Foo bar baz</i>"]
  ]
}
!! wikitext
[[Foo bar baz|Something else]]
!! wikitext/edited
''[[Foo bar baz]]''
!! end

## No sort-key or templated sort-key
# The conflicting category sort keys cause the
# 'prevent-selective-update' flag to be set; see
# [[mw:Parsoid/Internals/Handling_resource_limits]]
!! test
T192913 Regression test: 1. html2wt of links should not trip on parser functions found in target
!! options
parsoid
showflags
!! wikitext
[[Category:Bugs-{{#if:blah|Regression|None}}]]
[[Category:Bugs-{{#if:blah|Regression|None}}|{{#if:blah|2020|None}}-#fragment]]
!! metadata/parsoid
flags=prevent-selective-update
!! html/parsoid
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}]]}'/>
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression#2020-%23fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}],[{"txt":"mw:sortKey"},{"html":"&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"2020\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>2020&lt;/span>-#fragment"}]]}'/>
!! end

## Untemplated sort-key (wt2html data-mw is missing sort-key information!)
!! test
T192913 Regression test: 2. html2wt of links should not trip on parser functions found in target (2)
!! options
parsoid
!! wikitext
[[Category:Bugs-{{#if:blah|Regression|None}}|fragment]]
[[Category:Bugs-{{#if:blah|Regression|None}}-{{#if:blah|2020|None}}|fragment]]
!! html/parsoid
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression#fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>"}]]}'/>
<link typeof="mw:ExpandedAttrs" rel="mw:PageProp/Category" href="./Category:Bugs-Regression-2020#fragment" data-mw='{"attribs":[[{"txt":"href"},{"html":"Category:Bugs-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"Regression\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>Regression&lt;/span>-&lt;span typeof=\"mw:Transclusion\" data-mw=&apos;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"#if:blah\",\"function\":\"if\"},\"params\":{\"1\":{\"wt\":\"2020\"},\"2\":{\"wt\":\"None\"}},\"i\":0}}]}&apos;>2020&lt;/span>"}]]}'/>
!! end

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

#------------------------------
# End of tag minimization tests
#------------------------------

!!test
T56262: New entities
!! options
parsoid=html2wt
!! html/parsoid
<span typeof="mw:Entity">&nbsp;</span>
!! wikitext
&nbsp;
!! end

!! test
Consecutive <pre>s should not get merged
!! options
parsoid=html2wt,html2html
!! html/parsoid
<pre>a</pre><pre>b</pre>

<pre>c
</pre><pre>
d</pre>

<pre>e

</pre><pre>

f</pre>
!! wikitext
 a

 b

 c

 d

 e
 

 
 f
!! end

!! test
WTS of autolinks with trailing/surrounding context
!! options
parsoid=html2wt
!! html/parsoid
<p><a href="http://cscott.net">http://cscott.net</a><b>foo</b></p>
<p><a href="http://cscott.net">http://cscott.net</a><b data-parsoid='{"stx":"html"}'>foo</b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a></b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a> </b></p>
<p><b><a href="http://cscott.net">http://cscott.net</a>x</b></p>
<p><a href="http://cscott.net">http://cscott.net</a>x</p>
!! wikitext
http://cscott.net'''foo'''

http://cscott.net<b>foo</b>

'''http://cscott.net'''

'''http://cscott.net '''

'''http://cscott.net<nowiki/>x'''

http://cscott.net<nowiki/>x
!! end

!! test
WTS of autolinks with nowikis (round-trip)
!! wikitext
x<nowiki/>http://cscott.net<nowiki/>x
!! html/parsoid
<p>x<span typeof="mw:Nowiki"></span><a rel="mw:ExtLink nofollow" href="http://cscott.net" class="external free">http://cscott.net</a><span typeof="mw:Nowiki"></span>x</p>
!! end

# this is the "easy" test because it leaves in place all the
# data-parsoid information indicating this is an autolink
!! test
WTS of autolinks with escapes (editing)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "span", "remove" ]
  ]
}
!! wikitext
x<nowiki/>http://cscott.net<nowiki/>x
!! wikitext/edited
x<nowiki/>http://cscott.net<nowiki/>x
!! end

!! test
WTS of edited autolink-like text (T103364)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "span[typeof]", "removeAttr", "typeof" ]
  ]
}
!! wikitext
Not a link: <nowiki>http://example.com</nowiki>.
!! wikitext/edited
Not a link: <span><nowiki>http://example.com</nowiki></span>.
!! end

!! test
WTS of newly-authored autolink-like text (T103364)
!! options
parsoid=html2wt
!! html/parsoid
<p>http://example.com is not a link.</p>
!! wikitext
<nowiki>http://example.com</nowiki> is not a link.
!! end

!! test
WTS of autolink-like text after an autolink (T108563)
!! options
parsoid=html2wt
!! html/parsoid
<p><a rel="mw:ExtLink" href="http://example.com">http://example.com</a> http://example.com is not a link.</p>
!! wikitext
http://example.com <nowiki>http://example.com</nowiki> is not a link.
!! end

!! test
WTS of an autolink surrounded by square brackets (T220018)
!! options
parsoid=html2wt
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="http://example.com">http://example.com</a>]</p>
!! wikitext
<nowiki>[</nowiki>http://example.com]
!! end

!! test
WTS of edited autolink surrounded by square brackets (T220018)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "a", "before", "[" ],
    [ "a", "after", "]" ]
  ]
}
!! wikitext
http://example.com
!! wikitext/edited
<nowiki>[</nowiki>http://example.com]
!! end

!! test
WTS of an external link surrounded by square brackets (T220018)
!! options
parsoid=html2wt
!! html/parsoid
<p>[<a rel="mw:ExtLink" href="http://example.com">foo</a>]</p>
!! wikitext
<nowiki>[</nowiki>[http://example.com foo]]
!! end

!! test
WTS of edited external link surrounded by square brackets (T220018)
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "a", "before", "[" ],
    [ "a", "after", "]" ]
  ]
}
!! wikitext
[http://example.com foo]
!! wikitext/edited
<nowiki>[</nowiki>[http://example.com foo]]
!! end

!! test
Edited Redirect link should emit a non-piped wikitext link
!! options
parsoid=html2wt
!! html/parsoid
<link rel="mw:PageProp/redirect" href="Bar" data-parsoid='{"a":{"href":"./Foo"},"sa":{"href":"Foo"}}'>
!! wikitext
#REDIRECT [[Bar]]
!! end

!! test
T75121: Infer extension name from typeOf if data-mw is not present
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<div typeOf="mw:Extension/foo"></div>
!! wikitext
<foo />
!! end

# Note that the <p> wrapping isn't present in PHP parser output
# The important thing for this test is that P-wrapping doesn't
# interfere with the <nowiki> protection for leading - in <td>
# (which isn't necessary for <th>).
!! test
T88318: p-wrapped dash in table.
!! options
parsoid=html2wt,wt2wt
!! html/parsoid
<table><tbody>
<tr><th><p>-</p></th><th><p>- </p></th></tr>
<tr><td><p>-</p></td><td><p>- </p></td></tr>
<tr><td><small>-</small></td><td><br/><p>-</p></td><td><br/>-</td></tr>
</tbody></table>
!! wikitext
{|
!-
!- 
|-
|<nowiki>-</nowiki>
|<nowiki>- </nowiki>
|-
|<small>-</small>
|<br />
-
|<br />-
|}
!! html/php
<table>
<tbody><tr>
<th>-
</th>
<th>-
</th></tr>
<tr>
<td>-
</td>
<td>- 
</td></tr>
<tr>
<td><small>-</small>
</td>
<td><br />
<p>-
</p>
</td>
<td><br />-
</td></tr></tbody></table>
!! end

!! test
T149209: WTS: Handle newlines in table cells properly
!! options
parsoid=html2wt
!! html/parsoid
<table>
<tbody>
<tr><td>a
b
</td><td data-parsoid='{"stx":"row"}'>c</td></tr>
<tr><td><p>x</p>
</td><td data-parsoid='{"stx":"row", "startTagSrc": "{{!}}{{!}}"}'>y</td></tr>
</tbody></table>
<table>
<tbody>
<tr><th>a
b
</th><th data-parsoid='{"stx":"row"}'>c</th></tr>
<tr><th><p>x</h>
</th><th data-parsoid='{"stx":"row"}'>y</th></tr>
</tbody></table>
!! wikitext
{|
|a
b
|c
|-
|x
{{!}}y
|}
{|
!a
b
!c
|-
!x
!y
|}
!! end

!! test
T149209: Selser: Handle newlines in table cells properly
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#h1", "html", "a\nb\n" ],
    [ "#h2", "html", "a\nb\n" ],
    [ "#c1", "html", "a\nb\n" ],
    [ "#c2", "html", "<p>a</p>" ],
    [ "#c3", "html", "<p>a</p>" ],
    [ "#c4", "html", "edit-me<p>a</p>" ]
  ]
}
!! wikitext
{|
! id="h1" |edit-me!!1
|-
! id="h2" |edit-me||2
|-
| id="c1" |edit-me||3
|-
| id="c2" |edit-me||4
|-
| id="c3" |edit-me||p||q||r
|-
| id="c4" |edit-me||p||q||r
|}
!! wikitext/edited
{|
! id="h1" |a
b
!1
|-
! id="h2" |a
b
!2
|-
| id="c1" |a
b
|3
|-
| id="c2" |a
|4
|-
| id="c3" |a
|p||q||r
|-
| id="c4" |edit-me
a
|p||q||r
|}
!! end

!! test
HTML id attribute with Parsoid-like element ids should not be serialized to wikitext
!! options
parsoid=html2wt
!! html/parsoid
<table id='mwAb'>
<td id='mwAc'>foo</td>
<td id='serialize-this'>bar</td>
</table>
!! wikitext
{|
|foo
| id="serialize-this" |bar
|}
!! end

!! test
Parsoid-like element ids should not be serialized to wikitext unless shadowed
!! options
parsoid=html2wt
!! html/parsoid
<div id="mwAQ" data-parsoid='{"stx":"html","a":{"id":"mwAQ"},"sa":{"id":"hello"}}'>ok</div>
!! wikitext
<div id="hello">ok</div>
!! end

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

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

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

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

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

# Nested list should be inside <li>, that is
# <ul><li>foo<ul>..</ul></li></ul> instead of
# <ul><li>foo</li><ul>..</ul></ul>
# See https://stackoverflow.com/questions/5899337/proper-way-to-make-html-nested-list
!! test
Wikitext lists can be nested inside HTML lists
!! options
parsoid=html2wt
!! html/parsoid
<ul data-parsoid='{"stx": "html"}'>
<li data-parsoid='{"stx": "html"}'>a
<ul><li>b</li></ul>
</li>
</ul>

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

<ul>
<li>x
* y
</li>
</ul>
!! html/php
<ul>
<li>a
<ul><li>b</li></ul>
</li>
</ul>
<ul>
<li>x
<ul><li>y</li></ul>
</li>
</ul>
!! end

!! test
WTS change modes
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "#xyz", "before", "<b>before</b> stuff " ],
    [ "#xyz", "after", " stuff <i>after</i>" ],
    [ "#xyz", "html", "x <b>y</b> z" ]
  ]
}
!! wikitext
<span id="xyz">hello</span>
!! wikitext/edited
'''before''' stuff <span id="xyz">x '''y''' z</span> stuff ''after''
!! end

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

!! test
Never serialize a-tag as html, regardless of what data-parsoid has to say
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a rel="mw:WikiLink" href="./Foo" title="Foo" data-parsoid='{"stx":"html"}'>Foo</a>
!! wikitext
[[Foo]]
!! end

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

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

## SSS FIXME: This is broken output nevertheless.
## What might be a reasonable non-broken output for this?
## This is an edge case unlikely to be seen in production
## that I am not wasting more time on this right now.
!! test
Never serialize a-tag as html, no matter what attributes it has
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a bad='true' href='http://boo.org'><img src='http://boohoo.org' /></a>
!! wikitext
[http://boo.org http://boohoo.org]
!! end

# Misnested is an indication that selser can reuse the source but these have
# shown to sneak through on occasion. See T101768.
# The original wikitext here is: [http://test.com [[one]] two three]
!! test
Strip span tags added to mark misnested links
!! options
parsoid=html2wt
!! html/parsoid
<p data-parsoid='{}'><a rel="mw:ExtLink" href="http://test.com"></a><a rel="mw:WikiLink" href="./One" title="One" data-parsoid='{"stx":"simple","a":{"href":"./One"},"sa":{"href":"one"},"misnested":true}'>one</a><span data-parsoid='{"misnested":true}'> two three</span></p>
!! wikitext
[http://test.com][[one]] two three
!! end

!! test
Use data-parsoid.firstWikitextNode to compute newline constraints for template content
!! options
parsoid=html2wt
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span><table about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"a":{"{{1x|c\n{{!}}d\n}}":null},"sa":{"{{1x|c\n{{!}}d\n}}":""},"firstWikitextNode":"TABLE","pi":[[{"k":"1"}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"c\n{{!}}d\n"}},"i":0}},"\n|}"]}'>
<tbody><tr><td>d
</td></tr>
</tbody></table>
!! wikitext
{{1x|a}}
{|{{1x|c
{{!}}d
}}
|}
!! end

## This test verifies the presence and computation of this attribute indirectly
## by making an edit and ensuring that the serialization is correct (which it would be
## only if firstWikitextNode is properly set).
!! test
data-parsoid.firstWikitextNode should be computed properly in the presence of fostered content
!! options
parsoid= {
  "modes": ["wt2wt"],
  "changes": [
    [ "div#x", "remove" ],
    [ "div", "before", "<div>new</div>" ]
  ]
}
!! wikitext
<div id="x">foo</div>
{|
{{1x|<div>boo</div>
{{!}}b}}
|c
|}
!! wikitext/edited

<div>new</div>
{|
{{1x|<div>boo</div>
{{!}}b}}
|c
|}
!! end

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

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

!! test
Remove p tags surrounding a single element in a figcaption
!! options
parsoid=html2wt
!! wikitext
[[File:Foobar.jpg|right|200x200px|Caption]]
!! html/parsoid
<figure class="mw-halign-right" typeof="mw:File"><a href="./File:Foobar.jpg"><img resource="./File:Foobar.jpg" src="http://example.com/images/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="23" width="200"/></a><figcaption><p>Caption</p></figcaption></figure>
!! end

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

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

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

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

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

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

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

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

a&lt;nowiki /&gt;b

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

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

!! test
T199926: html arrow wt: Parsoid sometimes trips up on verticalbar chars in hrefs
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a href="https://stats.wikimedia.org/v2/#/fr.wikipedia.org/reading/page-views-by-country/normal|map|2-Year~2016060100~2018071100|~total">9</a>
<a href="https://stats.wikimedia.org/v2/#/fr.wikipedia.org/reading/page-views-by-country/normal%7Cmap%7C2-Year~2016060100~2018071100%7C~total">10</a>
!! wikitext
[[stats:v2/#/fr.wikipedia.org/reading/page-views-by-country/normal%7Cmap%7C2-Year~2016060100~2018071100%7C~total|9]]
[[stats:v2/#/fr.wikipedia.org/reading/page-views-by-country/normal%7Cmap%7C2-Year~2016060100~2018071100%7C~total|10]]
!! end

!! test
New element inserted (without intervening newlines) after an old sol-transparent node should serialize correctly
!! options
parsoid=html2wt
!! html/parsoid
<meta typeof="mw:Includes/IncludeOnly" data-parsoid='{"src":"&lt;includeonly>foo&lt;/includeonly>"}' data-mw='{"src":"&lt;includeonly>foo&lt;/includeonly>"}'/><meta typeof="mw:Includes/IncludeOnly/End" data-parsoid='{"src":""}'/><p>new para</p>

<link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{}'/><h1>new heading</h1>
!! wikitext
<includeonly>foo</includeonly>
new para

[[Category:Foo]]

= new heading =
!! end

## PHP emits broken html for this, and since this is primarily
## a Parsoid serializer test, marking this Parsoid only
!! test
Improperly nested inline or quotes tags with whitespace in between
!! options
parsoid=html2wt
!! html/parsoid
<p><span> <s>x</s></span><s> </s>
<b> <i>x</i></b><i> </i>
</p>
!! wikitext
<span> <s>x</s></span><s> </s>
''' ''x'''''
!! end

# --------------------------------------------
# Tests spec'ing wikitext serialization norms |
# --------------------------------------------

!! test
Serialize multi-line indent-pre starting with wikitext syntax
!! options
parsoid=html2wt
!! html/parsoid
<pre>* 1
** 2
* 3</pre>
!! wikitext
 * 1
 ** 2
 * 3
!! end

!! test
1. Categories should always be serialized on their own line
!! options
parsoid=html2wt
!! html/parsoid
foo<link rel="mw:PageProp/Category" href="./Category:Foo">bar
!! wikitext
foo
[[Category:Foo]]
bar
!! end

!! test
2. Categories that are part of templates should not introduce a line break
!! wikitext
foo {{1x|<span>bar</span> [[Category:baz]]}} bar
!! html/parsoid
<p>foo <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;span>bar&lt;/span> [[Category:baz]]"}},"i":0}}]}'>bar</span><span about="#mwt1"> </span><link rel="mw:PageProp/Category" href="./Category:Baz" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:baz"}}'/> bar</p>
!! end

# Careful while editing these next 2 tests. There are \u200f characters
# before and after the <link> tags in the HTML and following some
# of the categories in wikitext
# Do not remove these characters in edits.
#
# As part of the serialization, these bidi characters will get stripped.
!! test
RTL (\u200f) and LTR (\u200e) markers around category tags should be stripped
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<p>‏<link rel="mw:PageProp/Category" href="./קטגוריה:טקסים" />‏
‏<link rel="mw:PageProp/Category" href="./קטגוריה:_שיטות_משפט" />‏</p>
!! wikitext
[[קטגוריה:טקסים]]
[[קטגוריה: שיטות משפט]]
!! end

!! test
RTL (\u200f) and LTR (\u200e) markers should not be stripped if followed by a text node
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<p>‏<link rel="mw:PageProp/Category" href="./קטגוריה:טקסים" />‏y</p>
!! wikitext
[[קטגוריה:טקסים]]
‏y
!! end

!! test
Lists: Add space after bullets
!! options
parsoid=html2wt
!! html/parsoid
<ul>
<li>foo</li>
<li> bar</li>
<li><span> baz</span></li>
</ul>
!! wikitext
* foo
* bar
* <span> baz</span>
!! end

!! test
1. Headings: Add space before/after == (T53744)
!! options
parsoid=html2wt
!! html/parsoid
<h2>foo</h2>
<h2> bar</h2>
<h2>baz </h2>
<h2><span> baz</span></h2>
!! wikitext
== foo ==

== bar ==

== baz ==

== <span> baz</span> ==
!! end

!! test
2. Headings: Add space before/after == even after hoisted content
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<h2> <link href="./Category:A2" rel="mw:PageProp/Category" />ok</h2>
!! wikitext
[[Category:A2]]

== ok ==
!! end

!! test
1. Headings: suppress newly created empty headings
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<h2></h2>
!! wikitext
!! end

!! test
2. Headings: suppress empty headings on edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
==<span id="x">foo</span>==
!! wikitext/edited
!! end

!! test
Headings: Replace <br/> with a single whitespace char
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<h2>foo<br/>bar</h2>
<h2>foo <span><br/>bar</span> baz</h2>
!! wikitext
== foo bar ==

== foo <span> bar</span> baz ==
!! end

!! test
1. WT Quote Tags: suppress newly created empty style tags
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<i></i><b></b>
!! wikitext
!! end

!! test
2. WT Quote Tags: suppress empty style tags on edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
'''<span id="x">foo</span>'''
!! wikitext/edited
!! end

!! test
1. Anchors: suppress newly created empty anchors
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<a rel="mw:WikiLink" href="./Test" title="Test"></a>
!! wikitext
!! end

!! test
2. Anchors: suppress empty anchors on edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
[[Test|<span id="x">foo</span>]]
!! wikitext/edited
!! end

!! test
3a. Anchors: do not suppress numbered extlinks
!! options
parsoid={
  "modes": ["wt2wt"]
}
!! wikitext
[http://foo.com]
!! html/parsoid
<a rel="mw:ExtLink" href="http://foo.com"></a>
!! end

!! test
3b. Anchors: do not suppress numbered extlinks
!! options
parsoid={
  "modes": ["wt2wt"],
  "changes": [
    [ "#x", "remove"]
  ]
}
!! wikitext
[http://foo.com <span id="x">foo</span>]
!! wikitext/edited
[http://foo.com]
!! end

!!test
Normalizations should be restricted to edited content
!!options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "h1", "before", "<i></i>"]
  ]
}
!!wikitext
a
= =
b
!!wikitext/edited
a
= =
b
!!end

!! test
1. Multiple normalizations (html2wt)
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<h2><i></i></h2>
<p><a href='Foo' rel='mw:WikiLink'>foo<i></i>
 </a><b><i></i></b>x</p>
!! wikitext

[[foo]]
x
!! end

!! test
2. Multiple normalizations (selser)
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#x", "after", "<h1><i></i></h1>\n<p> bar<b></b></p>"]
  ]
}
!! wikitext
<div id="x">foo</div>
!! wikitext/edited
<div id="x">foo</div>
bar
!! end

!! test
1. Indent Pre Nowiki: suppress whitespace at the start of new paragraph
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<p> hi</p>
<p>    hello</p>
!! wikitext
hi

hello
!! end

!! test
2. Indent Pre Nowiki: suppress whitespace after newlines in new paragraph or table cell
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<p>Foo
 bar
baz</p>

<table><tr><td>Foo
 bar
 baz bang</td></tr></table>

<p><!--boo--> foo
 bar</p>

<p> foo
 bar<span>boo</span></p>
!! wikitext
Foo
bar
baz

{|
|Foo
bar
baz bang
|}

<!--boo-->foo
bar

foo
bar<span>boo</span>
!! end

!! test
3. Indent Pre Nowiki: suppress leading whitespace in edited paragraphs
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "p", "html", " a\n b" ]
  ]
}
!! wikitext
xyz
!! wikitext/edited
a
b
!! end

!! test
New links that end in spaces
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<p><a rel="mw:WikiLink" href="./Berlin" title="Berlin">Berlin </a>is the capital of Germany.</p>
<p><a rel="mw:WikiLink" href="./Foo" title="Foo">Foo </a><b>bar</b></p>
<p><a rel="mw:WikiLink" href="./Boston" title="Boston">Boston </a> is a city.</p>
!! wikitext
[[Berlin]] is the capital of Germany.

[[Foo]] '''bar'''

[[Boston]] is a city.
!! end

!! test
1. Table cells with escapable prefixes
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<table>
<tr><td>a</td></tr>
<tr><td>-</td></tr>
<tr><td>+</td></tr>
<tr><td>}</td></tr>
</table>
!! wikitext
{|
|a
|-
| -
|-
| +
|-
| }
|}
!! end

!! test
2a. Table cells with escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr:first-child td:first-child", "remove"]
  ]
}
!! wikitext
{|
|a||-
|}
!! wikitext/edited
{|
| -
|}
!! end

!! test
2b. Table cells with escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr:first-child td:first-child", "html", "-" ],
    [ "#x", "remove" ]
  ]
}
!! wikitext
{|
|pqr
|<span id="x">foo</span>+
|}
!! wikitext/edited
{|
| -
| +
|}
!! end

# FIXME: This test will fail because
# normalization doesn't realize that the id attribute
# will eliminate the escapable scenario
!! test
3a. Table cells without escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#x", "html", "-" ]
  ]
}
!! wikitext
{|
| id="x" |abcd
|}
!! wikitext/edited
{|
| id="x" |-
|}
!! end

## This tests normalizer's ability to discriminate between
## cells having identical content.
!! test
3b. Table cells without escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "td", "html", "-" ]
  ]
}
!! wikitext
{|
|a||b
|}
!! wikitext/edited
{|
| -||-
|}
!! end

## This tests normalizer's ability to not be tripped by
## comments (and whitespace)
!! test
3c. Table cells without escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr td:first-child", "remove" ]
  ]
}
!! wikitext
{|
|-
<!--foo--> |a||-
|}
!! wikitext/edited
{|
|-
<!--foo--> | -
|}
!! end

## This tests normalizer's ability to handle HTML cells
!! test
3d. Table cells without escapable prefixes after edits
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "td", "html", "-" ]
  ]
}
!! wikitext
<table>
<tr><td>a</td></tr>
</table>
!! wikitext/edited
<table>
<tr><td>-</td></tr>
</table>
!! end

## T111151 Remove font elements without attributes
!! test
4. font tags without attributes should be dropped
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<font>foo</font>
<font><font>bar</font></font>
<font class="x">boo</font>
!! wikitext
foo
bar
<font class="x">boo</font>
!! end

!! test
Normalize empty paragraphs to HTML form that html2wt expects
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<div>1</div>
<p>a</p><p></p><p>b</p>
<div>2</div>
<p>a</p>
<p></p>
<p>b</p>
<div>3</div>
<p>a</p>
<p></p>
<p></p>
<p></p>
<p></p>
<p>b</p>
<div>4</div>
<p>a</p>
<p></p>
<div>foo</div>
!! wikitext
<div>1</div>
a


b
<div>2</div>
a


b
<div>3</div>
a





b
<div>4</div>
a

<div>foo</div>
!! html/php
<div>1</div>
<p>a
</p><p><br />
b
</p>
<div>2</div>
<p>a
</p><p><br />
b
</p>
<div>3</div>
<p>a
</p><p><br />
</p><p><br />
</p><p>b
</p>
<div>4</div>
<p>a
</p>
<div>foo</div>
!! end

!! test
Templated content should be skipped over by normalization
!! options
parsoid={
  "modes": ["html2wt"]
}
!! html/parsoid
<p about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SomeTemplate1","href":"./Template:SomeTemplate1"},"params":{"1":{"wt":"boo"}},"i":0}}]}'>foobar</p><p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"SomeTemplate2","href":"./Template:SomeTemplate2"},"params":{"1":{"wt":"booboo"}},"i":0}}]}'>foobar</p><span about="#mwt2">
</span><p about="#mwt2"></p><span about="#mwt2">
</span>
!! wikitext
{{SomeTemplate1|boo}}{{SomeTemplate2|booboo}}
!! end

!! test
Escape DOM elements
!! options
parsoid=html2wt
!! html/parsoid
<nowiki><i>foo</i></nowiki>
<noinclude><i>foo</i></noinclude>
<includeonly><i>foo</i></includeonly>
!! wikitext
&lt;nowiki&gt;''foo''&lt;/nowiki&gt;
&lt;noinclude&gt;''foo''&lt;/noinclude&gt;
&lt;includeonly&gt;''foo''&lt;/includeonly&gt;
!! end

!! test
Don't escape pre elements that fail to parse as extension tags
!! wikitext
<pre>closed is extension tag, so everything is <span>text</span></pre>
<pre>unclosed is not, so these are <span>tags</span>
!! html/php
<pre>closed is extension tag, so everything is &lt;span&gt;text&lt;/span&gt;</pre>
<pre>unclosed is not, so these are <span>tags</span></pre>
!! html/parsoid
<pre typeof="mw:Extension/pre" about="#mwt3" data-mw='{"name":"pre","attrs":{},"body":{"extsrc":"closed is extension tag, so everything is &lt;span>text&lt;/span>"}}'>closed is extension tag, so everything is &lt;span>text&lt;/span></pre>
<pre data-parsoid='{"stx":"html","autoInsertedEnd":true}'>unclosed is not, so these are <span>tags</span></pre>
!! end

!! test
New list is serialized on newlines
!! options
parsoid=html2wt
!! html/parsoid
<p>The quick brown fox jumps over the lazy dog.</p><ul>
<li>Yesterday</li>
<li>Today</li>
<li>Tomorrow</li>
</ul><p>The quick onyx goblin jumps over the lazy dwarf.</p>
!! wikitext
The quick brown fox jumps over the lazy dog.

* Yesterday
* Today
* Tomorrow

The quick onyx goblin jumps over the lazy dwarf.
!! end

!! test
New lists in formatting elements serialized w/o newlines
!! options
parsoid=html2wt
!! html/parsoid
<small>

<ul>
<li>123</li>
</ul>

</small>

<small><ul><li>hi</li></ul></small>
!! wikitext
<small>
* 123
</small>

<small>
* hi
</small>
!! end

!! test
New list in table doesn't need newlines
!! options
parsoid=html2wt
!! html/parsoid
<table><tr><td><ul><li>test</li><li>123</li></td></tr></table>
!! wikitext
{|
|
* test
* 123
|}
!! end

!! test
Newly inserted noinclude tags do not need newlines before/after
!! html/parsoid
<p>a<meta typeof="mw:Includes/NoInclude">b<meta typeof="mw:Includes/NoInclude/End">c</p>
!! wikitext
a<noinclude>b</noinclude>c
!! end

!! test
List edge case: bare text after list on same line
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>x</li></ul> y
!! wikitext
* x
y
!! end

!! test
List edge case: list items without explicit list tag followed by bare text on same line
!! options
parsoid=html2wt
!! html/parsoid
<li>a</li> <!--x-->
<li>a</li> b
<li>a</li> <!--x--> b
!! wikitext
* a <!--x-->
* a
b
* a <!--x-->
b
!! end

# As seen on a ptwiki page
!! test
List edge case: Unclosed HTML bare list item should RT properly
!! options
parsoid=wt2html,wt2wt
!! wikitext
<li>a
#b
!! html/parsoid
<li data-parsoid='{"stx":"html"}'>a
<ol><li>b</li></ol></li>
!! end

# ---------------------------------------------------
# End of tests spec'ing wikitext serialization norms |
# ---------------------------------------------------

# T104032
!! test
Bare inline nodes not wrapped inside p-tags should be treated as p-wrapped
!! options
parsoid=html2wt
!! html/parsoid
a<p>b</p>
<b>c</b><p>d</p>
<table><tr>
<td>a<p>b</p></td>
<td><b>c</b><p>d</p></td>
</tr></table>
!! wikitext
a

b

'''c'''

d
{|
|a
b
|'''c'''
d
|}
!! end

!! test
Anchor without href scenarios
!! options
parsoid={ "modes": ["html2wt"], "suppressErrors": true }
!! html/parsoid
<a class="bc"></a>
<a class="no">dice</a>
<a name="foo"></a>
!! wikitext

dice
<span name="foo"></span>
!! end

!! test
New transclusion added after a list should be serialized after the list
!! options
parsoid=html2wt
!! html/parsoid
<ul><li>a</li></ul><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo"}},"i":0}}]}'>foo</span>
!! wikitext
* a
{{1x|foo}}
!! end

## FIXME: This test is less useful now that the leading space is normalized away
!! test
Only html p-tag is strong indent pre suppressing
!! options
parsoid=html2wt
!! html/parsoid
<p>test2<span>
 test3
</span></p>
!! wikitext
test2<span>
test3
</span>
!! end

# Clients like VE don't know about this property (T238721)
!! test
T238721: New transclusion without the "i" property for a template part should be handled properly
!! options
parsoid=html2wt
!! html/parsoid
<span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"}}}]}'>foo</span>
!! wikitext
{{1x}}
!! end

# -----------------------------------------------------------------
# End of section for Parsoid-only html2wt tests for serialization
# of new content
# -----------------------------------------------------------------

# -----------------------------------------------------------------
# The following section of tests are primarily to spec behavior of
# the selective serializer. All these tests have manual selser
# changes. The automated selser changes for all tests handle the
# wide variation of changes, but these tests here capture specs
# deterministically.
# ----------------------------------------------------------------

## T90517
!! test
Selser: New comments should not be lost
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "#a", "after", "<!--c1-->" ],
    [ "#b", "before", "<!--c2-->" ]
  ]
}
!! wikitext
<span id="a">a</span>

<span id="b">b</span>
!! wikitext/edited
<span id="a">a</span><!--c1-->

<!--c2--><span id="b">b</span>
!! end

!! test
DOMDiff: Edits to content nested in elements with templated attributes should not be lost (T139388)
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "div:first-child", "text", "bar" ]
  ]
}
!! wikitext
<div style="{{1x|color:red;}}%">foo</div>
!! wikitext/edited
<div style="{{1x|color:red;}}%">bar</div>
!! end

!! test
Selser preserves lack of newline before list and allows newline after the list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "ul", "after", "<p>footer</p>" ]
  ]
}
!! wikitext
header
*foo
*bar
!! wikitext/edited
header
*foo
*bar
footer
!! end

!! test
Selser does not introduce newlines between unedited paragraph preceding the list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr td p:last-child", "empty" ]
  ]
}
!! wikitext
{|
|
header
*foo
*bar
footer
|}
!! wikitext/edited
{|
|
header
*foo
*bar

|}
!! end

!! test
Selser does not introduce newlines between unedited paragraph following the list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    [ "table tbody tr td p:first-child", "empty" ]
  ]
}
!! wikitext
{|
|
header
*foo
*bar
footer
|}
!! wikitext/edited
{|
|
*foo
*bar
footer
|}
!! end

!! test
Remove a list item but do not insert newline above list
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
     [ "ul li:last-child", "remove" ]
  ]
}
!! wikitext
header
*foo
*bar
footer
!! wikitext/edited
header
*foo
footer
!! end

!! test
Spaced heading with element
!! options
parsoid={
  "modes": ["selser"],
  "changes": [
    ["#x", "attr", "class", "y"]
  ]
}
!! wikitext
=== hi <span id="x">hi</span> hi ho ===
!! wikitext/edited
=== hi <span id="x" class="y">hi</span> hi ho ===
!! end

!! test
Stripped tag in list
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
    ["dd", "append", "ho"]
  ]
}
!! wikitext
:<i>hi</i></b>
!! wikitext/edited
:<i>hi</i></b>ho
!! end

!! test
Misnested link nested in span
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
    ["dd", "append", " ho"]
  ]
}
!! wikitext
: [http://google.com <span>[[Lala]]:</span>ok]-hi
!! wikitext/edited
: [http://google.com <span>[[Lala]]:</span>ok]-hi ho
!! end

## From T290938, wrapper unmodified was prevented due to the auto-inserted end
!! test
Preserve the order invalid attributes
!! options
parsoid={
  "modes": ["selser"],
  "selser": "noauto",
  "changes": [
    ["div", "append", "ho"]
  ]
}
!! wikitext
<div width="95%" style="border: 3px solid darkblue">hi
!! wikitext/edited
<div width="95%" style="border: 3px solid darkblue">hiho
!! end
