jupyter-notebookmarkdown

Jupyter link to section


I tried to create an internal link to a heading in a jupyter notebook, using the following. The various answers on SO, such as here don't seem to be working as expected in my notebook. The code below creates a link, but nothing happens when trying to access the link.

[Link to section](#section)

... Some text ...

## Section

An alternative method suggested here does work as expected.

<a href='#section'>Link to section</a>

... Some Text ....

<a id='section'></a>
## Section

Is there a mistake in the first section of code?


Update

After researching the suggestions by Waylan, I came across this example for ipython. Just adding dashes, without using lowercase seems to work.

[Link to section](#section)

becomes

[Link to section](#Section)

Solution

  • There are a couple different factors which could be at play here.

    Non-Standard Markdown

    The Markdown rules do not specify that the outplay should include an id attribute. However, many implementations create one for you. Some do so out-of-the-box and others only if a specific extension is enabled. You will need to check the documentation for the implementation you are using to see if such a feature is supported and what you need to do to enable it. If such a feature is not available, then the only option is to manually define the ids using raw HTML.

    Slug creation method

    As there is no standard rule, each implementation which adds the feature does so using their own non-standard method for creating the slug (value of the id attribute). For example, some handle capitalization and/or whitespace differently. You will need to check the documentation for the implementation you are using to find the method used. Alternatively, you could run a draft of the document through the Markdown parser and check for an id attribute and simply use the value. This ensures it will match without needing to know the method used. You may need to use your browser's "view source" feature to determine what id, if any, was assigned to the header.