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

Non working internal links for manually added anchors in 0.9.2 #748

Open
jenshnielsen opened this issue May 31, 2023 · 4 comments
Open

Non working internal links for manually added anchors in 0.9.2 #748

jenshnielsen opened this issue May 31, 2023 · 4 comments

Comments

@jenshnielsen
Copy link

jenshnielsen commented May 31, 2023

In 0.9.2 I am seeing a warning about undefined labels for internal links starting with # when building the html version of my docs and the links are not working.

A minimal notebook that triggers this behavior is something like the following

# LinkExample

## Table of Contents <a class="anchor" id="toc"></a>

 * [LinkInSameCell](#link)

## Section <a class="anchor" id="link"></a>
([back to ToC](#toc))

This triggers warnings like the ones below and does not generate working links.

...LinkExample.ipynb:14: WARNING: undefined label: '/examples/linkexample.ipynb#link'
...LinkExample.ipynb:19: WARNING: undefined label: '/examples/linkexample.ipynb#toc'

This used to work with 0.9.1 and I have bisected this to break with #725

It seems that if I remove the manual anchors from my notebook and use the automatically generated ones this works fine. However due to the way my notebook is structured (with an introduction to each term and a longer section) these are not always unique causing the link to be to the wrong location

jenshnielsen added a commit to QCoDeS/broadbean that referenced this issue May 31, 2023
fixes problems with links in nbsphinx 0.9.2 but breaks due to non unique labels
spatialaudio/nbsphinx#748
@mgeier
Copy link
Member

mgeier commented Jun 6, 2023

This is just a warning, so you are getting the correct HTML output, right?

If you want to silence the warning, I think you can put that into your conf.py:

suppress_warnings = ['ref.ref']

The reason for this warning is that Sphinx is not aware of those manual anchors.
I think it would be possible to parse those and make them known to Sphinx, but I don't think it is trivial, and I'm not planning to do that. But if someone wants to implement this, I'm open for PRs!

BTW, if possible, I would just try to change the section titles slightly to avoid ambiguities.

@jenshnielsen
Copy link
Author

No it’s not just a warning. With 0.9.1 this produces working links with this does not produce working links

@mgeier
Copy link
Member

mgeier commented Jun 11, 2023

No it’s not just a warning.

Sorry, I haven't read your original report thoroughly enough, I have now seen that you have mentioned that already.

I have tried it with nbsphinx 0.9.1, and it doesn't work either!

This may be related to the pandoc version, though. I have 2.17.1.1 and it seems to strip the anchors from the headers. And even if the links are created as expected, it doesn't help if the anchors are gone.

Your header looks like this in the generated HTML:

<h2>Table of Contents<a class="headerlink" href="#Table-of-Contents" title="Permalink to this heading">#</a></h2>

If your pandoc version doesn't do that, you can try this work-around:

[LinkInSameCell](linkexample.html#link)

Note the .html! I normally wouldn't recommend using that, but in your case it might work.

@jenshnielsen
Copy link
Author

@mgeier Thanks I will try that when I have a sec (or it may simply be a better option to rework my notebooks to avoid duplicated headings)

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

No branches or pull requests

2 participants