jupyter-book icon indicating copy to clipboard operation
jupyter-book copied to clipboard

Scrolling to any cell in the page using URL hash fragment

Open nishikantparmariam opened this issue 2 years ago • 3 comments

Context

There are use-cases where we want to point to a specific section of the book, this can be done using ../my_book/chapter1.html#foo-bar. For this to work, foo bar must be a heading (starting with #, ##, ###...) in a markdown cell.

But, there are some markdown cells that do not have a heading naturally, so with the current behavior it forces the writer to always include a heading. Another solution is to use referencing for such cells.

It would be great if it is possible to scroll to any cell. Using say - cell id ../my_book/chapter1.html#cell-id-1. Open to any workarounds and suggestions.

Proposal

No response

Tasks and updates

No response

nishikantparmariam avatar Aug 18 '22 06:08 nishikantparmariam

Jupyter notebooks have native support for HTML. How about including a tag in your markdown with a unique id that you can reference from your anchor tags?

Something like:

<div id="jump_here"></div>

so that it can be targeted by:

<a href="#jump_here">This is a hyperlink.</a>

MantiMantilla avatar Aug 27 '22 10:08 MantiMantilla

Jupyter notebooks have native support for HTML. How about including a tag in your markdown with a unique id that you can reference from your anchor tags?

This is not the best approach because Jupyter already includes the identifiers for headings - it would lead to a duplication and extra work.

krassowski avatar Jul 03 '24 12:07 krassowski

With Jupyter Book becoming an official Jupyter subproject last week (https://github.com/jupyter/enhancement-proposals/pull/123) I hope that we could finally make some progress on this. All other major Jupyter applications support a uniform hash fragment pattern (Jupyter Notebook 7+, JupyterLab, nbconvert) as implemented in:

  • https://github.com/jupyterlab/jupyterlab/pull/13285
  • https://github.com/jupyter/nbconvert/pull/1897

I opened a PR in MyST-NB for this over a year ago https://github.com/executablebooks/MyST-NB/pull/519 but did not get any reaction. I also opened an issue in https://github.com/executablebooks/mystmd/issues/518 but I also did not get an answer there. @choldgraf as an author of the 122 JEP, do you have any suggestions on how can we make this move forward?

krassowski avatar Jul 03 '24 14:07 krassowski