From 6dc335ae0a77ab24ff800d74969b068c1986ce3e Mon Sep 17 00:00:00 2001 From: Max P Date: Thu, 30 Nov 2023 18:32:06 +0100 Subject: [PATCH] =?UTF-8?q?If=20there=20is=20no=20ID=20for=20a=20heading,?= =?UTF-8?q?=20an=20ID=20is=20generated=20from=20the=20content=20of=20the?= =?UTF-8?q?=20heading.=20In=20the=20case=20of=20repeated=20headings=20(e.g?= =?UTF-8?q?.=20=E2=80=9CSummary=E2=80=9D),=20this=20leads=20to=20an=20ambi?= =?UTF-8?q?guous=20ID.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The problem is solved by adding the index of all headings to the ID generated in this case. Changes to - PHP: If the ID does not exist, the given index is appended to the generated ID. --- TableOfContents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TableOfContents.php b/TableOfContents.php index 1fc5f2c..68b1abc 100644 --- a/TableOfContents.php +++ b/TableOfContents.php @@ -222,7 +222,7 @@ private function getList($document, $headers, &$index = 0) // Add missing id's to the h tags $id = $curr_header->getAttribute('id'); if ($id === "") { - $id = $this->slugify($curr_header->nodeValue); + $id = $this->slugify($curr_header->nodeValue) . '-' . $index; $curr_header->setAttribute('id', $id); }