On Sun, 14 Jul 2024 at 11:58, James Addison <[email protected]> wrote:
>
> On Fri, 12 Jul 2024 at 19:10, James Addison <[email protected]> wrote:
> > [ ... snip ... ]
> > Adding the patch would unnecessarily add the event handler to _all_ menu 
> > items;
> > now it seems to me that that's not what we want.  We only need the event
> > handler for links that refer to the same '.html' file.  But: that is all of
> > them in the 'singlehtml' build output.
>
> I'll have to check whether this works and is supported in most browsers, but
> there is a CSS anchor:local-link pseudo-selector[1] that might allow filtering
> to exactly these links.  In combination with omitting the '.current' filter,
> that would achieve the intended logical effect, I think.
>
> [1] - https://developer.mozilla.org/en-US/docs/Web/CSS/:local-link

No, the local-link CSS pseudo-selector doesn't seem suitable:

1. It is not yet supported in many (any?) browsers.

2. As per the current draft CSS Working Group specification[1], the comparison
   of the hyperlink target URL against the current URL _includes_ the fragment
   (the part after the '#' symbol after the filename in the URL) in the
   comparison:

   [draft quote] "If the hyperlink's target includes a fragment URL, then the
   fragment URL of the current URL must also match; ..." [end draft quote]

I've considered attaching the event handler to any menu hyperlinks whose href
attribute starts with a '#' character (CSS queries can
prefix-match[2]).  However,
currently some singlehtml menu hyperlinks contain the '.html' filename
part.  That
may change if https://github.com/sphinx-doc/sphinx/pull/12551 is
merged upstream.

The next alternative would be to use some JQuery logic to dynamically attach to
hyperlinks that are the same-document based on some custom logic.

[1] - https://drafts.csswg.org/selectors/#the-local-link-pseudo

[2] - https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors#links

Reply via email to