How to do internal links in Google Colab

Viewed 8531

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.

3 Answers

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

The following lines worked for me

Origination: text Destination:

A typical mistake must be the use of " ". If you look at my above lines carefully, it applies "" for the destination line Link, whereas not for the origination line.

Please do not add " " like "#Link" in the origination, otherwise it will direct you to the "Sorry, the file you have requested does not exist." page.

If you look close to your current colab url

https://colab.research.google.com/drive/BLAHBLAH?authuser=SOMENUMBER#scrollTo=BLOCKADDRESS

Every block has its own #scrollTo address. Try clicking other blocks. So, I use it like

1. [LINK TEXT](#scrollTo=BLOCKADDRESS)

This way you don't have to put id tags

Related