From 359e77d7c9cb44b46cc712fbdd9cb97460ef3ff8 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Wed, 15 Apr 2015 13:44:28 -0400 Subject: [PATCH] Parser: Avoid producing in the TOC If someone renames a section but wants old targeted links to still work, is the usual solution. And sometimes people put it inside the section header markup, like == New name == since putting it before makes it be considered part of the previous section while putting it after causes the browser to scroll the section header off the screen. But this has the unfortunate side effect that the TOC text for that section will be "New name". We should strip that useless empty span. Bug: T96153 Change-Id: I47a33ceb79d48f6d0c38fa3b3814a378feb5e31e --- includes/parser/Parser.php | 6 ++++++ tests/parser/parserTests.txt | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 1603fc699f..55066845b7 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4554,6 +4554,12 @@ class Parser { array( '', '<$1>' ), $safeHeadline ); + + # Strip '', which is the result from the above if + # is used to produce an additional anchor + # for a section. + $tocline = str_replace( '', '', $tocline ); + $tocline = trim( $tocline ); # For the anchor, strip out HTML-y stuff period diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 18d9aa85e0..1670fe4cc5 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -13744,6 +13744,22 @@ TOC regression (T11764) !! end +!! test +TOC for heading containing (T96153) +!! wikitext +__FORCETOC__ +==New title== +!! html +

Contents

+ +
+ +

New title[edit]

+ +!! end + !! test TOC with wgMaxTocLevel=3 (bug 6204) !! options -- 2.20.1