Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anchor tracking for TOC not working with anchors within tables #4689

Closed
5 tasks done
mh166 opened this issue Nov 29, 2022 · 4 comments
Closed
5 tasks done

Anchor tracking for TOC not working with anchors within tables #4689

mh166 opened this issue Nov 29, 2022 · 4 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@mh166
Copy link

mh166 commented Nov 29, 2022

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the mkdocs or readthedocs themes
  • ... the problem persists when all overrides are removed, i.e. custom_dir, extra_javascript and extra_css
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

As discussed previously, I went ahead and added custom anchors to the page's TOC.

Unfortunately, when scrolling down, anchors that reside within a <table> are not tracked correctly.

From what I've seen, src/assets/javascripts/components/toc/index.ts is responsible for this functionality. Maybe somewhere starting from Line #158? Unfortunately, it's above my level of expertise to understand where the strange behaviour is coming from.

Expected behaviour

Within the TOC, the section currently in view should be highlighted.

Actual behaviour

This does work only for anchors that DO NOT reside within a <table>. Those behave absolutely correctly.

But with those inside a <table> it is strange: is the page scrolled to the very top, an anchor from within the table is highlighted as active - even though it's not in view. And once you start scrolling, those anchors apparently get ignored.

Steps to reproduce

Result:

  • Just take a look at my example page. This is a minimal project to demo this problem.

Try for yourself:

  • The source code is also available
    • Using the customAnchors.py hook, I look for <strong> tags containing the id="..." attribute. Those get added to the TOC.
  • With the mkdoc's default theme, everything works as expected (clone the repo and remove the material theme definition from the config

Package versions

  • Python: 3.9.4
  • MkDocs: 1.4.0
  • Material: 8.5.3

Configuration

# Can be found here: https://github.com/mh166/mkdocs-custom-anchors/blob/main/mkdocs.yml

site_name: "Demo: problem with anchors within tables"
theme:
  name: material
markdown_extensions:
  - attr_list
copyright: mh166
extra_css:
  - extra.css

hooks:
  - customAnchors.py

System information

I've tried on Windows 10 using multiple browsers (Chrome, Edge, Opera). All show the same behaviour.

@squidfunk squidfunk added the needs investigation Issue must be investigated by the maintainers label Nov 29, 2022
@squidfunk
Copy link
Owner

Thanks for reporting. So yes, it's a bug which stems from the problem that the offset in tables is relative to the table, not to the page. That's actually related to #3453 and #4217. I need some time to generalize the fix, which will also fix this problem.

@squidfunk squidfunk added bug Issue reports a bug and removed needs investigation Issue must be investigated by the maintainers labels Dec 12, 2022
@squidfunk
Copy link
Owner

Fixed in 318903d. Thanks for the excellent reproduction – that made fixing quite simple. I'll revisit how we can generalize offset computation once annotations are released into the community edition once the next funding goal is hit, which I expect to be in February or March. 😊

Releasing a new feature always yields significant refactoring opportunities, like for search recently. Related:

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Jan 8, 2023
@squidfunk
Copy link
Owner

Released as part of 9.0.3.

@mh166
Copy link
Author

mh166 commented Jan 13, 2023

Thanks so much! Glad my example was of help. I'm excited to try this next week and roll back some of my hacky workarounds (mostly visually disabling the tracking... 😅).

Please keep up the great work you do! This project is absolutely amazing! ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

2 participants