Search code examples
jupyter-notebookmarkdowngoogle-colaboratory

How to do internal links in Google Colab


I would like to make a reference list with the sections of my Colab notebook. The notebook is saved in my Google Drive.

I am trying HTML and Markdown hyperlinks, which work fine if the link is to an HTTP URL, but it is not working for internal Sections in the notebook.

For example, in a text cell I set the outline:

1. [Section 1](#s1)
2. [Section 2](#s2)

and in the destination section:

<a id='s1'></a>
#Section 1

.....

<a id='s2'></a>
#Section 2

The hyperlink in the list of the outline it is showed as a hyperlink but when I click on it or it does not do anything, or it opens a new tab in the browser with an error message:

enter image description here

Colab creates its own Content list using the markdown sections and subsections but internal links from one section to another are not possible.


Solution

  • With Colab you have to insert an <a name="id"></a> tag in the cell you want to link to.

    The link works like normal:

    [Link Text](#cell-id)
    

    And the destination cell with the tag would be:

    <a name="cell-id"></a>
    # Heading
    This is the cell I'm linking to