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

Scrolling to arbitrary cell using cell ID as URL hash #1862

Open
nishikantparmariam opened this issue Sep 9, 2022 · 0 comments
Open

Scrolling to arbitrary cell using cell ID as URL hash #1862

nishikantparmariam opened this issue Sep 9, 2022 · 0 comments

Comments

@nishikantparmariam
Copy link

nishikantparmariam commented Sep 9, 2022

Problem

We want to point (scroll) to a specific cell when a notebook is opened in nbviewer (or jupyterlab) using url hash. This is currently possible with markdown cells which have a heading say ## My Heading so in url hash we can use #My-Heading. But some cells do not having a heading naturally and there is no way to scroll to an arbitrary cell.

We know the id of the cell which we want to point to beforehand.

Proposed Solution

Creating a div or span element before each cell with element id being the cell id (or its function). It will help in pointing to arbitrary markdown as well as code cells. I found this code section to start with. We can possibly extract cell id and prepend the required html / modify the renderer.

def markdown2html(self, context, source):
"""Markdown to HTML filter respecting the anchor_link_text setting"""
cell = context.get("cell", {})
attachments = cell.get("attachments", {})
path = context.get("resources", {}).get("metadata", {}).get("path", "")
renderer = IPythonRenderer(
escape=False,
attachments=attachments,
embed_images=self.embed_images,
path=path,
anchor_link_text=self.anchor_link_text,
exclude_anchor_links=self.exclude_anchor_links,
)
return MarkdownWithMath(renderer=renderer).render(source)

Open for workarounds and suggestions.

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

1 participant