-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Make markdown header ID and anchor ID unique #77
Comments
Any news here? I can put up a PR for this, if that's better to discuss the issue? If someone has a better idea (aka more stable across notebook reloads), this would be great! It would also probably need a issue for nbviewer, as links to certain headline should be stable there, too. |
If you want ID for cells, that are persistent, you need a change of the notebook format. Which won't happen soon. Cf among other ipython/ipython#3777. It will probably not be for 4.0 at 4.0 will be "no new features". |
We have talked about using the heading levels as structure. If we implemented that, you could create a more unique & stable ID by putting its 'heading path' in the hash - e.g. Short of that, you could also sequentially number headings with the same text - As Matthias says, we don't store any ID for cells - but then even that wouldn't completely solve the issue, because you could repeat the same heading in one long Markdown cell. |
Ok, the "heading path" or "numbering" solutions seems doable for me (the "change the notebook format" not -> I don't think I've a deep enough understanding what this would mean for the rest of the functionality). numbering
Heading path
add some metadata hash foreach md cell and add that to the ids (current id+metadata hash) in that cell
If adding to metadata isn't a problem (i.e. splitting does not copy metadata) I would try that first, but if you thing that's a problem I would go with simple numbering. |
I'm not sure about splitting, but I would expect copying cells to copy their metadata. |
Even metadata on copy/past is not obvious. Let say a metadata field is supposed to be unique. |
Hi @JanSchulz : We're tidying up our issue log and closing or progressing issues older than 1 year. Could you please tell us if this issue been resolved to your satisfaction? |
This probably should remain open it relates to a lot of the work that I've been doing around auto-header specification and is a useful resource for me to touch back on. My solution to something like this would be to make available manually specified ids that rely on an extension of markdown syntax (specifically I'm thinking that the pandoc approach of using That said, it's not a small undertaking to make something like that available given our current header-id implementation. Regardless, thank you @JamiesHQ for bringing this to my attention it had escaped my notice until now. |
We mitigated it a bit in https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/src/jupyter_contrib_nbextensions/nbextensions/toc2/toc2.js#L7, but the problem of preserving links from outside to headers when they have the same name still exists. |
Sounds good, thanks @mpacer and @JanSchulz ! I've added mpacer as an assignee. cheerio. |
That's what I think manual specification will be able to solve. Otherwise this is always going to be an issue because no matter however clever we are about updating links within a notebook, outside links can't be updated and will fail if there's any change in the header positioning (i.e., even if you were to do this in pandoc you would run into this problem). But if we encourage manual header specification, then permanent links can be guaranteed (since they aren't autogenerated). |
Is there any work in progress to implement this feature ? |
Currently, two headlines with the same text (say "Plots") get the same ID for the appended anchor. This is problematic, if you use repetitive headlines (think "Analysis 1" -> "Plots", "Analysis 2" -> "Plots"...) and @minrk TOC script which links to headers and so links to the second "Plots" go to the first ones, as that's the first with such an ID.
The place which adds the links is this here:
https://github.com/jupyter/notebook/blob/master/jupyter_notebook/static/notebook/js/textcell.js#L281
I replaced that locally with:
and now my header IDs and the anchor ID are unique (and TOC works!) but they are not the same across notebook reloads, so links to a certain headline do not work :-(
Is there any "ID" for a cell which could be used to make the IDs unique?
The text was updated successfully, but these errors were encountered: