# This file has tests to verify the following:
# - TOC section metadata output for wikitext snippets
# - Behavior of various *toc* magic words
# - Various edge cases related to heading parsing and TOC behavior
#   (special chars, language variants, entities, bdi chars, etc.)
#
# NOTE about data-parsoid in html/parsoid
# - html/parsoid sections have data-parsoid="{}" to eliminate unnecessary
#   html2wt failures because of normalization
# - We could strip them eithre by marking those tests wt2html, wt2wt only

!! options
version=2
parsoid-compatible=wt2html,wt2wt
!! end

!! article
Main Page
!! text
blah blah
!! endarticle

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

!! article
Template:Test
!! text
==th2==
===th2.1===
!! endarticle

!! test
Basic test
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==h1==
===h1.1===
==h2==
===h2.1===
====h2.1.1====
===h2.2===
====h2.2.1====
====h2.2.2====
==h3==
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:h1 line:h1
  h3 index:2 toclevel:2 number:1.1 title:Parser_test off:7 anchor/linkAnchor:h1.1 line:h1.1
 h2 index:3 toclevel:1 number:2 title:Parser_test off:18 anchor/linkAnchor:h2 line:h2
  h3 index:4 toclevel:2 number:2.1 title:Parser_test off:25 anchor/linkAnchor:h2.1 line:h2.1
   h4 index:5 toclevel:3 number:2.1.1 title:Parser_test off:36 anchor/linkAnchor:h2.1.1 line:h2.1.1
  h3 index:6 toclevel:2 number:2.2 title:Parser_test off:51 anchor/linkAnchor:h2.2 line:h2.2
   h4 index:7 toclevel:3 number:2.2.1 title:Parser_test off:62 anchor/linkAnchor:h2.2.1 line:h2.2.1
   h4 index:8 toclevel:3 number:2.2.2 title:Parser_test off:77 anchor/linkAnchor:h2.2.2 line:h2.2.2
 h2 index:9 toclevel:1 number:3 title:Parser_test off:92 anchor/linkAnchor:h3 line:h3
!! end

!! test
HTML headings should get TOC entries with some empty properties
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==a==
<h2>b</h2>
<h3>c</h3>
===d===
<h2>e</h2>
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:a line:a
 h2 index: toclevel:1 number:2 title:NULL off:NULL anchor/linkAnchor:b line:b
  h3 index: toclevel:2 number:2.1 title:NULL off:NULL anchor/linkAnchor:c line:c
  h3 index:2 toclevel:2 number:2.2 title:Parser_test off:28 anchor/linkAnchor:d line:d
 h2 index: toclevel:1 number:3 title:NULL off:NULL anchor/linkAnchor:e line:e
!! end

!! test
Literal html heading from template
!! options
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{1x|
<h2>hi</h2>
ho
}}
!! html/php
<div class="mw-heading mw-heading2"><h2 id="hi">hi</h2></div>
<p>ho
</p>
!! html/parsoid
<section data-mw-section-id="0"></section><section data-mw-section-id="-1"><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n&lt;h2>hi&lt;/h2>\nho\n"}},"i":0}}]}'>
</span><h2 about="#mwt1" id="hi">hi</h2><span about="#mwt1">
</span><p about="#mwt1">ho</p><span about="#mwt1">
</span></section>
!! metadata
Sections:
 h2 index: toclevel:1 number:1 title:NULL off:NULL anchor/linkAnchor:hi line:hi
!! end

!! test
Duplicate headings should get unique anchors
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==a==
==a==
==b==
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:a line:a
 h2 index:2 toclevel:1 number:2 title:Parser_test off:6 anchor/linkAnchor:a_2 line:a
 h2 index:3 toclevel:1 number:3 title:Parser_test off:12 anchor/linkAnchor:b line:b
!! end

!! test
Templated sections (heading from template content)
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==a==
{{Test}}
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:a line:a
 h2 index:T-1 toclevel:1 number:2 title:Template:Test off:NULL anchor/linkAnchor:th2 line:th2
  h3 index:T-2 toclevel:2 number:2.1 title:Template:Test off:NULL anchor/linkAnchor:th2.1 line:th2.1
!! end

!! test
Ensure headings with html tags get the right anchors
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==<span>x</span>==
==<strike>y</strike>==
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:x line:<span>x</span>
 h2 index:2 toclevel:1 number:2 title:Parser_test off:19 anchor/linkAnchor:y line:<strike>y</strike>
!! end

!! test
Ensure unallowed tag wrappers in headings get stripped
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==<div>b</div>==
==<font>c</font>==
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:b line:b
 h2 index:2 toclevel:1 number:2 title:Parser_test off:17 anchor/linkAnchor:c line:c
!! end

!! test
Ensure disallowed attributes are stripped, but dir attribute in a span is left behind
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==<span dir='ltr' title='x'>a</span>==
==<span dir='rtl' title='x'>b</span>==
==<i dir='rtl' title='ha'>c</i>==
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:a line:<span dir="ltr">a</span>
 h2 index:2 toclevel:1 number:2 title:Parser_test off:39 anchor/linkAnchor:b line:<span dir="rtl">b</span>
 h2 index:3 toclevel:1 number:3 title:Parser_test off:78 anchor/linkAnchor:c line:<i>c</i>
!! end

# Legacy parser behavior is broken. Parsoid's output is correct.
!! test
Ensure empty tags are stripped
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==<span><div></div></span>x==
==<span dir='ltr'><i dir='ltr'></i></span>y==
!! metadata/php
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:x line:x
 h2 index:2 toclevel:1 number:2 title:Parser_test off:30 anchor/linkAnchor:y line:<span dir="ltr"><i></i></span>y
!! metadata/parsoid
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:x line:x
 h2 index:2 toclevel:1 number:2 title:Parser_test off:30 anchor/linkAnchor:y line:y
!! end

!! test
Ensure tags following empty tags are stripped
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! wikitext
==<div></div>x==
==<abbr><abbr></abbr></abbr><abbr><abbr title="abbr title">y</abbr></abbr>z==
!! metadata/php
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:x line:x
 h2 index:2 toclevel:1 number:2 title:Parser_test off:17 anchor/linkAnchor:yz line:yz
!! metadata/parsoid
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:x line:x
 h2 index:2 toclevel:1 number:2 title:Parser_test off:17 anchor/linkAnchor:yz line:yz
!! end

!! test
Ensure comments in toc lines are stripped
!! config
wgRawHtml=1
wgParserEnableLegacyHeadingDOM=false
!! options
nohtml
showtocdata
!! wikitext
==hi<html><!--ho--></html>==
!! metadata/php
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:hi line:hi
!! end

!! test
Handle links in heading content
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==[[Cat]]==
==[[Dog]]s==
==[[Cat|I love my ''cat'']]==
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:Cat line:Cat
 h2 index:2 toclevel:1 number:2 title:Parser_test off:12 anchor/linkAnchor:Dogs line:Dogs
 h2 index:3 toclevel:1 number:3 title:Parser_test off:25 anchor/linkAnchor:I_love_my_cat line:I love my <i>cat</i>
!! end

# Parsoid uses HTML5 semantics for anchors as the default.
# Legacy parser tests require wgFragmentMode=[ "html5" ] for the same
# behavior, which isn't (yet) the default in ParserTestRunner
!! test
Ensure headings with special chars get the right anchors
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
===a=
=''x''=
!! metadata
Sections:
 h1 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:==a line:==a
 h1 index:2 toclevel:1 number:2 title:Parser_test off:6 anchor/linkAnchor:x line:<i>x</i>
!! end

# For heading that come from template args, core, Parsoid-standalone, and
# Parsoid-integrate different in ther "index" output.
#
# - For templated sections, Parsoid and core differ in some of the metadata.
#   Parsoid doesn't distinguish between sections that come from template args
#   and from templated content - it treats them all as template-generated headings.
#   But core does not consider headings from template-args as "inTemplate", but
#   'fromtitle' is set to false even so.
#
# - Parsoid's behavior is more consistent wrt templates. But, this is potentially
#   a breaking change for users of TOC data. The index for templated
#   content is used to generate section edit links for content coming
#   from a template, and in updating the appropriate article when that
#   section is saved.  So this is potentially a breaking change when
#   Parsoid starts to generate section edit links, and possible one
#   which could cause db corruption.
#
# - Additionally, heading-index is reset in integrated mode because templates are
#   processed by core preprocessor whereas in native preprocessing mode (used by
#   parsertests), the heading index is not reset.
# - See also T222419.
!! test
Templated sections (heading from template arg)
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==a==
{{1x|1=
==b==
}}
!! metadata/php
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:a line:a
 h2 index: toclevel:1 number:2 title:NULL off:NULL anchor/linkAnchor:b line:b
!! metadata/parsoid+integrated
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:a line:a
 h2 index:T-1 toclevel:1 number:2 title:Template:1x off:NULL anchor/linkAnchor:b line:b
!! metadata/parsoid+standalone
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:a line:a
 h2 index:T-2 toclevel:1 number:2 title:Template:1x off:NULL anchor/linkAnchor:b line:b
!! end

!! test
Handle extension content in section headers properly (non-Cite version)
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! wikitext
==c<tag>d</tag>==
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:c'd'_array_(_) line:"c'd'\narray (\n)"
!! end

!! test
Offsets in toc metadata should be unicode codepoints, not bytes or UCS-2
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! options
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
showtocdata
nohtml
!! wikitext
==One 💩==
==Two 💩==
==Three 💩==
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:One_💩 line:One 💩
 h2 index:2 toclevel:1 number:2 title:Parser_test off:10 anchor/linkAnchor:Two_💩 line:Two 💩
 h2 index:3 toclevel:1 number:3 title:Parser_test off:20 anchor/linkAnchor:Three_💩 line:Three 💩
!! end

!! test
Handle multi-part content transclusion blocks
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
<div>
{{1x|1=
==foo==
</div>
}}
==bar==
!! metadata
Sections:
 h2 index: toclevel:1 number:1 title:NULL off:NULL anchor/linkAnchor:foo line:foo
 h2 index:2 toclevel:1 number:2 title:Parser_test off:32 anchor/linkAnchor:bar line:bar
!! end

# Parsoid's parser function implementation used for standalone testing
# is incomplete and only used in parser tests.
# So, use HTML h-tags instead of wikitext h-tags in the parser function
# to let us run this test in both standalone and integrated modes.
!! test
Handle parser functions generating sections
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{#if:1|<h2>foo</h2>|unused}}
==bar==
!! metadata
Sections:
 h2 index: toclevel:1 number:1 title:NULL off:NULL anchor/linkAnchor:foo line:foo
 h2 index:1 toclevel:1 number:2 title:Parser_test off:30 anchor/linkAnchor:bar line:bar
!! end

!! test
Handle top-level template args generating sections
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{{foo|
==tplarg==
|abcd}}}
!! metadata
Sections:
 h2 index: toclevel:1 number:1 title:NULL off:NULL anchor/linkAnchor:tplarg line:tplarg
!! end

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

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

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

==Headline 2==
Some text
===Another headline===
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Headline_1"><span class="tocnumber">1</span> <span class="toctext">Headline 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Subheadline_1"><span class="tocnumber">1.1</span> <span class="toctext">Subheadline 1</span></a>
<ul>
<li class="toclevel-3 tocsection-3"><a href="#Skipping_a_level"><span class="tocnumber">1.1.1</span> <span class="toctext">Skipping a level</span></a>
<ul>
<li class="toclevel-4 tocsection-4"><a href="#Skipping_a_level_2"><span class="tocnumber">1.1.1.1</span> <span class="toctext">Skipping a level</span></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#Headline_2"><span class="tocnumber">2</span> <span class="toctext">Headline 2</span></a>
<ul>
<li class="toclevel-2 tocsection-6"><a href="#Another_headline"><span class="tocnumber">2.1</span> <span class="toctext">Another headline</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Headline_1">Headline 1</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: Headline 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Subheadline_1">Subheadline 1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Subheadline 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading5"><h5 id="Skipping_a_level">Skipping a level</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Skipping a level">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading6"><h6 id="Skipping_a_level_2">Skipping a level</h6><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Skipping a level">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Headline_2">Headline 2</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>Some text
</p>
<div class="mw-heading mw-heading3"><h3 id="Another_headline">Another headline</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Another headline">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="Headline_1" data-parsoid="{}">Headline 1</h2>
<h3 id="Subheadline_1" data-parsoid="{}">Subheadline 1</h3>
<h5 id="Skipping_a_level" data-parsoid="{}">Skipping a level</h5>
<h6 id="Skipping_a_level_2" data-parsoid="{}">Skipping a level</h6>

<h2 id="Headline_2" data-parsoid="{}">Headline 2</h2>
<p data-parsoid="{}">Some text</p>
<h3 id="Another_headline" data-parsoid="{}">Another headline</h3>
!! end

!! test
Section headings with TOC and language conversion (T295187, T306862)
!! config
wgUsePigLatinVariant=true
wgParserEnableLegacyHeadingDOM=false
!! options
language=en htmlVariantLanguage=en-x-piglatin
!! wikitext
==Headline 1==
===Subheadline 1===
==Headline 2==
Some text
===Another headline===
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en-x-piglatin" dir="ltr"><h2 id="mw-toc-heading">Ontentscay</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Headline_1"><span class="tocnumber">1</span> <span class="toctext">Eadlinehay 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Subheadline_1"><span class="tocnumber">1.1</span> <span class="toctext">Ubheadlinesay 1</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-3"><a href="#Headline_2"><span class="tocnumber">2</span> <span class="toctext">Eadlinehay 2</span></a>
<ul>
<li class="toclevel-2 tocsection-4"><a href="#Another_headline"><span class="tocnumber">2.1</span> <span class="toctext">Anotherway eadlinehay</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Headline_1">Eadlinehay 1</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: Eadlinehay 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Subheadline_1">Ubheadlinesay 1</h3><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: Ubheadlinesay 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Headline_2">Eadlinehay 2</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: Eadlinehay 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>Omesay exttay
</p>
<div class="mw-heading mw-heading3"><h3 id="Another_headline">Anotherway eadlinehay</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Anotherway eadlinehay">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="Headline_1" data-parsoid="{}">Headline 1</h2>
<h3 id="Subheadline_1" data-parsoid="{}">Subheadline 1</h3>
<h2 id="Headline_2" data-parsoid="{}">Headline 2</h2>
<p data-parsoid="{}">Some text</p>
<h3 id="Another_headline" data-parsoid="{}">Another headline</h3>
!! end

# Note that even though conversion of the *content* is disabled, the
# user interface messages (aka the TOC title) are still in the user's
# preferred UX variant (that is, pig latin).
!! test
Section headings with TOC and language conversion disabled (T295187)
!! config
wgUsePigLatinVariant=true
wgParserEnableLegacyHeadingDOM=false
!! options
language=en htmlVariantLanguage=en-x-piglatin
!! wikitext
==Headline 1==
===Subheadline 1===
==Headline 2==
Some text
===Another headline===
__NOCONTENTCONVERT__
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en-x-piglatin" dir="ltr"><h2 id="mw-toc-heading">Ontentscay</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Headline_1"><span class="tocnumber">1</span> <span class="toctext">Headline 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Subheadline_1"><span class="tocnumber">1.1</span> <span class="toctext">Subheadline 1</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-3"><a href="#Headline_2"><span class="tocnumber">2</span> <span class="toctext">Headline 2</span></a>
<ul>
<li class="toclevel-2 tocsection-4"><a href="#Another_headline"><span class="tocnumber">2.1</span> <span class="toctext">Another headline</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Headline_1">Headline 1</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: Headline 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Subheadline_1">Subheadline 1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Subheadline 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Headline_2">Headline 2</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: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>Some text
</p>
<div class="mw-heading mw-heading3"><h3 id="Another_headline">Another headline</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Another headline">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="Headline_1" data-parsoid="{}">Headline 1</h2>
<h3 id="Subheadline_1" data-parsoid="{}">Subheadline 1</h3>
<h2 id="Headline_2" data-parsoid="{}">Headline 2</h2>
<p data-parsoid="{}">Some text</p>
<h3 id="Another_headline" data-parsoid="{}">Another headline</h3>
<meta property="mw:PageProp/nocontentconvert" data-parsoid="{}" />
!! end

# The -{T}- below checks for regressions in T26072: the contents of
# the displaytitle should not be double-converted.  That is, we want
# the title to end up as 'Bar' not 'Ball' (aka converted by the -{H}-
# rule immediately preceding it).
!! test
Section headings with TOC, language conversion rules, and displaytitle
(T306862, T331316, T26072)
!! config
wgUsePigLatinVariant=true
wgRestrictDisplayTitle=false
wgParserEnableLegacyHeadingDOM=false
!! options
language=en htmlVariantLanguage=en-x-piglatin
showtitle
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! wikitext
<!--
-->-{H|Foo=>en:Boo;Foo=>en-x-piglatin:Bob;}-<!--
-->-{H|Bar=>en:Bat;Bar=>en-x-piglatin:Ball;}-<!--
-->-{T|en:Foo;en-x-piglatin:Bar;}-<!--
-->
Introduction.
-{A|en:Do; en-x-piglatin:Re;}-
== Foo ==
Foo Do
== Bar ==
Bar Re
== -{Foo Bar}- ==
!! metadata
Bar
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:192 anchor/linkAnchor:Foo line:Bob
 h2 index:2 toclevel:1 number:2 title:Parser_test off:209 anchor/linkAnchor:Bar line:Ball
 h2 index:3 toclevel:1 number:3 title:Parser_test off:226 anchor/linkAnchor:-.7BFoo_Bar.7D- line:Foo Bar
!! html/php
<p>
Introductionway.
Re
</p>
<div class="mw-heading mw-heading2"><h2 id="Foo">Bob</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: Bob">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>Bob Re
</p>
<div class="mw-heading mw-heading2"><h2 id="Bar">Ball</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: Ball">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>Ball Eray
</p>
<div class="mw-heading mw-heading2"><h2 id="-.7BFoo_Bar.7D-">Foo Bar</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: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid+standalone
<section data-mw-section-id="0"><!--
--><p>-{H|Foo=>en:Boo;Foo=>en-x-piglatin:Bob;}-<!--
-->-{H|Bar=>en:Bat;Bar=>en-x-piglatin:Ball;}-<!--
-->-{T|en:Foo;en-x-piglatin:Bar;}-<!--
-->
Introduction.
-{A|en:Do; en-x-piglatin:Re;}-</p>
</section><section data-mw-section-id="1"><h2 id="Foo">Foo</h2>
<p>Foo Do</p>
</section><section data-mw-section-id="2"><h2 id="Bar">Bar</h2>
<p>Bar Re</p>
</section><section data-mw-section-id="3"><h2 id="-{Foo_Bar}-"><span id="-.7BFoo_Bar.7D-" typeof="mw:FallbackId"></span>-{Foo Bar}-</h2></section>
!! html/parsoid+integrated
<section data-mw-section-id="0"><!--
--><p><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"Foo","l":"en","t":"Boo"},{"f":"Foo","l":"en-x-piglatin","t":"Bob"}]}'/><!--
--><meta typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"oneway":[{"f":"Bar","l":"en","t":"Bat"},{"f":"Bar","l":"en-x-piglatin","t":"Ball"}]}'/><!--
--><meta typeof="mw:LanguageVariant" data-mw-variant='{"title":true,"twoway":[{"l":"en","t":"Foo"},{"l":"en-x-piglatin","t":"Bar"}]}'/><!--
--> Introduction. <span typeof="mw:LanguageVariant" data-mw-variant='{"add":true,"twoway":[{"l":"en","t":"Do"},{"l":"en-x-piglatin","t":"Re"}]}'></span></p>
</section><section data-mw-section-id="1"><h2 id="Foo">Foo</h2>
<p>Foo Do</p>
</section><section data-mw-section-id="2"><h2 id="Bar">Bar</h2>
<p>Bar Re</p>
</section><section data-mw-section-id="3"><h2 id="-{Foo_Bar}-"><span id="-.7BFoo_Bar.7D-" typeof="mw:FallbackId"></span><span typeof="mw:LanguageVariant" data-mw-variant='{"disabled":{"t":"Foo Bar"}}'></span></h2>
</section>

!! end

!! test
TOC anchors don't collide
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__FORCETOC__
==Headline 2==
==Headline==
==Headline 2==
==Headline==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Headline_2"><span class="tocnumber">1</span> <span class="toctext">Headline 2</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Headline"><span class="tocnumber">2</span> <span class="toctext">Headline</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Headline_2_2"><span class="tocnumber">3</span> <span class="toctext">Headline 2</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Headline_3"><span class="tocnumber">4</span> <span class="toctext">Headline</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Headline_2">Headline 2</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: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Headline">Headline</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: Headline">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Headline_2_2">Headline 2</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: Headline 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Headline_3">Headline</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Headline">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

# perl -e 'print "="x$_," Level $_ heading","="x$_,"\n" for 1..10'
# Parsoid html2wt direction adds <nowiki> for level 7 and up.
!! test
Handling of sections up to level 6 and beyond
!! options
parsoid=wt2html
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
=Level 1 Heading=
==Level 2 Heading==
===Level 3 Heading===
====Level 4 Heading====
=====Level 5 Heading=====
======Level 6 Heading======
=======Level 7 Heading=======
========Level 8 Heading========
=========Level 9 Heading=========
==========Level 10 Heading==========
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Level_1_Heading"><span class="tocnumber">1</span> <span class="toctext">Level 1 Heading</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Level_2_Heading"><span class="tocnumber">1.1</span> <span class="toctext">Level 2 Heading</span></a>
<ul>
<li class="toclevel-3 tocsection-3"><a href="#Level_3_Heading"><span class="tocnumber">1.1.1</span> <span class="toctext">Level 3 Heading</span></a>
<ul>
<li class="toclevel-4 tocsection-4"><a href="#Level_4_Heading"><span class="tocnumber">1.1.1.1</span> <span class="toctext">Level 4 Heading</span></a>
<ul>
<li class="toclevel-5 tocsection-5"><a href="#Level_5_Heading"><span class="tocnumber">1.1.1.1.1</span> <span class="toctext">Level 5 Heading</span></a>
<ul>
<li class="toclevel-6 tocsection-6"><a href="#Level_6_Heading"><span class="tocnumber">1.1.1.1.1.1</span> <span class="toctext">Level 6 Heading</span></a></li>
<li class="toclevel-6 tocsection-7"><a href="#.3DLevel_7_Heading.3D"><span class="tocnumber">1.1.1.1.1.2</span> <span class="toctext">=Level 7 Heading=</span></a></li>
<li class="toclevel-6 tocsection-8"><a href="#.3D.3DLevel_8_Heading.3D.3D"><span class="tocnumber">1.1.1.1.1.3</span> <span class="toctext">==Level 8 Heading==</span></a></li>
<li class="toclevel-6 tocsection-9"><a href="#.3D.3D.3DLevel_9_Heading.3D.3D.3D"><span class="tocnumber">1.1.1.1.1.4</span> <span class="toctext">===Level 9 Heading===</span></a></li>
<li class="toclevel-6 tocsection-10"><a href="#.3D.3D.3D.3DLevel_10_Heading.3D.3D.3D.3D"><span class="tocnumber">1.1.1.1.1.5</span> <span class="toctext">====Level 10 Heading====</span></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="Level_1_Heading">Level 1 Heading</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: Level 1 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Level_2_Heading">Level 2 Heading</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: Level 2 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Level_3_Heading">Level 3 Heading</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Level 3 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading4"><h4 id="Level_4_Heading">Level 4 Heading</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Level 4 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading5"><h5 id="Level_5_Heading">Level 5 Heading</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Level 5 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading6"><h6 id="Level_6_Heading">Level 6 Heading</h6><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Level 6 Heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading6"><h6 id=".3DLevel_7_Heading.3D">=Level 7 Heading=</h6><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=7" title="Edit section: =Level 7 Heading=">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading6"><h6 id=".3D.3DLevel_8_Heading.3D.3D">==Level 8 Heading==</h6><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=8" title="Edit section: ==Level 8 Heading==">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading6"><h6 id=".3D.3D.3DLevel_9_Heading.3D.3D.3D">===Level 9 Heading===</h6><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=9" title="Edit section: ===Level 9 Heading===">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading6"><h6 id=".3D.3D.3D.3DLevel_10_Heading.3D.3D.3D.3D">====Level 10 Heading====</h6><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=10" title="Edit section: ====Level 10 Heading====">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h1 id="Level_1_Heading" data-parsoid='{}'>Level 1 Heading</h1>
<h2 id="Level_2_Heading" data-parsoid='{}'>Level 2 Heading</h2>
<h3 id="Level_3_Heading" data-parsoid='{}'>Level 3 Heading</h3>
<h4 id="Level_4_Heading" data-parsoid='{}'>Level 4 Heading</h4>
<h5 id="Level_5_Heading" data-parsoid='{}'>Level 5 Heading</h5>
<h6 id="Level_6_Heading" data-parsoid='{}'>Level 6 Heading</h6>
<h6 id="=Level_7_Heading=" data-parsoid='{}'><span id=".3DLevel_7_Heading.3D" typeof="mw:FallbackId"></span>=Level 7 Heading=</h6>
<h6 id="==Level_8_Heading==" data-parsoid='{}'><span id=".3D.3DLevel_8_Heading.3D.3D" typeof="mw:FallbackId"></span>==Level 8 Heading==</h6>
<h6 id="===Level_9_Heading===" data-parsoid='{}'><span id=".3D.3D.3DLevel_9_Heading.3D.3D.3D" typeof="mw:FallbackId"></span>===Level 9 Heading===</h6>
<h6 id="====Level_10_Heading====" data-parsoid='{}'><span id=".3D.3D.3D.3DLevel_10_Heading.3D.3D.3D.3D" typeof="mw:FallbackId"></span>====Level 10 Heading====</h6>
!! end

!! test
TOC regression (T11764)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==title 1==
===title 1.1===
====title 1.1.1====
===title 1.2===
==title 2==
===title 2.1===
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#title_1.1"><span class="tocnumber">1.1</span> <span class="toctext">title 1.1</span></a>
<ul>
<li class="toclevel-3 tocsection-3"><a href="#title_1.1.1"><span class="tocnumber">1.1.1</span> <span class="toctext">title 1.1.1</span></a></li>
</ul>
</li>
<li class="toclevel-2 tocsection-4"><a href="#title_1.2"><span class="tocnumber">1.2</span> <span class="toctext">title 1.2</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#title_2"><span class="tocnumber">2</span> <span class="toctext">title 2</span></a>
<ul>
<li class="toclevel-2 tocsection-6"><a href="#title_2.1"><span class="tocnumber">2.1</span> <span class="toctext">title 2.1</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="title_1">title 1</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: title 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="title_1.1">title 1.1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: title 1.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading4"><h4 id="title_1.1.1">title 1.1.1</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: title 1.1.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="title_1.2">title 1.2</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: title 1.2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="title_2">title 2</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: title 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="title_2.1">title 2.1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: title 2.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="title_1" data-parsoid="{}">title 1</h2>
<h3 id="title_1.1" data-parsoid="{}">title 1.1</h3>
<h4 id="title_1.1.1" data-parsoid="{}">title 1.1.1</h4>
<h3 id="title_1.2" data-parsoid="{}">title 1.2</h3>
<h2 id="title_2" data-parsoid="{}">title 2</h2>
<h3 id="title_2.1" data-parsoid="{}">title 2.1</h3>
!! end

!! test
TOC for heading containing <span id="..."></span> (T96153)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__FORCETOC__
==<span id="old-anchor"></span>New title==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#New_title"><span class="tocnumber">1</span> <span class="toctext">New title</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="New_title"><span id="old-anchor"></span>New title</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: New title">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

!! test
TOC with wgMaxTocLevel=3 (T8204)
!! options
wgMaxTocLevel=3
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==title 1==
===title 1.1===
====title 1.1.1====
===title 1.2===
==title 2==
===title 2.1===
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#title_1.1"><span class="tocnumber">1.1</span> <span class="toctext">title 1.1</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#title_1.2"><span class="tocnumber">1.2</span> <span class="toctext">title 1.2</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#title_2"><span class="tocnumber">2</span> <span class="toctext">title 2</span></a>
<ul>
<li class="toclevel-2 tocsection-6"><a href="#title_2.1"><span class="tocnumber">2.1</span> <span class="toctext">title 2.1</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="title_1">title 1</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: title 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="title_1.1">title 1.1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: title 1.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading4"><h4 id="title_1.1.1">title 1.1.1</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: title 1.1.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="title_1.2">title 1.2</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: title 1.2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="title_2">title 2</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: title 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="title_2.1">title 2.1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: title 2.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="title_1" data-parsoid="{}">title 1</h2>
<h3 id="title_1.1" data-parsoid="{}">title 1.1</h3>
<h4 id="title_1.1.1" data-parsoid="{}">title 1.1.1</h4>
<h3 id="title_1.2" data-parsoid="{}">title 1.2</h3>
<h2 id="title_2" data-parsoid="{}">title 2</h2>
<h3 id="title_2.1" data-parsoid="{}">title 2.1</h3>
!! end

!! test
TOC with wgMaxTocLevel=3 and two level four headings (T8204)
!! options
wgMaxTocLevel=3
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Section 1==
===Section 1.1===
====Section 1.1.1====
====Section 1.1.1.1====
==Section 2==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Section_1"><span class="tocnumber">1</span> <span class="toctext">Section 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Section_1.1"><span class="tocnumber">1.1</span> <span class="toctext">Section 1.1</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-5"><a href="#Section_2"><span class="tocnumber">2</span> <span class="toctext">Section 2</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Section_1">Section 1</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 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Section_1.1">Section 1.1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: Section 1.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading4"><h4 id="Section_1.1.1">Section 1.1.1</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: Section 1.1.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading4"><h4 id="Section_1.1.1.1">Section 1.1.1.1</h4><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Section 1.1.1.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Section_2">Section 2</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="Section_1" data-parsoid="{}">Section 1</h2>
<h3 id="Section_1.1" data-parsoid="{}">Section 1.1</h3>
<h4 id="Section_1.1.1" data-parsoid="{}">Section 1.1.1</h4>
<h4 id="Section_1.1.1.1" data-parsoid="{}">Section 1.1.1.1</h4>
<h2 id="Section_2" data-parsoid="{}">Section 2</h2>
!! end

!! test
Resolving duplicate section names
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Foo bar==
==Foo bar==
!! html
<div class="mw-heading mw-heading2"><h2 id="Foo_bar">Foo bar</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 bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Foo_bar_2">Foo 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: Foo bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

!! test
Resolving duplicate section names with differing case (T12721)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Foo bar==
==Foo Bar==
!! html
<div class="mw-heading mw-heading2"><h2 id="Foo_bar">Foo bar</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 bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Foo_Bar_2">Foo 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: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

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

!! test
Template with sections, __NOTOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__NOTOC__
==Section 0==
{{sections}}
==Section 4==
!! metadata
flags=no-toc
!! html/php
<div class="mw-heading mw-heading2"><h2 id="Section_0">Section 0</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 0">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Section_1">Section 1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Sections&amp;action=edit&amp;section=T-1" title="Edit section: Section 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Section_2">Section 2</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Sections&amp;action=edit&amp;section=T-2" title="Edit section: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Section_4">Section 4</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: Section 4">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/notoc" data-parsoid="{}" />
</section><section data-mw-section-id="1" about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":["==Section 0==\n",{"template":{"target":{"wt":"sections","href":"./Template:Sections"},"params":{},"i":0}},"\n"]}'><h2 id="Section_0" data-parsoid="{}">Section 0</h2>
<section data-mw-section-id="-1"><h3 about="#mwt1" typeof="mw:Transclusion" id="Section_1" data-parsoid="{}" data-mw='{"parts":[{"template":{"target":{"wt":"sections","href":"./Template:Sections"},"params":{},"i":0}}]}'>Section 1</h3><span about="#mwt1">
</span></section></section><section data-mw-section-id="-1" about="#mwt2"><h2 about="#mwt1" id="Section_2">Section 2</h2>
</section><section data-mw-section-id="2"><h2 id="Section_4" data-parsoid="{}">Section 4</h2></section>
!! end

!! test
T307691: show-toc flag: no sections
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
!! metadata
flags=
!! html
!! html/parsoid
<section data-mw-section-id="0"></section>
!! end

# You can't force a TOC if there aren't any sections
!! test
T307691: show-toc flag: no sections, but __FORCETOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__FORCETOC__
!! metadata
flags=
!! html/php
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/forcetoc"/></section>
!! end

# Placing a manual __TOC__ doesn't do anything if there aren't any sections
!! test
T307691: show-toc flag: no sections, but __TOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
!! metadata
flags=
!! html/php
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/toc"/></section>
!! end

!! test
T307691: show-toc flag: no sections, and __NOTOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__NOTOC__
!! metadata
flags=no-toc
!! html/php
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/notoc"/></section>
!! end

!! test
T307691: show-toc flag: not "enough" sections
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
== One ==
!! metadata
flags=
!! html/php
<div class="mw-heading mw-heading2"><h2 id="One">One</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: One">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="One">One</h2>
</section>
!! end

!! test
T352467: synthetic sections shouldn't count towards "enough" sections
!! options
showflags
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
<div>
==a==
==b==
</div>
==c==
!! metadata
flags=
!! html/php
<div>
<div class="mw-heading mw-heading2"><h2 id="a">a</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">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="b">b</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: b">edit</a><span class="mw-editsection-bracket">]</span></span></div>
</div>
<div class="mw-heading mw-heading2"><h2 id="c">c</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: c">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<section data-mw-section-id="-1"></section><section data-mw-section-id="-2"><div>
<section data-mw-section-id="1"><h2 id="a">a</h2>
</section><section data-mw-section-id="-1"><h2 id="b">b</h2>
</section></div>
</section><section data-mw-section-id="3"><h2 id="c">c</h2></section>
!! end

!! test
T307691: show-toc flag: not "enough" sections, but __FORCETOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__FORCETOC__
== One ==
!! metadata
flags=show-toc
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#One"><span class="tocnumber">1</span> <span class="toctext">One</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="One">One</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: One">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/forcetoc"/>
<meta property="mw:PageProp/toc" data-mw='{"autoGenerated":true}'/></section><section data-mw-section-id="1">
<h2 id="One">One</h2></section>
!! end

!! test
T307691: show-toc flag: not "enough" sections, but __TOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
== One ==
__TOC__
!! metadata
flags=show-toc
!! html/php
<div class="mw-heading mw-heading2"><h2 id="One">One</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: One">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#One"><span class="tocnumber">1</span> <span class="toctext">One</span></a></li>
</ul>
</div>
!! html/parsoid
<section data-mw-section-id="0"></section><section data-mw-section-id="1"><h2 id="One">One</h2>
<meta property="mw:PageProp/toc"/></section>
!! end

!! test
T307691: show-toc flag: not "enough" sections, and __NOTOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__NOTOC__
== One ==
!! metadata
flags=no-toc
!! html/php
<div class="mw-heading mw-heading2"><h2 id="One">One</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: One">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/notoc"/>
</section><section data-mw-section-id="1">
<h2 id="One">One</h2></section>
!! end

!! test
T307691: show-toc flag: "enough" sections
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
== One ==
=== Two ===
== Three ==
=== Four ===
!! metadata
flags=show-toc
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#One"><span class="tocnumber">1</span> <span class="toctext">One</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Two"><span class="tocnumber">1.1</span> <span class="toctext">Two</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-3"><a href="#Three"><span class="tocnumber">2</span> <span class="toctext">Three</span></a>
<ul>
<li class="toclevel-2 tocsection-4"><a href="#Four"><span class="tocnumber">2.1</span> <span class="toctext">Four</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="One">One</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: One">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Two">Two</h3><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: Two">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Three">Three</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: Three">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Four">Four</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Four">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/toc" data-mw='{"autoGenerated":true}'/></section><section data-mw-section-id="1"><h2 id="One">One</h2>
<section data-mw-section-id="2"><h3 id="Two">Two</h3>
</section></section><section data-mw-section-id="3"><h2 id="Three">Three</h2>
<section data-mw-section-id="4"><h3 id="Four">Four</h3></section></section>
!! end

!! test
T307691: show-toc flag: "enough" sections and __FORCETOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__FORCETOC__
== One ==
=== Two ===
== Three ==
=== Four ===
!! metadata
flags=show-toc
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#One"><span class="tocnumber">1</span> <span class="toctext">One</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#Two"><span class="tocnumber">1.1</span> <span class="toctext">Two</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-3"><a href="#Three"><span class="tocnumber">2</span> <span class="toctext">Three</span></a>
<ul>
<li class="toclevel-2 tocsection-4"><a href="#Four"><span class="tocnumber">2.1</span> <span class="toctext">Four</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="One">One</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: One">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Two">Two</h3><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: Two">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Three">Three</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: Three">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Four">Four</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Four">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/forcetoc"/>
<meta property="mw:PageProp/toc" data-mw='{"autoGenerated":true}'/></section><section data-mw-section-id="1"><h2 id="One">One</h2>
<section data-mw-section-id="2"><h3 id="Two">Two</h3>
</section></section><section data-mw-section-id="3"><h2 id="Three">Three</h2>
<section data-mw-section-id="4"><h3 id="Four">Four</h3></section></section>
!! end

!! test
T307691: show-toc flag: "enough" sections and __NOTOC__
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__NOTOC__
== One ==
=== Two ===
== Three ==
=== Four ===
!! metadata
flags=no-toc
!! html/php
<div class="mw-heading mw-heading2"><h2 id="One">One</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: One">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Two">Two</h3><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: Two">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Three">Three</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: Three">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="Four">Four</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Four">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/notoc"/>
</section><section data-mw-section-id="1"><h2 id="One">One</h2>
<section data-mw-section-id="2"><h3 id="Two">Two</h3>
</section></section><section data-mw-section-id="3"><h2 id="Three">Three</h2>
<section data-mw-section-id="4"><h3 id="Four">Four</h3></section></section>
!! end

## Note that the legacy parser doesn't set the flag.  It instead uses the presence
## of the behavior switch to inhibit the creation of the placeholders that would
## get replaced with the section edit links.
!! test
__NOEDITSECTION__ keyword
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__NOEDITSECTION__
==Section 1==
==Section 2==
!! html/php
<div class="mw-heading mw-heading2"><h2 id="Section_1">Section 1</h2></div>
<div class="mw-heading mw-heading2"><h2 id="Section_2">Section 2</h2></div>
!! metadata/php
flags=
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/noeditsection" data-parsoid='{"magicSrc":"__NOEDITSECTION__"}'/>
</section><section data-mw-section-id="1"><h2 id="Section_1" data-parsoid='{}'>Section 1</h2>
</section><section data-mw-section-id="2"><h2 id="Section_2" data-parsoid='{}'>Section 2</h2></section>
!! metadata/parsoid
flags=no-section-edit-links
!! end

!! test
Link inside a section heading
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Section with a [[Main Page|link]] in it==
!! html
<div class="mw-heading mw-heading2"><h2 id="Section_with_a_link_in_it">Section with a <a href="/wiki/Main_Page" title="Main Page">link</a> in it</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 with a link in it">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

!! test
TOC regression (T14077)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==title 1==
===title 1.1===
==title 2==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#title_1"><span class="tocnumber">1</span> <span class="toctext">title 1</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#title_1.1"><span class="tocnumber">1.1</span> <span class="toctext">title 1.1</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-3"><a href="#title_2"><span class="tocnumber">2</span> <span class="toctext">title 2</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="title_1">title 1</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: title 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="title_1.1">title 1.1</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: title 1.1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="title_2">title 2</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: title 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid="{}"/>
<h2 id="title_1" data-parsoid="{}">title 1</h2>
<h3 id="title_1.1" data-parsoid="{}">title 1.1</h3>
<h2 id="title_2" data-parsoid="{}">title 2</h2>
!! end

# test added in 4e717c01589378893c98e333884315c166c217b3
# __FORCETOC__ won't set show-toc if there are no sections
# present to show; also test that __NEWSECTIONLINK__ results in the
# proper ParserOutputFlag being set.
!! test
__FORCETOC__ override
!! options
showflags
parsoid={
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__NEWSECTIONLINK__
__FORCETOC__
!! metadata
flags=mw-NewSection
!! html/php
<p><br />
</p>
!! html/parsoid
<section data-mw-section-id="0"><meta property="mw:PageProp/newsectionlink" />
<meta property="mw:PageProp/forcetoc" /></section>
!! end

# Note that Parsoid doesn't emit an explicit TOC.
# Note also that the html2wt direction tends to emit an extra newline
# between the __TOC__ magicword and the first heading unless *both*
# the <meta> and the <h2> have a data-parsoid attribute set (even if
# it's "{}").

!! test
T28375: TOC with italics
!! options
title=[[Main Page]]
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==''Lost'' episodes==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Lost_episodes"><span class="tocnumber">1</span> <span class="toctext"><i>Lost</i> episodes</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Lost_episodes"><i>Lost</i> episodes</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: Lost episodes">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Lost_episodes" data-parsoid='{}'><i>Lost</i> episodes</h2>
!! end

!! test
T28375: TOC with bold
!! options
title=[[Main Page]]
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
=='''should be bold''' then normal text==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#should_be_bold_then_normal_text"><span class="tocnumber">1</span> <span class="toctext"><b>should be bold</b> then normal text</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="should_be_bold_then_normal_text"><b>should be bold</b> then normal text</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: should be bold then normal text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="should_be_bold_then_normal_text" data-parsoid='{}'><b>should be bold</b> then normal text</h2>
!! end

!! test
T35845: Headings become cursive in TOC when they contain an image
!! options
title=[[Main Page]]
!! config
wgParserEnableLegacyMediaDOM=false
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==Image [[Image:foobar.jpg]]==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Image"><span class="tocnumber">1</span> <span class="toctext">Image</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Image">Image <span class="mw-default-size" typeof="mw:File"><a href="/wiki/File:Foobar.jpg" class="mw-file-description"><img src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" width="1941" height="220" class="mw-file-element" /></a></span></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: Image">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Image" data-parsoid='{}'>Image <span class="mw-default-size" typeof="mw:File"><a href="./File:Foobar.jpg" class="mw-file-description"><img resource="./File:Foobar.jpg" src="http://example.com/images/3/3a/Foobar.jpg" decoding="async" data-file-width="1941" data-file-height="220" data-file-type="bitmap" height="220" width="1941" data-parsoid='{"a":{"resource":"./File:Foobar.jpg","height":"220","width":"1941"},"sa":{"resource":"Image:foobar.jpg"}}' class="mw-file-element"/></a></span></h2>
!! end

!! test
T35845 (2): Headings become bold in TOC when they contain a blockquote
!! options
title=[[Main Page]]
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==<blockquote>Quote</blockquote>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Quote"><span class="tocnumber">1</span> <span class="toctext">Quote</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Quote"><blockquote><p>Quote</p></blockquote></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: Quote">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Quote" data-parsoid='{}'><blockquote><p>Quote</p></blockquote></h2>
!! end

!! test
Unclosed tags in TOC
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! options
title=[[Main Page]]
!! wikitext
__TOC__
==Proof: 2 < 3==
<small>Hanc marginis exiguitas non caperet.</small>
QED
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Proof:_2_&lt;_3"><span class="tocnumber">1</span> <span class="toctext">Proof: 2 &lt; 3</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Proof:_2_&lt;_3"><span id="Proof:_2_.3C_3"></span>Proof: 2 &lt; 3</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: Proof: 2 &lt; 3">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><small>Hanc marginis exiguitas non caperet.</small>
QED
</p>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Proof:_2_&lt;_3" data-parsoid='{}'><span id="Proof:_2_.3C_3" typeof="mw:FallbackId"></span>Proof: 2 &lt; 3</h2>
<p><small>Hanc marginis exiguitas non caperet.</small>
QED</p>
!! end

!! test
Multiple tags in TOC
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==<i>Foo</i> <b>Bar</b>==

==<i>Foo</i> <blockquote>Bar</blockquote>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_Bar"><span class="tocnumber">1</span> <span class="toctext"><i>Foo</i> <b>Bar</b></span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext"><i>Foo</i> Bar</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Foo_Bar"><i>Foo</i> <b>Bar</b></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 Bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Foo_Bar_2"><i>Foo</i> <blockquote><p>Bar</p></blockquote></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: Foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Foo_Bar" data-parsoid='{}'><i data-parsoid='{"stx":"html"}'>Foo</i> <b data-parsoid='{"stx":"html"}'>Bar</b></h2>

<h2 id="Foo_Bar_2" data-parsoid='{}'><i data-parsoid='{"stx":"html"}'>Foo</i> <blockquote><p>Bar</p></blockquote></h2>
!! end

# Don't expect Parsoid to roundtrip this until the php parser comes closer to
# html5 tag parsing.
!! test
Tags with parameters in TOC
!! options
parsoid=wt2html
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==<sup class="in-h2">Hello</sup>==

==<sup class="a > b">Evilbye</sup>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Hello"><span class="tocnumber">1</span> <span class="toctext"><sup>Hello</sup></span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#b.22.3EEvilbye"><span class="tocnumber">2</span> <span class="toctext"><sup> b"&gt;Evilbye</sup></span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Hello"><sup class="in-h2">Hello</sup></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: Hello">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="b.22.3EEvilbye"><sup class="a"> b"&gt;Evilbye</sup></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: b&quot;&gt;Evilbye">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" />
<h2 id="Hello"><sup class="in-h2" data-parsoid='{"stx":"html"}'>Hello</sup></h2>

<h2 id='b">Evilbye'><span id="b.22.3EEvilbye" typeof="mw:FallbackId"></span><sup class="a " data-parsoid='{"stx":"html"}'> b">Evilbye</sup></h2>
!! end

!! test
span tags with directionality in TOC
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==<span dir="ltr">C++</span>==

==<span dir="rtl">זבנג!</span>==

==<span style="font-style: italic" dir="ltr" title="hello">Attributes other than dir</span>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#C.2B.2B"><span class="tocnumber">1</span> <span class="toctext"><span dir="ltr">C++</span></span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#.D7.96.D7.91.D7.A0.D7.92.21"><span class="tocnumber">2</span> <span class="toctext"><span dir="rtl">זבנג!</span></span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Attributes_other_than_dir"><span class="tocnumber">3</span> <span class="toctext"><span dir="ltr">Attributes other than dir</span></span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="C.2B.2B"><span dir="ltr">C++</span></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: C++">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id=".D7.96.D7.91.D7.A0.D7.92.21"><span dir="rtl">זבנג!</span></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: זבנג!">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Attributes_other_than_dir"><span style="font-style: italic" dir="ltr" title="hello">Attributes other than dir</span></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: Attributes other than dir">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="C++" data-parsoid='{}'><span id="C.2B.2B" typeof="mw:FallbackId"></span><span dir="ltr">C++</span></h2>
<h2 id="זבנג!"><span id=".D7.96.D7.91.D7.A0.D7.92.21" typeof="mw:FallbackId"></span><span dir="rtl">זבנג!</span></h2>
<h2 id="Attributes_other_than_dir"><span style="font-style: italic" dir="ltr" title="hello">Attributes other than dir</span></h2>
!! end

!! test
T74884: bdi element in ToC
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==<bdi>test</bdi>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#test"><span class="tocnumber">1</span> <span class="toctext"><bdi>test</bdi></span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="test"><bdi>test</bdi></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: test">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="test" data-parsoid='{}'><bdi>test</bdi></h2>
!! end

!! test
T35715: s/strike element in ToC
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==<s>test</s> test <strike>test</strike>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#test_test_test"><span class="tocnumber">1</span> <span class="toctext"><s>test</s> test <strike>test</strike></span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="test_test_test"><s>test</s> test <strike>test</strike></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: test test test">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="test_test_test" data-parsoid='{}'><s>test</s> test <strike>test</strike></h2>
!! end

!! test
T198618: style element in ToC
!! options
styletag=1
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==<style>.foo {}</style>Style<style>.bar {}</style>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Style"><span class="tocnumber">1</span> <span class="toctext">Style</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Style"><style>.foo {}</style>Style<style>.bar {}</style></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: Style">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid="{}"/>
<h2 id="Style" data-parsoid="{}"><style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".foo {}"}}'>.foo {}</style>Style<style typeof="mw:Extension/style" data-mw='{"name":"style","attrs":{},"body":{"extsrc":".bar {}"}}'>.bar {}</style></h2>
!! end

!! test
T198618: script element in ToC
!! options
wgRawHtml=1
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==<html><script>alert(1);</script></html>Script<html><script>alert(1);</script></html>==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Script"><span class="tocnumber">1</span> <span class="toctext">Script</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Script"><script>alert(1);</script>Script<script>alert(1);</script></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: Script">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="Script" data-parsoid='{}'><script typeof="mw:Extension/html" about="#mwt4" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;script>alert(1);&lt;/script>"}}'>alert(1);</script>Script<script typeof="mw:Extension/html" about="#mwt6" data-mw='{"name":"html","attrs":{},"body":{"extsrc":"&lt;script>alert(1);&lt;/script>"}}'>alert(1);</script></h2>
!! end

!! test
Empty <p> tag in TOC, removed by Sanitizer (T92892)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__TOC__
==x==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#x"><span class="tocnumber">1</span> <span class="toctext">x</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="x">x</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: x">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<meta property="mw:PageProp/toc" data-parsoid='{}'/>
<h2 id="x" data-parsoid='{}'>x</h2>
!! end

!! test
Disable TOC
!! options
notoc
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
Lead
==Section 1==
==Section 2==
==Section 3==
==Section 4==
==Section 5==
!! html
<p>Lead
</p>

<div class="mw-heading mw-heading2"><h2 id="Section_1">Section 1</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 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Section_2">Section 2</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: Section 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Section_3">Section 3</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: Section 3">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Section_4">Section 4</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Section 4">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Section_5">Section 5</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Section 5">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

###
### Headings
###

# Parsoid doesn't wt2wt this cleanly because it adds <nowiki>s.
!! test
Short headings with trailing space should match behavior of Parser::doHeadings (T21910)
!! options
parsoid=wt2html,html2html
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
=== 
The line above must have a trailing space!
=== <!--
--> <!-- -->
But just in case it doesn't...
!! html/php
<div class="mw-heading mw-heading1"><h1 id=".3D">=</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: =">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>The line above must have a trailing space!
</p>
<div class="mw-heading mw-heading1"><h1 id=".3D_2">=</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: =">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>But just in case it doesn't...
</p>
!! html/parsoid
<h1 id="="><span id=".3D" typeof="mw:FallbackId"></span>=</h1> 
<p>The line above must have a trailing space!</p>
<h1 id="=_2"><span id=".3D_2" typeof="mw:FallbackId"></span>=</h1> <!--
--> <!-- -->
<p>But just in case it doesn't...</p>
!! end

!! test
Header with special characters (T27462)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
The tooltips shall not show entities to the user (ie. be double escaped)

==text > text==
section 1

==text < text==
section 2

==text & text==
section 3

==text ' text==
section 4

==text " text==
section 5
!! html/php
<p>The tooltips shall not show entities to the user (ie. be double escaped)
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#text_.3E_text"><span class="tocnumber">1</span> <span class="toctext">text &gt; text</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#text_.3C_text"><span class="tocnumber">2</span> <span class="toctext">text &lt; text</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#text_.26_text"><span class="tocnumber">3</span> <span class="toctext">text &amp; text</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#text_.27_text"><span class="tocnumber">4</span> <span class="toctext">text ' text</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#text_.22_text"><span class="tocnumber">5</span> <span class="toctext">text " text</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="text_.3E_text">text &gt; text</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: text &gt; text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 1
</p>
<div class="mw-heading mw-heading2"><h2 id="text_.3C_text">text &lt; text</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: text &lt; text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 2
</p>
<div class="mw-heading mw-heading2"><h2 id="text_.26_text">text &amp; text</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: text &amp; text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 3
</p>
<div class="mw-heading mw-heading2"><h2 id="text_.27_text">text ' text</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: text &#39; text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 4
</p>
<div class="mw-heading mw-heading2"><h2 id="text_.22_text">text " text</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: text &quot; text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 5
</p>
!! html/parsoid
<p>The tooltips shall not show entities to the user (ie. be double escaped)</p>

<h2 id="text_>_text"><span id="text_.3E_text" typeof="mw:FallbackId"></span>text > text</h2>
<p>section 1</p>

<h2 id="text_&lt;_text"><span id="text_.3C_text" typeof="mw:FallbackId"></span>text &lt; text</h2>
<p>section 2</p>

<h2 id="text_&amp;_text"><span id="text_.26_text" typeof="mw:FallbackId"></span>text &amp; text</h2>
<p>section 3</p>

<h2 id="text_'_text"><span id="text_.27_text" typeof="mw:FallbackId"></span>text ' text</h2>
<p>section 4</p>

<h2 id='text_"_text'><span id="text_.22_text" typeof="mw:FallbackId"></span>text " text</h2>
<p>section 5</p>
!! end

!! test
Header with space, plus and underscore as entity
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
Id should not contain + for spaces

==Space between Text==
section 1

==Space-Entity&#32;between&#32;Text==
section 2

==Plus+between+Text==
section 3

==Plus-Entity&#43;between&#43;Text==
section 4

==Underscore_between_Text==
section 5

==Underscore-Entity&#95;between&#95;Text==
section 6

[[#Space between Text]]
[[#Space-Entity&#32;between&#32;Text]]
[[#Plus+between+Text]]
[[#Plus-Entity&#43;between&#43;Text]]
[[#Underscore_between_Text]]
[[#Underscore-Entity&#95;between&#95;Text]]
!! html/php
<p>Id should not contain + for spaces
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Space_between_Text"><span class="tocnumber">1</span> <span class="toctext">Space between Text</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#Space-Entity_between_Text"><span class="tocnumber">2</span> <span class="toctext">Space-Entity between Text</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Plus.2Bbetween.2BText"><span class="tocnumber">3</span> <span class="toctext">Plus+between+Text</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Plus-Entity.2Bbetween.2BText"><span class="tocnumber">4</span> <span class="toctext">Plus-Entity+between+Text</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#Underscore_between_Text"><span class="tocnumber">5</span> <span class="toctext">Underscore_between_Text</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="#Underscore-Entity_between_Text"><span class="tocnumber">6</span> <span class="toctext">Underscore-Entity_between_Text</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Space_between_Text">Space between Text</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: Space between Text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 1
</p>
<div class="mw-heading mw-heading2"><h2 id="Space-Entity_between_Text">Space-Entity&#32;between&#32;Text</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: Space-Entity between Text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 2
</p>
<div class="mw-heading mw-heading2"><h2 id="Plus.2Bbetween.2BText">Plus+between+Text</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: Plus+between+Text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 3
</p>
<div class="mw-heading mw-heading2"><h2 id="Plus-Entity.2Bbetween.2BText">Plus-Entity&#43;between&#43;Text</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Plus-Entity+between+Text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 4
</p>
<div class="mw-heading mw-heading2"><h2 id="Underscore_between_Text">Underscore_between_Text</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: Underscore_between_Text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 5
</p>
<div class="mw-heading mw-heading2"><h2 id="Underscore-Entity_between_Text">Underscore-Entity&#95;between&#95;Text</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Underscore-Entity_between_Text">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>section 6
</p><p><a href="#Space_between_Text">#Space between Text</a>
<a href="#Space-Entity_between_Text">#Space-Entity&#32;between&#32;Text</a>
<a href="#Plus.2Bbetween.2BText">#Plus+between+Text</a>
<a href="#Plus-Entity.2Bbetween.2BText">#Plus-Entity&#43;between&#43;Text</a>
<a href="#Underscore_between_Text">#Underscore_between_Text</a>
<a href="#Underscore-Entity_between_Text">#Underscore-Entity&#95;between&#95;Text</a>
</p>
!! html/parsoid
<p>Id should not contain + for spaces</p>

<h2 id="Space_between_Text">Space between Text</h2>
<p>section 1</p>

<h2 id="Space-Entity_between_Text">Space-Entity<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#32;","srcContent":" "}'> </span>between<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#32;","srcContent":" "}'> </span>Text</h2>
<p>section 2</p>

<h2 id="Plus+between+Text"><span id="Plus.2Bbetween.2BText" typeof="mw:FallbackId"></span>Plus+between+Text</h2>
<p>section 3</p>

<h2 id="Plus-Entity+between+Text"><span id="Plus-Entity.2Bbetween.2BText" typeof="mw:FallbackId"></span>Plus-Entity<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#43;","srcContent":"+"}'>+</span>between<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#43;","srcContent":"+"}'>+</span>Text</h2>
<p>section 4</p>

<h2 id="Underscore_between_Text">Underscore_between_Text</h2>
<p>section 5</p>

<h2 id="Underscore-Entity_between_Text">Underscore-Entity<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#95;","srcContent":"_"}'>_</span>between<span typeof="mw:Entity" data-parsoid='{"src":"&amp;#95;","srcContent":"_"}'>_</span>Text</h2>
<p>section 6</p>

<p><a rel="mw:WikiLink" href="./Parser_test#Space_between_Text" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Space_between_Text"},"sa":{"href":"#Space between Text"}}'>#Space between Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Space-Entity_between_Text" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Space-Entity_between_Text"},"sa":{"href":"#Space-Entity&amp;#32;between&amp;#32;Text"}}'>#Space-Entity between Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Plus+between+Text" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Plus+between+Text"},"sa":{"href":"#Plus+between+Text"}}'>#Plus+between+Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Plus-Entity+between+Text" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Plus-Entity+between+Text"},"sa":{"href":"#Plus-Entity&amp;#43;between&amp;#43;Text"}}'>#Plus-Entity+between+Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Underscore_between_Text" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Underscore_between_Text"},"sa":{"href":"#Underscore_between_Text"}}'>#Underscore_between_Text</a>
<a rel="mw:WikiLink" href="./Parser_test#Underscore-Entity_between_Text" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Underscore-Entity_between_Text"},"sa":{"href":"#Underscore-Entity&amp;#95;between&amp;#95;Text"}}'>#Underscore-Entity_between_Text</a></p>
!! end

# Parsoid html2wt disabled because it adds padding spaces around =
!! test
Headers with excess '=' characters
(Are similar tests necessary beyond the 1st level?)
!! options
parsoid=wt2html,wt2wt,html2html
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
=foo==
==foo=
=''italic'' heading==
==''italic'' heading=
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#foo.3D"><span class="tocnumber">1</span> <span class="toctext">foo=</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#.3Dfoo"><span class="tocnumber">2</span> <span class="toctext">=foo</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#italic_heading.3D"><span class="tocnumber">3</span> <span class="toctext"><i>italic</i> heading=</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#.3Ditalic_heading"><span class="tocnumber">4</span> <span class="toctext">=<i>italic</i> heading</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="foo.3D">foo=</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: foo=">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading1"><h1 id=".3Dfoo">=foo</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: =foo">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading1"><h1 id="italic_heading.3D"><i>italic</i> heading=</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: italic heading=">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading1"><h1 id=".3Ditalic_heading">=<i>italic</i> heading</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: =italic heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h1 id="foo=" data-parsoid="{}"><span id="foo.3D" typeof="mw:FallbackId"></span>foo=</h1>
<h1 id="=foo" data-parsoid="{}"><span id=".3Dfoo" typeof="mw:FallbackId"></span>=foo</h1>
<h1 id="italic_heading=" data-parsoid="{}"><span id="italic_heading.3D" typeof="mw:FallbackId"></span><i>italic</i> heading=</h1>
<h1 id="=italic_heading" data-parsoid="{}"><span id=".3Ditalic_heading" typeof="mw:FallbackId"></span>=<i>italic</i> heading</h1>
!! end

!! test
HTML headers vs TOC (T25393)
(__NOEDITSECTION__ for clearer output, doesn't matter here)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
<h1>Header 1</h1>
==Header 1.1==
==Header 1.2==

<h1>Header 2
</h1>
==Header 2.1==
==Header 2.2==
__NOEDITSECTION__
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1"><a href="#Header_1"><span class="tocnumber">1</span> <span class="toctext">Header 1</span></a>
<ul>
<li class="toclevel-2 tocsection-1"><a href="#Header_1.1"><span class="tocnumber">1.1</span> <span class="toctext">Header 1.1</span></a></li>
<li class="toclevel-2 tocsection-2"><a href="#Header_1.2"><span class="tocnumber">1.2</span> <span class="toctext">Header 1.2</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="#Header_2"><span class="tocnumber">2</span> <span class="toctext">Header 2</span></a>
<ul>
<li class="toclevel-2 tocsection-3"><a href="#Header_2.1"><span class="tocnumber">2.1</span> <span class="toctext">Header 2.1</span></a></li>
<li class="toclevel-2 tocsection-4"><a href="#Header_2.2"><span class="tocnumber">2.2</span> <span class="toctext">Header 2.2</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading1"><h1 id="Header_1">Header 1</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Header_1.1">Header 1.1</h2></div>
<div class="mw-heading mw-heading2"><h2 id="Header_1.2">Header 1.2</h2></div>
<div class="mw-heading mw-heading1"><h1 id="Header_2">Header 2
</h1></div>
<div class="mw-heading mw-heading2"><h2 id="Header_2.1">Header 2.1</h2></div>
<div class="mw-heading mw-heading2"><h2 id="Header_2.2">Header 2.2</h2></div>
!! html/parsoid
<h1 id="Header_1" data-parsoid='{"stx":"html"}'>Header 1</h1>
<h2 id="Header_1.1" data-parsoid='{}'>Header 1.1</h2>
<h2 id="Header_1.2" data-parsoid='{}'>Header 1.2</h2>

<h1 id="Header_2" data-parsoid='{"stx":"html"}'>Header 2
</h1>
<h2 id="Header_2.1" data-parsoid='{}'>Header 2.1</h2>
<h2 id="Header_2.2" data-parsoid='{}'>Header 2.2</h2>
<meta property="mw:PageProp/noeditsection"/>
!! end

!! test
Out-of-order TOC heading levels
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==2==
======6======
===3===
=1=
=====5=====
==2==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#2"><span class="tocnumber">1</span> <span class="toctext">2</span></a>
<ul>
<li class="toclevel-2 tocsection-2"><a href="#6"><span class="tocnumber">1.1</span> <span class="toctext">6</span></a></li>
<li class="toclevel-2 tocsection-3"><a href="#3"><span class="tocnumber">1.2</span> <span class="toctext">3</span></a></li>
</ul>
</li>
<li class="toclevel-1 tocsection-4"><a href="#1"><span class="tocnumber">2</span> <span class="toctext">1</span></a>
<ul>
<li class="toclevel-2 tocsection-5"><a href="#5"><span class="tocnumber">2.1</span> <span class="toctext">5</span></a></li>
<li class="toclevel-2 tocsection-6"><a href="#2_2"><span class="tocnumber">2.2</span> <span class="toctext">2</span></a></li>
</ul>
</li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="2">2</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: 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading6"><h6 id="6">6</h6><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: 6">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading3"><h3 id="3">3</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: 3">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading1"><h1 id="1">1</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading5"><h5 id="5">5</h5><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: 5">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="2_2">2</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: 2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="2" data-parsoid="{}">2</h2>
<h6 id="6" data-parsoid="{}">6</h6>
<h3 id="3" data-parsoid="{}">3</h3>
<h1 id="1" data-parsoid="{}">1</h1>
<h5 id="5" data-parsoid="{}">5</h5>
<h2 id="2_2" data-parsoid="{}">2</h2>
!! end

# Note that HTML (but not wikitext) allows the trailing semicolon to
# be omitted from an entity, so we need to escape the ampersand in
# situations where HTML would interpret a "semicolonless" entity.
!! test
TOC with HTML entities which are not wikitext entities (T355386)
!! config
wgFragmentMode=[ "html5" ]
wgParserEnableLegacyHeadingDOM=false
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! wikitext
__TOC__
== F&GT ==
Test
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:8 anchor/linkAnchor:F&GT line:F&amp;GT
!! end

# Note that the metadata section below contains non-breaking spaces around
# the french quotes, which also show up in the link anchor
!! test
TOC with french spacing (T324763)
!! config
wgFragmentMode=[ "html5" ]
wgParserEnableLegacyHeadingDOM=false
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! wikitext
__TOC__
== Renommer la page « Informatique durable » en « Numérique responsable » ? ==
Oui.
!! metadata/php
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:8 anchor/linkAnchor:Renommer_la_page_«_Informatique_durable_»_en_«_Numérique_responsable_»_? line:Renommer la page « Informatique durable » en « Numérique responsable » ?
!! metadata/parsoid
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:8 anchor/linkAnchor:Renommer_la_page_«_Informatique_durable_»_en_«_Numérique_responsable_»_? line:Renommer la page «<span> </span>Informatique durable<span> </span>» en «<span> </span>Numérique responsable<span> </span>»<span> </span>?
!! end

!! test
1. Ensure sections in extensions are ignored + TOC is inserted outside extensions
!! options
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__FORCETOC__
<spantag>
==spantag h2==
</spantag>
intro
==page h2==
blah
!! html/php
<p><span>
</span></p>
<div class="mw-heading mw-heading2"><h2 id="spantag_h2">spantag h2</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: spantag h2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>intro
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#page_h2"><span class="tocnumber">1</span> <span class="toctext">page h2</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="page_h2">page h2</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: page h2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>blah
</p>
!! html/parsoid
<section data-mw-section-id="-1"><meta property="mw:PageProp/forcetoc"/> </section><section data-mw-section-id="-2"><span typeof="mw:Extension/spantag" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"\n==spantag h2==\n"}}'>
<section data-mw-section-id="-1"><h2 id="spantag_h2">spantag h2</h2></section></span>
<p>intro</p>
<meta property="mw:PageProp/toc" data-mw='{"autoGenerated":true}'/></section><section data-mw-section-id="1"><h2 id="page_h2">page h2</h2>
<p>blah</p></section>
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:55 anchor/linkAnchor:page_h2 line:page h2
!! end

!! test
2. Ensure sections in extensions are ignored + TOC is inserted outside extensions
!! options
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__FORCETOC__
{{1x|1=foo
<spantag>
==spantag h2==
</spantag>
}}
intro
==page h2==
blah
!! html/php
<p>foo
<span>
</span></p>
<div class="mw-heading mw-heading2"><h2 id="spantag_h2">spantag h2</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: spantag h2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>intro
</p>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#page_h2"><span class="tocnumber">1</span> <span class="toctext">page h2</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="page_h2">page h2</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: page h2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>blah
</p>
!! html/parsoid
<section data-mw-section-id="-1" about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":["__FORCETOC__\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo\n&lt;spantag>\n==spantag h2==\n&lt;/spantag>"}},"i":0}},"\nintro\n"]}'><meta property="mw:PageProp/forcetoc" />
<p about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"foo\n&lt;spantag>\n==spantag h2==\n&lt;/spantag>"}},"i":0}}]}'>foo</p><span about="#mwt2">
</span></section><section data-mw-section-id="-2" about="#mwt4"><span typeof="mw:Extension/spantag" about="#mwt2" data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"\n==spantag h2==\n"}}'>
<section data-mw-section-id="-1"><h2 id="spantag_h2">spantag h2</h2></section></span>
<p>intro</p>
<meta property="mw:PageProp/toc" data-mw='{"autoGenerated":true}'/></section><section data-mw-section-id="1"><h2 id="page_h2">page h2</h2>
<p>blah</p></section>
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:69 anchor/linkAnchor:page_h2 line:page h2
!! end

!! test
3. Ensure sections in extensions are ignored + TOC is inserted outside extensions
!! options
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
__FORCETOC__
{{1x|1=<spantag>
==spantag h2==
</spantag>
==template h2==
}}
intro
==page h2==
blah
!! html/php
<p><span>
</span></p>
<div class="mw-heading mw-heading2"><h2 id="spantag_h2">spantag h2</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: spantag h2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1"><a href="#template_h2"><span class="tocnumber">1</span> <span class="toctext">template h2</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#page_h2"><span class="tocnumber">2</span> <span class="toctext">page h2</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="template_h2">template h2</h2></div>
<p>intro
</p>
<div class="mw-heading mw-heading2"><h2 id="page_h2">page h2</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: page h2">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p>blah
</p>
!! html/parsoid
<section data-mw-section-id="-1"><meta property="mw:PageProp/forcetoc" data-parsoid='{"src":"__FORCETOC__","magicSrc":"__FORCETOC__"}'/>
</section><section data-mw-section-id="-2" about="#mwt4" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;spantag>\n==spantag h2==\n&lt;/spantag>\n==template h2=="}},"i":0}},"\nintro\n"]}'><span typeof="mw:Extension/spantag mw:Transclusion" about="#mwt2" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["","","","\n"]}]],"dsr":[13,74,null,null]}' data-mw='{"name":"spantag","attrs":{},"body":{"extsrc":"\n==spantag h2==\n"},"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;spantag>\n==spantag h2==\n&lt;/spantag>\n==template h2=="}},"i":0}}]}'>
<section data-mw-section-id="-1"><h2 id="spantag_h2">spantag h2</h2>
</section></span><span about="#mwt2">
</span><meta property="mw:PageProp/toc" data-mw='{"autoGenerated":true}'/></section><section data-mw-section-id="-1" about="#mwt4"><h2 about="#mwt2" id="template_h2">template h2</h2>
<p>intro</p>
</section><section data-mw-section-id="2"><h2 id="page_h2">page h2</h2>
<p>blah</p></section>
!! metadata/php
Sections:
 h2 index: toclevel:1 number:1 title:NULL off:NULL anchor/linkAnchor:template_h2 line:template h2
 h2 index:2 toclevel:1 number:2 title:Parser_test off:81 anchor/linkAnchor:page_h2 line:page h2
!! metadata/parsoid
Sections:
 h2 index:T-1 toclevel:1 number:1 title:Template:1x off:NULL anchor/linkAnchor:template_h2 line:template h2
 h2 index:2 toclevel:1 number:2 title:Parser_test off:81 anchor/linkAnchor:page_h2 line:page h2
!! end

!! test
TOC data when heading content is equal to an id already set on the page
!! options
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
<span id="hiho">hiho</span>
=== hiho ===
!! html/php
<p><span id="hiho">hiho</span>
</p>
<div class="mw-heading mw-heading3"><h3 id="hiho">hiho</h3><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: hiho">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! metadata/php
Sections:
 h3 index:1 toclevel:1 number:1 title:Parser_test off:28 anchor/linkAnchor:hiho line:hiho
!! html/parsoid
<section data-mw-section-id="0"><p><span id="hiho">hiho</span></p>
</section><section data-mw-section-id="1"><h3 id="hiho_2">hiho</h3></section>
!! metadata/parsoid
Sections:
 h3 index:1 toclevel:1 number:1 title:Parser_test off:28 anchor/linkAnchor:hiho_2 line:hiho
!! end

!! test
TOC data when heading already has an id
!! options
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
<h3 id="asdf">odd</h3>
!! html/php
<h3 id="asdf">odd</h3>
!! metadata/php
Sections:
 h3 index: toclevel:1 number:1 title:NULL off:NULL anchor/linkAnchor:asdf line:odd
!! html/parsoid
<section data-mw-section-id="0"></section><section data-mw-section-id="-1"><h3 id="asdf" data-parsoid='{"stx":"html","reusedId":true}'>odd</h3></section>
!! metadata/parsoid
Sections:
 h3 index: toclevel:1 number:1 title:NULL off:NULL anchor/linkAnchor:asdf line:odd
!! end

!! test
Extra newlines followed by heading
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
a


=b=
[[a]]


=b=
!! html
<p>a
</p><p><br />
</p>
<div class="mw-heading mw-heading1"><h1 id="b">b</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: b">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><a href="/wiki/A" title="A">a</a>
</p><p><br />
</p>
<div class="mw-heading mw-heading1"><h1 id="b_2">b</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: b">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

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

!! test
Extra newlines between heading and content are swallowed (Parsoid does not)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
=b=



[[a]]
!! html/php
<div class="mw-heading mw-heading1"><h1 id="b">b</h1><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: b">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><a href="/wiki/A" title="A">a</a>
</p>
!! html/parsoid
<h1 id="b">b</h1>
<p>
<br/></p>

<p><a rel="mw:WikiLink" href="./A" title="A" data-parsoid='{"stx":"simple","a":{"href":"./A"},"sa":{"href":"a"}}'>a</a></p>
!! end

!! test
Heading with line break in nowiki
!! options
parsoid=wt2html
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==A <nowiki>B
C</nowiki>==
!! html/php
<div class="mw-heading mw-heading2"><h2 id="A_B_C"><span id="A_B.0AC"></span>A B
C</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 B&#10;C">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="A_B_C"><span id="A_B.0AC" typeof="mw:FallbackId"></span>A <span typeof="mw:Nowiki">B
C</span></h2>
!! end

!! test
Heading with nonbreaking space in prefix/suffix (T235684)
!! options
parsoid=wt2html,html2html
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
== &nbsp; A &nbsp; B &nbsp; ==
!! html/php
<div class="mw-heading mw-heading2"><h2 id="_A_B">&#160; A &#160; B &#160;</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: &#160; A &#160; B &#160;">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! html/parsoid
<h2 id="_A_B"><span typeof="mw:Entity"> </span> A <span typeof="mw:Entity"> </span> B <span typeof="mw:Entity"> </span></h2>
!! end

!! test
Heading with literal wikitext - the wikitext is not parsed in section edit link tooltip
!! config
wgFragmentMode=[ "html5" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
== <nowiki>{{PAGENAME}}</nowiki> ==
== &#123;&#123;PAGENAME}} ==
!! html/php
<div class="mw-heading mw-heading2"><h2 id="{{PAGENAME}}">{{PAGENAME}}</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: {{PAGENAME}}">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="{{PAGENAME}}_2">&#123;&#123;PAGENAME}}</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: {{PAGENAME}}">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

!! article
Template:Includeonly section
!! text
<includeonly>
==Includeonly section==
</includeonly>
==Section T-1==
!!endarticle

!! test
T8563: Edit link generation for section shown by <includeonly>
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{includeonly section}}
!! html
<div class="mw-heading mw-heading2"><h2 id="Includeonly_section">Includeonly section</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Includeonly_section&amp;action=edit&amp;section=T-1" title="Edit section: Includeonly section">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Section_T-1">Section T-1</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:Includeonly_section&amp;action=edit&amp;section=T-2" title="Edit section: Section T-1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

!! test
T8563: Edit link generation for section suppressed by <includeonly>
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
<includeonly>
==Includeonly section==
</includeonly>
==Section 1==
!! html
<div class="mw-heading mw-heading2"><h2 id="Section_1">Section 1</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 1">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

# Note that Parsoid output differs from the PHP parser here: the PHP
# parser breaks the URL for the magic word, while in Parsoid the URL
# production takes precedence.
!! test
Fuzz testing: Parser14
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==onmouseover===
http://__TOC__
!! html/php
<div class="mw-heading mw-heading2"><h2 id="onmouseover.3D">onmouseover=</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: onmouseover=">edit</a><span class="mw-editsection-bracket">]</span></span></div><p>
http://</p><div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#onmouseover.3D"><span class="tocnumber">1</span> <span class="toctext">onmouseover=</span></a></li>
</ul>
</div>
!! html/parsoid
<h2 id="onmouseover="><span id="onmouseover.3D" typeof="mw:FallbackId"></span>onmouseover=</h2>
<p><a rel="mw:ExtLink" href="http://__TOC__" class="external free" data-parsoid='{"stx":"url"}'>http://__TOC__</a></p>
!! end

!! test
Fuzz testing: Parser14-table
!! options
parsoid=wt2html,html2html
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==a==
{| STYLE=__TOC__
!! html/php
<div class="mw-heading mw-heading2"><h2 id="a">a</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">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<table style="&#95;&#95;TOC&#95;&#95;">
<tbody><tr><td></td></tr>
</tbody></table>
!! html/parsoid
<h2 id="a">a</h2>
<table style="__TOC__"></table>
!! end


!! article
MediaWiki:Fake
!! text
==header==
!! endarticle

!! test
Inclusion of !userCanEdit() content
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{MediaWiki:Fake}}
!! html
<div class="mw-heading mw-heading2"><h2 id="header">header</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=MediaWiki:Fake&amp;action=edit&amp;section=T-1" title="Edit section: header">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end


!! test
Morwen/13: Unclosed link followed by heading
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
[[link
==heading==
!! html
<p>[[link
</p>
<div class="mw-heading mw-heading2"><h2 id="heading">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: heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

!! test
HHP2.1: Heuristics for headings in preprocessor parenthetical structures
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{foo|
=heading=
!! html
<p>{{foo|
</p>
<div class="mw-heading mw-heading1"><h1 id="heading">heading</h1></div>
!! end

!! test
HHP2.2: Heuristics for headings in preprocessor parenthetical structures
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{foo|
==heading==
!! html
<p>{{foo|
</p>
<div class="mw-heading mw-heading2"><h2 id="heading">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: heading">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

!!article
Foo
!!text
FOO
!!endarticle

!! test
nowiki inside link inside heading (T20295)
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==[[foo|x<nowiki>y</nowiki>z]]==
!! html
<div class="mw-heading mw-heading2"><h2 id="xyz"><a href="/wiki/Foo" title="Foo">xyz</a></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: xyz">edit</a><span class="mw-editsection-bracket">]</span></span></div>
!! end

!! test
Decoding of HTML entities in headings and links for IDs and link fragments (T103714)
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! options
showtocdata
parsoid={
	"wrapSections": true
}
!! wikitext
==A&B&amp;C&amp;amp;D&amp;amp;amp;E==
[[#A&B&amp;C&amp;amp;D&amp;amp;amp;E]]
!! html/php
<div class="mw-heading mw-heading2"><h2 id="A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E"><span id="A.26B.26C.26amp.3BD.26amp.3Bamp.3BE"></span>A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</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&amp;B&amp;C&amp;amp;D&amp;amp;amp;E">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><a href="#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E">#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</a>
</p>
!! html/parsoid
<section data-mw-section-id="0"></section><section data-mw-section-id="1"><h2 id="A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E"><span id="A.26B.26C.26amp.3BD.26amp.3Bamp.3BE" typeof="mw:FallbackId"></span>A&amp;B<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>C<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>amp;D<span typeof="mw:Entity" data-parsoid='{"src":"&amp;amp;","srcContent":"&amp;"}'>&amp;</span>amp;amp;E</h2>
<p><a rel="mw:WikiLink" href="./Parser_test#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E"},"sa":{"href":"#A&amp;B&amp;amp;C&amp;amp;amp;D&amp;amp;amp;amp;E"}}'>#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</a></p></section>
!! metadata
Sections:
 h2 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:A&B&C&amp;D&amp;amp;E line:A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E
!! end

!! test
Decoding of HTML entities in headings and links for IDs and link fragments (T103714) (legacy)
!! config
wgFragmentMode=[ "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==A&B&amp;C&amp;amp;D&amp;amp;amp;E==
[[#A&B&amp;C&amp;amp;D&amp;amp;amp;E]]
!! html/php
<div class="mw-heading mw-heading2"><h2 id="A.26B.26C.26amp.3BD.26amp.3Bamp.3BE">A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</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&amp;B&amp;C&amp;amp;D&amp;amp;amp;E">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><a href="#A.26B.26C.26amp.3BD.26amp.3Bamp.3BE">#A&amp;B&amp;C&amp;amp;D&amp;amp;amp;E</a>
</p>
!! end

# This fragment mode is what Parsoid supports.
!! test
HTML5 ids: fallback to legacy
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Foo bar==

==foo Bar==

==Тест==

==Тест==

==тест==

==Hey < # " > % : '==
[[#Foo bar]] [[#foo Bar]] [[#Тест]] [[#тест]] [[#Hey < # " > % : ']]

{{anchorencode:💩}} <span id="{{anchorencode:💩}}"></span>

<!-- These two links should produce identical HTML -->
[[#啤酒]] [[#%E5%95%A4%E9%85%92]]

!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Тест"><span class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Тест_2"><span class="tocnumber">4</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#тест"><span class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="#Hey_&lt;_#_&quot;_&gt;_%_:_&#39;"><span class="tocnumber">6</span> <span class="toctext">Hey &lt; # " &gt;&#160;%&#160;: '</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Foo_bar">Foo bar</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 bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="foo_Bar_2">foo 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: foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Тест"><span id=".D0.A2.D0.B5.D1.81.D1.82"></span>Тест</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>
<div class="mw-heading mw-heading2"><h2 id="Тест_2"><span id=".D0.A2.D0.B5.D1.81.D1.82_2"></span>Тест</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="тест"><span id=".D1.82.D0.B5.D1.81.D1.82"></span>тест</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: тест">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Hey_&lt;_#_&quot;_&gt;_%_:_'"><span id="Hey_.3C_.23_.22_.3E_.25_:_.27"></span>Hey &lt; # " &gt;&#160;%&#160;: '</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Hey &lt; # &quot; &gt;&#160;%&#160;: &#39;">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a href="#Тест">#Тест</a> <a href="#тест">#тест</a> <a href="#Hey_&lt;_#_&quot;_&gt;_%_:_&#39;">#Hey &lt; # " &gt;&#160;%&#160;: '</a>
</p><p>💩 <span id="💩"></span>
</p><p><a href="#啤酒">#啤酒</a> <a href="#啤酒">#啤酒</a>
</p>
!! html/parsoid
<h2 id="Foo_bar">Foo bar</h2>

<h2 id="foo_Bar_2">foo Bar</h2>

<h2 id="Тест"><span id=".D0.A2.D0.B5.D1.81.D1.82" typeof="mw:FallbackId"></span>Тест</h2>

<h2 id="Тест_2"><span id=".D0.A2.D0.B5.D1.81.D1.82_2" typeof="mw:FallbackId"></span>Тест</h2>

<h2 id="тест"><span id=".D1.82.D0.B5.D1.81.D1.82" typeof="mw:FallbackId"></span>тест</h2>

<h2 id="Hey_&lt;_#_&quot;_>_%_:_'"><span id="Hey_.3C_.23_.22_.3E_.25_:_.27" typeof="mw:FallbackId"></span>Hey &lt; # " ><span typeof="mw:DisplaySpace"> </span>%<span typeof="mw:DisplaySpace"> </span>: '</h2>
<p><a rel="mw:WikiLink" href="./Parser_test#Foo_bar" class="mw-selflink-fragment">#Foo bar</a> <a rel="mw:WikiLink" href="./Parser_test#foo_Bar" class="mw-selflink-fragment">#foo Bar</a> <a rel="mw:WikiLink" href="./Parser_test#Тест" class="mw-selflink-fragment">#Тест</a> <a rel="mw:WikiLink" href="./Parser_test#тест" class="mw-selflink-fragment">#тест</a> <a rel="mw:WikiLink" href="./Parser_test#Hey_&lt;_#_&quot;_>_%_:_'" class="mw-selflink-fragment">#Hey &lt; # " ><span typeof="mw:DisplaySpace"> </span>%<span typeof="mw:DisplaySpace"> </span>: '</a></p>

<p><span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"anchorencode:💩","function":"anchorencode"},"params":{},"i":0}}]}'>💩</span> <span id="💩" about="#mwt3" typeof="mw:ExpandedAttrs" data-mw='{"attribs":[[{"txt":"id"},{"html":"&lt;span about=\"#mwt2\" typeof=\"mw:Transclusion\" data-parsoid=&#39;{\"pi\":[[]],\"dsr\":[178,197,null,null]}&#39; data-mw=&#39;{\"parts\":[{\"template\":{\"target\":{\"wt\":\"anchorencode:💩\",\"function\":\"anchorencode\"},\"params\":{},\"i\":0}}]}&#39;>💩&lt;/span>"}]]}'></span></p>

<!-- These two links should produce identical HTML -->
<p><a rel="mw:WikiLink" href="./Parser_test#啤酒" class="mw-selflink-fragment">#啤酒</a> <a rel="mw:WikiLink" href="./Parser_test#啤酒" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#啤酒"},"sa":{"href":"#%E5%95%A4%E9%85%92"}}'>#啤酒</a></p>
!! end

# Parsoid doesn't support this mode
!! test
HTML5 ids: legacy with a fallback to modern
!! config
wgFragmentMode=[ "legacy", "html5" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Foo bar==

==foo Bar==

==Тест==

==Тест==

==тест==

==Hey < # " > % : '==
[[#Foo bar]] [[#foo Bar]] [[#Тест]] [[#тест]] [[#Hey < # " > % : ']]

{{anchorencode:💩}} <span id="{{anchorencode:💩}}"></span>

<!-- These two links should produce identical HTML -->
[[#啤酒]] [[#%E5%95%A4%E9%85%92]]

!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#.D0.A2.D0.B5.D1.81.D1.82"><span class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#.D0.A2.D0.B5.D1.81.D1.82_2"><span class="tocnumber">4</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#.D1.82.D0.B5.D1.81.D1.82"><span class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="#Hey_.3C_.23_.22_.3E_.25_:_.27"><span class="tocnumber">6</span> <span class="toctext">Hey &lt; # " &gt;&#160;%&#160;: '</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Foo_bar">Foo bar</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 bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="foo_Bar_2">foo 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: foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id=".D0.A2.D0.B5.D1.81.D1.82"><span id="Тест"></span>Тест</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>
<div class="mw-heading mw-heading2"><h2 id=".D0.A2.D0.B5.D1.81.D1.82_2"><span id="Тест_2"></span>Тест</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id=".D1.82.D0.B5.D1.81.D1.82"><span id="тест"></span>тест</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: тест">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Hey_.3C_.23_.22_.3E_.25_:_.27"><span id="Hey_&lt;_#_&quot;_&gt;_%_:_'"></span>Hey &lt; # " &gt;&#160;%&#160;: '</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Hey &lt; # &quot; &gt;&#160;%&#160;: &#39;">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a href="#.D0.A2.D0.B5.D1.81.D1.82">#Тест</a> <a href="#.D1.82.D0.B5.D1.81.D1.82">#тест</a> <a href="#Hey_.3C_.23_.22_.3E_.25_:_.27">#Hey &lt; # " &gt;&#160;%&#160;: '</a>
</p><p>.F0.9F.92.A9 <span id=".F0.9F.92.A9"></span>
</p><p><a href="#.E5.95.A4.E9.85.92">#啤酒</a> <a href="#.E5.95.A4.E9.85.92">#啤酒</a>
</p>
!! end

# Parsoid doesn't support this mode.
!! test
HTML5 ids: no legacy
!! config
wgFragmentMode=[ "html5" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Foo bar==

==foo Bar==

==Тест==

==Тест==

==тест==

==Hey < # " > % : '==
[[#Foo bar]] [[#foo Bar]] [[#Тест]] [[#тест]] [[#Hey < # " > % : ']]

{{anchorencode:💩}} <span id="{{anchorencode:💩}}"></span>

<!-- These two links should produce identical HTML -->
[[#啤酒]] [[#%E5%95%A4%E9%85%92]]

!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#Foo_bar"><span class="tocnumber">1</span> <span class="toctext">Foo bar</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#foo_Bar_2"><span class="tocnumber">2</span> <span class="toctext">foo Bar</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#Тест"><span class="tocnumber">3</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#Тест_2"><span class="tocnumber">4</span> <span class="toctext">Тест</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#тест"><span class="tocnumber">5</span> <span class="toctext">тест</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="#Hey_&lt;_#_&quot;_&gt;_%_:_&#39;"><span class="tocnumber">6</span> <span class="toctext">Hey &lt; # " &gt;&#160;%&#160;: '</span></a></li>
</ul>
</div>

<div class="mw-heading mw-heading2"><h2 id="Foo_bar">Foo bar</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 bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="foo_Bar_2">foo 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: foo Bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Тест">Тест</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>
<div class="mw-heading mw-heading2"><h2 id="Тест_2">Тест</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: Тест">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="тест">тест</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: тест">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="Hey_&lt;_#_&quot;_&gt;_%_:_'">Hey &lt; # " &gt;&#160;%&#160;: '</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=6" title="Edit section: Hey &lt; # &quot; &gt;&#160;%&#160;: &#39;">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><a href="#Foo_bar">#Foo bar</a> <a href="#foo_Bar">#foo Bar</a> <a href="#Тест">#Тест</a> <a href="#тест">#тест</a> <a href="#Hey_&lt;_#_&quot;_&gt;_%_:_&#39;">#Hey &lt; # " &gt;&#160;%&#160;: '</a>
</p><p>💩 <span id="💩"></span>
</p><p><a href="#啤酒">#啤酒</a> <a href="#啤酒">#啤酒</a>
</p>
!! end

!! test
T90902: Normalize weird characters in section IDs
!! config
wgFragmentMode=[ "html5", "legacy" ]
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Foo&nbsp;bar==
[[#Foo&nbsp;bar]]

!! html/php
<div class="mw-heading mw-heading2"><h2 id="Foo_bar">Foo&#160;bar</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&#160;bar">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<p><a href="#Foo_bar">#Foo&#160;bar</a>
</p>
!! html/parsoid
<h2 id="Foo_bar">Foo<span typeof="mw:Entity" data-parsoid='{"src":"&amp;nbsp;","srcContent":" "}'> </span>bar</h2>
<p><a rel="mw:WikiLink" href="./Parser_test#Foo_bar" class="mw-selflink-fragment" data-parsoid='{"stx":"simple","a":{"href":"./Parser_test#Foo_bar"},"sa":{"href":"#Foo&amp;nbsp;bar"}}'>#Foo bar</a></p>
!! end

!! test
mw-heading wrapper edge cases
!! options
notoc
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==Normal heading!==

<h2>HTML heading!</h2>

<h2 style="border: 1px solid green; background: lightgreen; padding: 5px; font-size: 1.5em;">HTML heading with attributes!</h2>

<div class="mw-heading mw-heading2">
==Normal heading with existing wrapper!==
</div>
!! html/php

<div class="mw-heading mw-heading2"><h2 id="Normal_heading.21">Normal 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: Normal heading!">edit</a><span class="mw-editsection-bracket">]</span></span></div>
<div class="mw-heading mw-heading2"><h2 id="HTML_heading.21">HTML heading!</h2></div>
<h2 id="HTML_heading_with_attributes.21" style="border: 1px solid green; background: lightgreen; padding: 5px; font-size: 1.5em;">HTML heading with attributes!</h2>
<div class="mw-heading mw-heading2">
<h2 id="Normal_heading_with_existing_wrapper.21">Normal heading with existing wrapper!</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: Normal heading with existing wrapper!">edit</a><span class="mw-editsection-bracket">]</span></span>
</div>
!! html/parsoid
<h2 id="Normal_heading!" data-parsoid='{"dsr":[0,19,2,2]}'><span id="Normal_heading.21" typeof="mw:FallbackId" data-parsoid='{"dsr":[2,2,null,null]}'></span>Normal heading!</h2>

<h2 id="HTML_heading!" data-parsoid='{"stx":"html","dsr":[21,43,4,5]}'><span id="HTML_heading.21" typeof="mw:FallbackId" data-parsoid='{"dsr":[25,25,null,null]}'></span>HTML heading!</h2>

<h2 style="border: 1px solid green; background: lightgreen; padding: 5px; font-size: 1.5em;" id="HTML_heading_with_attributes!" data-parsoid='{"stx":"html","dsr":[45,172,93,5]}'><span id="HTML_heading_with_attributes.21" typeof="mw:FallbackId" data-parsoid='{"dsr":[138,138,null,null]}'></span>HTML heading with attributes!</h2>

<div class="mw-heading mw-heading2" data-parsoid='{"stx":"html","dsr":[174,259,36,6]}'>
<h2 id="Normal_heading_with_existing_wrapper!" data-parsoid='{"dsr":[211,252,2,2]}'><span id="Normal_heading_with_existing_wrapper.21" typeof="mw:FallbackId" data-parsoid='{"dsr":[213,213,null,null]}'></span>Normal heading with existing wrapper!</h2>
</div>
!! end

!! test
T365413: Headings with dollar signs
!! options
wgParserEnableLegacyHeadingDOM=false
!! wikitext
==$text==

==$ text==

==text $text==

==\$text==

==$$text==
!! html/php
<div id="toc" class="toc" role="navigation" aria-labelledby="mw-toc-heading"><input type="checkbox" role="button" id="toctogglecheckbox" class="toctogglecheckbox" style="display:none" /><div class="toctitle" lang="en" dir="ltr"><h2 id="mw-toc-heading">Contents</h2><span class="toctogglespan"><label class="toctogglelabel" for="toctogglecheckbox"></label></span></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="#.24text"><span class="tocnumber">1</span> <span class="toctext">$text</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="#.24_text"><span class="tocnumber">2</span> <span class="toctext">$ text</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="#text_.24text"><span class="tocnumber">3</span> <span class="toctext">text $text</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="#.5C.24text"><span class="tocnumber">4</span> <span class="toctext">\$text</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="#.24.24text"><span class="tocnumber">5</span> <span class="toctext">$$text</span></a></li>
</ul>
</div>

<h2><span class="mw-headline" id=".24text">$text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=1" title="Edit section: $text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id=".24_text">$ text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=2" title="Edit section: $ text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id="text_.24text">text $text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=3" title="Edit section: text $text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id=".5C.24text">\$text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=4" title="Edit section: \$text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
<h2><span class="mw-headline" id=".24.24text">$$text</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Parser_test&amp;action=edit&amp;section=5" title="Edit section: $$text">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
!! end

!! article
Template:With a section?
!! text
=== test ===
!! endarticle

!! test
T368334: Headings from template titles that would need uri encoding
!! options
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{With a section?}}
!! html/php
<div class="mw-heading mw-heading3"><h3 id="test">test</h3><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Template:With_a_section%3F&amp;action=edit&amp;section=T-1" title="Edit section: test">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">
<h3 typeof="mw:Transclusion" id="test" data-mw='{"parts":[{"template":{"target":{"wt":"With a section?","href":"./Template:With_a_section%3F"},"params":{},"i":0}}]}'>test</h3>
</section>
!! metadata
Sections:
 h3 index:T-1 toclevel:1 number:1 title:Template:With_a_section? off:NULL anchor/linkAnchor:test line:test
!! end

!! article
Template:With one
!! text
=== in ===
123
!! endarticle

!! article
Template:With two
!! text
=== in 2 ===
456

=== in 3 ===
789
!! endarticle

!! test
Reset section numbering per template
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
=== out ===
123

{{with one}}

=== out 2 ===
456

{{with two}}

{{with one}}
!! metadata
Sections:
 h3 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:out line:out
 h3 index:T-1 toclevel:1 number:2 title:Template:With_one off:NULL anchor/linkAnchor:in line:in
 h3 index:2 toclevel:1 number:3 title:Parser_test off:31 anchor/linkAnchor:out_2 line:out 2
 h3 index:T-1 toclevel:1 number:4 title:Template:With_two off:NULL anchor/linkAnchor:in_2 line:in 2
 h3 index:T-2 toclevel:1 number:5 title:Template:With_two off:NULL anchor/linkAnchor:in_3 line:in 3
 h3 index:T-1 toclevel:1 number:6 title:Template:With_one off:NULL anchor/linkAnchor:in_4 line:in
!! end

!! article
Template:With heading nesting
!! text
=== in 4 ===
lala

{{with two}}
!! endarticle

## FIXME: Parsoid doesn't have insight into nested templates
!! test
Nested section numbering
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
=== out ===
123

{{with heading nesting}}
!! metadata
Sections:
 h3 index:1 toclevel:1 number:1 title:Parser_test off:0 anchor/linkAnchor:out line:out
 h3 index:T-1 toclevel:1 number:2 title:Template:With_heading_nesting off:NULL anchor/linkAnchor:in_4 line:in 4
 h3 index:T-1 toclevel:1 number:3 title:Template:With_two off:NULL anchor/linkAnchor:in_2 line:in 2
 h3 index:T-2 toclevel:1 number:4 title:Template:With_two off:NULL anchor/linkAnchor:in_3 line:in 3
!! end

!! article
Template:With redirect
!! text
#REDIRECT [[Template:With one]]
!! endarticle

!! test
Sections follow template redirects
!! options
nohtml
showtocdata
parsoid={
	"modes": [ "wt2html" ],
	"wrapSections": true
}
!! config
wgParserEnableLegacyHeadingDOM=false
!! wikitext
{{with redirect}}
!! metadata
Sections:
 h3 index:T-1 toclevel:1 number:1 title:Template:With_one off:NULL anchor/linkAnchor:in line:in
!! end
