Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID of the headings are not unique #12

Open
PxaMMaxP opened this issue Oct 6, 2023 · 0 comments
Open

ID of the headings are not unique #12

PxaMMaxP opened this issue Oct 6, 2023 · 0 comments

Comments

@PxaMMaxP
Copy link

PxaMMaxP commented Oct 6, 2023

The IDs that are automatically assigned to the headings, indirectly via the “slugify” function, are not unique.
This means that these headings cannot be accessed through the table of contents, but only the first heading with the same ID can be reached.

For example, if you have several headings with the name “Summary”, the same ID “summary” is generated for each of them.

To solve this problem, I have changed the code of the “getList” function in one place:

for ($index; $index < $headers->length; $index++) {
            $curr_header = $headers[$index];
            if (isset($curr_header->tagName) && $curr_header->tagName !== '') {
                // Add missing id's to the h tags
                $id = $curr_header->getAttribute('id');
                if ($id === "") {
                    $id = $this->slugify($curr_header->nodeValue) . '-' . $index; // Add the index to the ID
                    $curr_header->setAttribute('id', $id);
                }

This turns several “summary” IDs into “summary-1”, “summary-4”, “summary-n”…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant