Nav is empty if selector for heading are not h1,h2,etc. selector

Created on 17 September 2024, 3 months ago

Problem/Motivation

Looks like 3.x introduces a bug if selector headings are not title tag.

If I want to generate a Toc of eelement inside adic wth the class title-fake for example.
Then all the element are well processed ad get an Id

<div class="title-fake" id="toc-titre-2-1-fake">Titre 2.1 fake</div>

But the nav of the toc is still empty.

Steps to reproduce

Configure a TOC with the selectors "div.title-fake".
In a body with full_html format, write some text and some div tag with the class title-fake.
The nav TOC is still empty.

Proposed resolution

I guess the bug occurs in function processHeadings(tocObj) {} in the asset tocjs.js

line 336
const level = heading.tagName.slice(-1);
For a heading which is not a title tag, I get as value for the level the string "V" as the tagname is "DIV".
And so the next logic is wrong as we are trying to compare levels of tag element which have not levels.

I suggest to handle this by checking if the selectors used matches title tag. If in the selectors used we found a tag wich id not a title tag (so for example div.title-fake), we should considerer that we can not anymore trying to order the TOC and then we should process the headings without trying to order it.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇫🇷France flocondetoile Lyon

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024