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

Create unique url's / anchors for each code cell #310

Open
darribas opened this issue Mar 10, 2021 · 9 comments · May be fixed by #519
Open

Create unique url's / anchors for each code cell #310

darribas opened this issue Mar 10, 2021 · 9 comments · May be fixed by #519

Comments

@darribas
Copy link

Is your feature request related to a problem? Please describe.

Very often, once I have created a resource on JB, I find myself wanting to link to specific code cells to illustrate a solution for questions from students, for example.

Describe the solution you'd like

I know it is possible to create unique links with the (<id>)= pattern but this'd require to manually hardcode it on to every code cell just in case/for when some of them will be required.

Ideally, in a similar way to how there is a button that appears on the cell to copy the code, there'd be another one that provides a unique and direct URL to that code cell (it could perhaps be related to the cell number/position in the underlying notebook?).

Describe alternatives you've considered

Currently I default to link to the closest section on which that cell belongs to, and mostly works; or create manual links if I know I'll need them.

@choldgraf
Copy link
Member

choldgraf commented Mar 17, 2021

This is a cool idea - I'm not sure where the best place would be to implement this, since we'd be bottlenecked on how Sphinx itself handles cross-refs (I think that you must put a label just before a header title, for example). But would be cool to experiment with and implement.

@choldgraf choldgraf changed the title Providing unique url's to each code cell Create unique url's for each code cell Mar 17, 2021
@choldgraf choldgraf changed the title Create unique url's for each code cell Create unique url's / anchors for each code cell Mar 17, 2021
@chrisjsewell
Copy link
Member

Oh its already in my thinking for myst-nb: I've already implemented a similar thing previously for ipypublish: https://ipypublish.readthedocs.io/en/latest/code_cells.html#plots-with-matplotlib

@choldgraf
Copy link
Member

Nice - shall we move this to myst-nb then?

@chrisjsewell
Copy link
Member

Yep sounds good 👍

@choldgraf choldgraf transferred this issue from jupyter-book/jupyter-book Mar 18, 2021
@welcome
Copy link

welcome bot commented Mar 18, 2021

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

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! 🎉

@krassowski
Copy link

Anchors for cell based on cell IDs have been implemented in JupyterLab (jupyterlab/jupyterlab#13285) and nbconvert (jupyter/nbconvert#1897). There is also a related issue open on Jupyter Book repo jupyter-book/jupyter-book#1812.

@krassowski
Copy link

krassowski commented May 21, 2023

Could the myst_parser expose the _heading_slugs logic from executablebooks/MyST-Parser#718 so that we could add anchors to cells reusing the same reference collection logic?

Edit: I mean having a function similar to existing generate_heading_target, but allowing to set an arbitrary slug (and use it on cell nodes).

@krassowski krassowski linked a pull request May 21, 2023 that will close this issue
@krassowski
Copy link

@chrisjsewell would you agree that the above proposal of exposing _heading_slugs logic is going in the right direction? I can open a PR against MyST-parser to complement the preliminary work in #519 but would appreciate an early feedback.

@krassowski
Copy link

#519 is ready for review; I will need help over there - despite many attempts the slugs do not get embedded as identifiers in the cells. It seems like the target processing code does not get invoked but I cannot narrow it down why.

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

Successfully merging a pull request may close this issue.

4 participants