Flexibility in targeting heading tags

Created on 16 August 2024, 4 months ago

Problem/Motivation

I am now working with a patched (MR) version of 3.0.x-bdev and I have noticed a regession (I think!).

I used to be able to exempt particular heading (ones sitting inside <div>a of class .heading-class) by using…

But when I do that now, I see no ToC at all and an error in the JavaScript console saying…

Uncaught Error: Syntax error, unrecognized expression: h1, :not(.is-a-group-title-Yes)&gt;h2
    at I.error (jquery.min.js?v=3.7.1:2:11769)...

I can see that the > element of my selector has been escaped.

On the otherhand, I don't even know why I really need to > anyway so this ought to work…

But it does not.

In short, I think it would be very useful to have as much flexibility as possible to exempt certain <h> tags.

πŸ’¬ Support request
Status

Active

Version

3.0

Component

Miscellaneous

Created by

πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset

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

Merge Requests

Comments & Activities

  • Issue created by @SirClickALot
  • Assigned to mably
  • πŸ‡«πŸ‡·France mably

    Will have a look at it.

  • πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset
  • πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset
  • πŸ‡«πŸ‡·France mably

    mably β†’ changed the visibility of the branch 3468538-flexibility-in-targeting to hidden.

  • πŸ‡«πŸ‡·France mably

    @SirClickalot could you give a try to this issue's MR and check that it fixes this headings selector regression?

  • πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset

    @mably, Nice, it fixes it for the first selector I tried (the with the > in it).

    However, it does not exempt the heading when using the second version - i.e without the > and I as far as my understanding of selectors goes, the second case should also cover the first?

  • πŸ‡«πŸ‡·France flocondetoile Lyon

    @mably ok with the decodeHtml.

    @SirClickalot

    However, it does not exempt the heading when using the second version - i.e without the > and I as far as my understanding of selectors goes, the second case should also cover the first?

    Yes it should do. Could you check in your console, in debug mode, if the whitespace in the selector not(.is-a-group-title-Yes) h2 is not escaped too ?

  • πŸ‡«πŸ‡·France mably

    @SirClickalot seems to be working as it should on my side...

  • πŸ‡¬πŸ‡§United Kingdom SirClickALot Somerset

    Nope, case two definitely not working, case 1 good as gold.
    Nothing reported in JavScript Console.

  • πŸ‡«πŸ‡·France mably

    Here is the code that gets the headings:

    function initTocObject(element, opts) {
        const $container = $(opts.container);
        return {
          opts,
          element,
          $element: $(element),
          $container,
          $headings: $(opts.selectors, $container),
          highlightTimeout: null,
          scrollToTimeout: null,
          bodyPaddingTop: 0,
          highlightOnScroll,
          scrollTo,
          scrollListener: undefined,
          updating: false,
        };
      }
    

    We can see that it's pretty simple, a first line of code gets the container:

    const $container = $(opts.container);
    

    opts.container is the container selector specified in the configuration.

    And a second line gets the headings using the container as context:

    $headings: $(opts.selectors, $container),
    

    It's some pretty basic jQuery here.

  • πŸ‡«πŸ‡·France flocondetoile Lyon

    In fact, the selector :not(.is-a-group-title-Yes) h2 match all h2 inside the container. Because even if the direct parent of the h2 has the class "is-a-group-title-Yes", then the parant of this parent don't have this class, and so the h2 inside this parent is also targeted by the css selector :not(.is-a-group-title-Yes) h2 because there is always a parent (ancestor) of the h2 which dont have this class.

    It's a css selector issue here

  • πŸ‡«πŸ‡·France flocondetoile Lyon

    However, it does not exempt the heading when using the second version - i.e without the > and I as far as my understanding of selectors goes, the second case should also cover the first?

    In fact no.

  • Status changed to Fixed 4 months ago
  • πŸ‡«πŸ‡·France mably

    Regression fix has been merged.

    • mably β†’ committed a50b61f1 on 3.0.x
      Issue #3468538 by mably, SirClickalot: Flexibility in targeting heading...
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Issue was unassigned.
  • πŸ‡«πŸ‡·France mably
Production build 0.71.5 2024