TOC links might have an unwanted trailing dash character in their paths

Created on 25 May 2021, over 3 years ago
Updated 30 August 2024, 4 months ago

Problem/Motivation

Any trailing whitespace or non-alphabetical character gets converted into an extra trailing dash in their corresponding TOC menu links.

Steps to reproduce

Try adding an extra space character after your heading elements or simply end one with a question mark.
Examples:

  • <h2 class="anchor">Academic Writing Submission(s)&nbsp;</h2> translates into #toc-academic-writing-submission-s-
  • <h2 class="anchor">Recommendation&nbsp;</h2> translates into #toc-recommendation-
  • <h2 class="anchor">Who can apply?</h2> translates into #toc-who-can-apply-

Proposed resolution

Use jQuery's trim() function after the conversion to alphabetical.

Remaining tasks

  1. Test and review patch from #1.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇭🇺Hungary zserno

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium LRoels Ghent

    The issue stated above also happens when the HTML is formed as follows:

    <h2>
        <div>My title goes here</div>
    </h2>
    

    Forgetting for a moment that this is not the HTML structure all sites would use, it does have the same issue as described in the original report.
    Using the attached patch also strips the trailing - in these cases.

    Putting this as RTBC since this is a small fix to implement.

  • 🇫🇷France mably

    FYI it has been fixed in the new 3.0.x-dev version.

  • Status changed to Fixed 4 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024