Suppress enumeration that is part of the headline in ToC
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 9 Dec 2020 13:49:11 +0000 (14:49 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 9 Dec 2020 13:49:11 +0000 (14:49 +0100)
Resolves #3757

wcfsetup/install/files/lib/system/html/toc/HtmlTocItem.class.php

index 92b42fe7a81f645f2dca6c1eec60e457aded48d9..213a3f35ef0cd18a9a8fdca14702a16b95a73986 100644 (file)
@@ -46,7 +46,15 @@ class HtmlTocItem implements \Countable, \RecursiveIterator {
        }
        
        public function getTitle() {
-               return $this->title;
+               return preg_replace_callback('/^\s*(\d+)([\.):]|\s*-)\s*/', function ($matches) {
+                       // Strip of a enumeration prefix if the prefixed number matches
+                       // the current offset within the ToC.
+                       if ($this->getParent() && intval($matches[1]) === ($this->getParent()->position + 1)) {
+                               return '';
+                       }
+                       
+                       return $matches[0];
+               }, $this->title);
        }
        
        public function setParent($parent) {