anchors add -01

Created on 29 January 2024, 5 months ago
Updated 26 February 2024, 4 months ago

Problem/Motivation

I suspect i am missing something in how this works.

We have a toc type which defines header id type as number_path and header id prefix as "section". So any H2 that is missing an id, it sets the toc url anchor to something like section-1-1. Which won't work as their was no id assigned to the H2. I have written js to add H2 ids in a similar manner as to how they are defined for the toc urls.

And if it does have an id value, then it makes an anchor in the toc url like [id]-01 (ver 1.4). Which breaks the toc from working. Ver 1.3 used just [id] in the anchor, which worked correctly.

Any idea why this was changed?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

1.4

Component

Code

Created by

🇨🇦Canada liquidcms

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @liquidcms
  • Status changed to Needs review 5 months ago
  • 🇬🇧United Kingdom John_B London (UK), Worthing (UK), Innsbruck (Tirol)

    If a heading text appears twice, auto-generated IDs based on the heading text must be unique, so an -01 should be added the second time that text us used to generate an ID

    Also, if the markup contains an ID which is used more than once, which is of course incorrect HTML, the second copy of the ID should be modified by the module by adding -01.

    There is a bug because in certain cases the -01 is being added where it is not required.

    The problem is that in src/Toc.php, the line while (isset($this->ids[$id]) || isset($this->existingIds[$id])) { the part
    isset($this->existingIds[$id])) is returning TRUE for IDs which are not in fact duplicates. Once that is removed, the -01 is added only where there really is a duplicate ID, or a heading with duplicate text from which we risk creating a duplicate ID. A patch is attached.

    Note that Drupal 10 rewrote the core HTML utility, which is used to parse HTML. There are significant differences and this can create bugs. I have not checked whether the problem arose on D9.

  • 🇨🇦Canada liquidcms

    Thanks for this.. will try it out.

  • 🇮🇳India sumithra ramalingam

    @john_B
    #2 patch works fine. Thank you

Production build 0.69.0 2024