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

Cannot cross-reference a specific section in a notebook page

Open adityarao-freenome opened this issue 3 years ago • 2 comments

Describe the bug

When I try to cross-reference a specific section of a notebook page, the hyperlink just takes me to the top of that notebook page instead of the specific place in the page that I placed the reference.

This is a problem because I want to directly point people towards specific sections of my notebooks (e.g. to show blocks of analysis that are too long for the markdown pages, or to show things that only render correctly in the notebook pages like plotly plots) but I'm not able to do that if the reference just takes me to the top of the notebook page.

Reproduce the bug

For example, if I have this in a markdown cell in the middle of my notebook:

(test-section)=
#### Header for test section

And then I include this in one of the markdown pages:

Check out the test section [here](test-section)

Then when I click on the resulting hyperlink, I just get sent to the top of the notebook page that I placed the test-section reference in.

List your environment

jupyter-book --version

Jupyter Book      : 0.12.3
External ToC      : 0.2.4
MyST-Parser       : 0.15.2
MyST-NB           : 0.13.2
Sphinx Book Theme : 0.1.10
Jupyter-Cache     : 0.4.3
NbClient          : 0.5.13
uname -a

Linux jupyter-arao 5.10.109+ #1 SMP Sun Apr 24 09:09:13 UTC 2022 x86_64 GNU/Linux

Using python 3.9

adityarao-freenome avatar Jun 24 '22 22:06 adityarao-freenome

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar Jun 24 '22 22:06 welcome[bot]

I think I've found a temporary workaround for this bug - the reference tag has to be the same as the sequence of characters that’s added to the url when you manually link to a specific section of the notebook. So for example, this would work correctly:

Notebook file:

(header-for-test-section)=
#### Header for test section

Markdown file:

Check out the test section [here](header-for-test-section)

adityarao-freenome avatar Jun 25 '22 03:06 adityarao-freenome

For me this silences the build error, but the link still does not render

Jupyter Book      : 0.15.1
External ToC      : 0.3.1
MyST-Parser       : 0.18.1
MyST-NB           : 0.17.2
Sphinx Book Theme : 1.0.1
Jupyter-Cache     : 0.6.1
NbClient          : 0.7.4

phelps-sg avatar May 03 '23 16:05 phelps-sg

The workaround I ended up using was to embed an HTML link e.g.

<a href="./Results.html#figure-1">Figure 1</a>

for the notebook Results.ipynb.

phelps-sg avatar May 03 '23 16:05 phelps-sg