Index: trunk/extensions/LabeledSectionTransclusion/lstParserTests.txt |
— | — | @@ -267,7 +267,31 @@ |
268 | 268 | </p> |
269 | 269 | !!end |
270 | 270 | |
| 271 | +!!article |
| 272 | +lst_head_bounds |
| 273 | +!!text |
| 274 | +=== |
| 275 | +=2= |
| 276 | +<section begin=s/> |
| 277 | +=3= |
| 278 | +hi |
| 279 | +=4= |
| 280 | +<section end=s/> |
| 281 | +=head4= |
| 282 | +!!endarticle |
| 283 | +!!test |
| 284 | +more sensitive test for heading count boundaries. |
| 285 | +!!input |
| 286 | +{{#lst:lst_head_bounds|s}} |
| 287 | +!!result |
| 288 | +<a name="3"></a><h1><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Lst_head_bounds&action=edit&section=3" title="Lst head bounds">edit</a>]</span> <span class="mw-headline">3</span></h1> |
| 289 | +<p>hi |
| 290 | +</p> |
| 291 | +<a name="4"></a><h1><span class="editsection">[<a href="https://www.mediawiki.org/index.php?title=Lst_head_bounds&action=edit&section=4" title="Lst head bounds">edit</a>]</span> <span class="mw-headline">4</span></h1> |
271 | 292 | |
| 293 | +!!end |
| 294 | + |
| 295 | + |
272 | 296 | !!test |
273 | 297 | Nick's bogus input |
274 | 298 | !!input |
Index: trunk/extensions/LabeledSectionTransclusion/lst.php |
— | — | @@ -165,8 +165,21 @@ |
166 | 166 | */ |
167 | 167 | function wfLst_count_headings_($text,$limit) |
168 | 168 | { |
169 | | - $pat = '^(={1,6}).+\1\s*$'; |
170 | | - return preg_match_all( "/$pat/im", substr($text,0,$limit), $m); |
| 169 | + $pat = '^(={1,6}).+\1\s*$()'; |
| 170 | + |
| 171 | + //return preg_match_all( "/$pat/im", substr($text,0,$limit), $m); |
| 172 | + |
| 173 | + $count = 0; |
| 174 | + $offset = 0; |
| 175 | + while (preg_match("/$pat/im", $text, $m, PREG_OFFSET_CAPTURE, $offset)) { |
| 176 | + if ($m[2][1] > $limit) |
| 177 | + break; |
| 178 | + |
| 179 | + $count++; |
| 180 | + $offset = $m[2][1]; |
| 181 | + } |
| 182 | + |
| 183 | + return $count; |
171 | 184 | } |
172 | 185 | |
173 | 186 | /** |