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

Use bootstrap ScrollSpy with anchor using dots? #39248

Open
2 tasks done
12rambau opened this issue Sep 28, 2023 · 2 comments
Open
2 tasks done

Use bootstrap ScrollSpy with anchor using dots? #39248

12rambau opened this issue Sep 28, 2023 · 2 comments

Comments

@12rambau
Copy link

12rambau commented Sep 28, 2023

Prerequisites

Context

In the development of the pydata-sphinx-theme we use extensively twitter bootstrap to build the UI of a Sphinx generated documentation. When documenting Python API, the Autodoc plugin (that reads the Python docstring and transform it into a documentation page) creates anchors for functions that correspond to the exact path f the method: "pandas.DataFrame.from_csv". These points seems to be incompatible with the twitter bootstrap ScrollSpy tool as they are not interpreted as correct anchors.

For interested reader, see this thread for more context: pydata/pydata-sphinx-theme#1435

reproducible example

I created this small fiddle by adapting one of bootstrap example: https://codepen.io/12rambau/pen/rNovoyw

<div id="container" class="row">
  <div id="list-example" class="list-group col-4">
    <a class="list-group-item list-group-item-action" href="#item.1">Item 1</a>
    <a class="list-group-item list-group-item-action" href="#item.2">Item2</a>
    <a class="list-group-item list-group-item-action" href="#item.3">Item 3</a>
    <a class="list-group-item list-group-item-action" href="#item.4">Item 4</a>
  </div>
  <div class=col-8>
    <div data-spy="scroll" data-target="#list-example" data-offset="0" class="scrollspy-example">
      <h4 id="item.1">Item 1</h4>
      <p> ... </p>
      <h4 id="item.2">Item 2</h4>
      <p> ...</p>
      <h4 id="item.3">Item 3</h4>
      <p> ... </p>
      <h4 id="item.4">Item 4</h4>
      <p> ... </p>
    </div>
  </div>
</div>

As you see it's simply not working as I replaced the target names by "item.1" instead of "item 1".

Going down this issue, it seems related to how uri are parsed in bootstrap. Is there any will to support my use case ? if yes how can I help, if not do you see a workaround that would not imply using custom scrollspy ?

@julien-deramond
Copy link
Member

julien-deramond commented Sep 28, 2023

Thanks for opening this issue @12rambau.
I haven't checked in detail this precise use case yet but it could be linked to my comment here #39201 (review) where it seems that the specification really allows almost all characters as IDs and that maybe our selector engine is too restrictive in a way.
We need to dig that :)

Note: depending on how this issue is treated, if the modification is approved, we definitely need to add this use case (and others) as unit tests.

@flack
Copy link

flack commented Jan 17, 2024

just wanted to add that we've stumbled across this problem, too. It basically affects all JS modules, e.g. modal, collapse, etc. As soon as the ID has anything in it that has a special meaning in a selector (e.g. ., ,, +, ~), the functionality breaks. According to HTML standards, the only character that's not allowed in an ID is a whitespace, so it would be great if bootstrap could support that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants