1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
# This file has tests to verify TOC section metadata output for wikitext snippets
!! options
version=2
!! end
!! 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
}
!! wikitext
==h1==
===h1.1===
==h2==
===h2.1===
====h2.1.1====
===h2.2===
====h2.2.1====
====h2.2.2====
==h3==
!! html
{"toclevel":1,"level":"2","line":"h1","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"h1","linkAnchor":"h1"}
{"toclevel":2,"level":"3","line":"h1.1","number":"1.1","index":"2","fromtitle":"Parser_test","byteoffset":7,"anchor":"h1.1","linkAnchor":"h1.1"}
{"toclevel":1,"level":"2","line":"h2","number":"2","index":"3","fromtitle":"Parser_test","byteoffset":18,"anchor":"h2","linkAnchor":"h2"}
{"toclevel":2,"level":"3","line":"h2.1","number":"2.1","index":"4","fromtitle":"Parser_test","byteoffset":25,"anchor":"h2.1","linkAnchor":"h2.1"}
{"toclevel":3,"level":"4","line":"h2.1.1","number":"2.1.1","index":"5","fromtitle":"Parser_test","byteoffset":36,"anchor":"h2.1.1","linkAnchor":"h2.1.1"}
{"toclevel":2,"level":"3","line":"h2.2","number":"2.2","index":"6","fromtitle":"Parser_test","byteoffset":51,"anchor":"h2.2","linkAnchor":"h2.2"}
{"toclevel":3,"level":"4","line":"h2.2.1","number":"2.2.1","index":"7","fromtitle":"Parser_test","byteoffset":62,"anchor":"h2.2.1","linkAnchor":"h2.2.1"}
{"toclevel":3,"level":"4","line":"h2.2.2","number":"2.2.2","index":"8","fromtitle":"Parser_test","byteoffset":77,"anchor":"h2.2.2","linkAnchor":"h2.2.2"}
{"toclevel":1,"level":"2","line":"h3","number":"3","index":"9","fromtitle":"Parser_test","byteoffset":92,"anchor":"h3","linkAnchor":"h3"}
!! end
!! test
HTML headings should get TOC entries with some empty properties
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==a==
<h2>b</h2>
<h3>c</h3>
===d===
<h2>e</h2>
!! html
{"toclevel":1,"level":"2","line":"a","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"a","linkAnchor":"a"}
{"toclevel":1,"level":"2","line":"b","number":"2","index":"","fromtitle":false,"byteoffset":null,"anchor":"b","linkAnchor":"b"}
{"toclevel":2,"level":"3","line":"c","number":"2.1","index":"","fromtitle":false,"byteoffset":null,"anchor":"c","linkAnchor":"c"}
{"toclevel":2,"level":"3","line":"d","number":"2.2","index":"2","fromtitle":"Parser_test","byteoffset":28,"anchor":"d","linkAnchor":"d"}
{"toclevel":1,"level":"2","line":"e","number":"3","index":"","fromtitle":false,"byteoffset":null,"anchor":"e","linkAnchor":"e"}
!! end
!! test
Duplicate headings should get unique anchors
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==a==
==a==
==b==
!! html
{"toclevel":1,"level":"2","line":"a","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"a","linkAnchor":"a"}
{"toclevel":1,"level":"2","line":"a","number":"2","index":"2","fromtitle":"Parser_test","byteoffset":6,"anchor":"a_2","linkAnchor":"a_2"}
{"toclevel":1,"level":"2","line":"b","number":"3","index":"3","fromtitle":"Parser_test","byteoffset":12,"anchor":"b","linkAnchor":"b"}
!! end
!! test
Templated sections (heading from template content)
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==a==
{{Test}}
!! html
{"toclevel":1,"level":"2","line":"a","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"a","linkAnchor":"a"}
{"toclevel":1,"level":"2","line":"th2","number":"2","index":"T-1","fromtitle":"Template:Test","byteoffset":null,"anchor":"th2","linkAnchor":"th2"}
{"toclevel":2,"level":"3","line":"th2.1","number":"2.1","index":"T-2","fromtitle":"Template:Test","byteoffset":null,"anchor":"th2.1","linkAnchor":"th2.1"}
!! end
!! test
Ensure headings with html tags get the right anchors
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==<span>x</span>==
==<strike>y</strike>==
!! html
{"toclevel":1,"level":"2","line":"<span>x<\/span>","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"x","linkAnchor":"x"}
{"toclevel":1,"level":"2","line":"<strike>y<\/strike>","number":"2","index":"2","fromtitle":"Parser_test","byteoffset":19,"anchor":"y","linkAnchor":"y"}
!! end
!! test
Ensure unallowed tag wrappers in headings get stripped
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==<div>b</div>==
==<font>c</font>==
!! html
{"toclevel":1,"level":"2","line":"b","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"b","linkAnchor":"b"}
{"toclevel":1,"level":"2","line":"c","number":"2","index":"2","fromtitle":"Parser_test","byteoffset":17,"anchor":"c","linkAnchor":"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
}
!! wikitext
==<span dir='ltr' title='x'>a</span>==
==<span dir='rtl' title='x'>b</span>==
==<i dir='rtl' title='ha'>c</i>==
!! html
{"toclevel":1,"level":"2","line":"<span dir=\"ltr\">a<\/span>","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"a","linkAnchor":"a"}
{"toclevel":1,"level":"2","line":"<span dir=\"rtl\">b<\/span>","number":"2","index":"2","fromtitle":"Parser_test","byteoffset":39,"anchor":"b","linkAnchor":"b"}
{"toclevel":1,"level":"2","line":"<i>c<\/i>","number":"3","index":"3","fromtitle":"Parser_test","byteoffset":78,"anchor":"c","linkAnchor":"c"}
!! 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
}
!! wikitext
==<span><div></div></span>x==
==<span dir='ltr'><i dir='ltr'></i></span>y==
!! html/php
{"toclevel":1,"level":"2","line":"x","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"x","linkAnchor":"x"}
{"toclevel":1,"level":"2","line":"<span dir=\"ltr\"><i><\/i><\/span>y","number":"2","index":"2","fromtitle":"Parser_test","byteoffset":30,"anchor":"y","linkAnchor":"y"}
!! html/parsoid
{"toclevel":1,"level":"2","line":"x","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"x","linkAnchor":"x"}
{"toclevel":1,"level":"2","line":"y","number":"2","index":"2","fromtitle":"Parser_test","byteoffset":30,"anchor":"y","linkAnchor":"y"}
!! end
!! test
Handle links in heading content
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==[[Cat]]==
==[[Dog]]s==
==[[Cat|I love my ''cat'']]==
!! html
{"toclevel":1,"level":"2","line":"Cat","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"Cat","linkAnchor":"Cat"}
{"toclevel":1,"level":"2","line":"Dogs","number":"2","index":"2","fromtitle":"Parser_test","byteoffset":12,"anchor":"Dogs","linkAnchor":"Dogs"}
{"toclevel":1,"level":"2","line":"I love my <i>cat<\/i>","number":"3","index":"3","fromtitle":"Parser_test","byteoffset":25,"anchor":"I_love_my_cat","linkAnchor":"I_love_my_cat"}
!! 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" ]
!! wikitext
===a=
=''x''=
!! html
{"toclevel":1,"level":"1","line":"==a","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"==a","linkAnchor":"==a"}
{"toclevel":1,"level":"1","line":"<i>x<\/i>","number":"2","index":"2","fromtitle":"Parser_test","byteoffset":6,"anchor":"x","linkAnchor":"x"}
!! 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
}
!! wikitext
==a==
{{1x|1=
==b==
}}
!! html/php
{"toclevel":1,"level":"2","line":"a","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"a","linkAnchor":"a"}
{"toclevel":1,"level":"2","line":"b","number":"2","index":"","fromtitle":false,"byteoffset":null,"anchor":"b","linkAnchor":"b"}
!! html/parsoid
{"toclevel":1,"level":"2","line":"a","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"a","linkAnchor":"a"}
{"toclevel":1,"level":"2","line":"b","number":"2","index":"T-2","fromtitle":"Template:1x","byteoffset":null,"anchor":"b","linkAnchor":"b"}
!! html/parsoid+integrated
{"toclevel":1,"level":"2","line":"a","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"a","linkAnchor":"a"}
{"toclevel":1,"level":"2","line":"b","number":"2","index":"T-1","fromtitle":"Template:1x","byteoffset":null,"anchor":"b","linkAnchor":"b"}
!! end
# FIXME:
# 1. This potentially exposes a subtle issue in the interaction between TOC, Cite, and
# localization. Parsoid doesn't localize numbers in Cite (at all!) since it relies on CSS.
# But, with the legacy parser, a wiki with localized numbers will have an anchor
# based off a localized number if a <ref> is used in a heading. Parsoid won't!.
# 2. We probably should be a bit smarter about what to strip for tags when that output
# comes from extensions. Below, we have stripped all extension typeofs and info.
# But, depends on who uses this 'line' property and how.
# FIXME: test disabled because CI doesn't have the Cite extension installed
!! test
Handle extension content in section headers properly
!! config
wgFragmentMode=[ "html5", "legacy" ]
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==c<ref>d</ref>==
!! html+disabled
{"toclevel":1,"level":"2","line":"c<sup>[1]<\/sup>","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"c[1]","linkAnchor":"c[1]"}
!! html/parsoid
{"toclevel":1,"level":"2","line":"c<sup><span>[1]<\/span><\/sup>","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"c[1]","linkAnchor":"c[1]"}
!! end
# FIXME: This test shows a similar difference between legacy and
# Parsoid output, but it may be due to a subtle difference in the
# whitespace emitted by the parser test runner's <tag> implementation
!! test
Handle extension content in section headers properly (non-Cite version)
!! config
wgFragmentMode=[ "html5", "legacy" ]
!! options
nohtml
showtocdata
parsoid={
"modes": [ "wt2html" ],
"wrapSections": true
}
!! wikitext
==c<tag>d</tag>==
!! html
{"toclevel":1,"level":"2","line":"c\n'd'\narray (\n)","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"c_'d'_array_(_)","linkAnchor":"c_'d'_array_(_)"}
!! html/parsoid
{"toclevel":1,"level":"2","line":"c'd'\narray (\n)","number":"1","index":"1","fromtitle":"Parser_test","byteoffset":0,"anchor":"c'd'_array_(_)","linkAnchor":"c'd'_array_(_)"}
!! end
|