Search code examples
markdowndatabricksazure-databricks

How to create a link to a markdown header in databricks?


I would like to reference a markdown cell inside a databricks workspace from another markdown cell. The reference cell is the following:

%md
[business questions](#buisiness-questions)

The referenced cell look like this:

%md
# Buisiness Questions

If I click on the link then it will navigate me to the home page because it can not find the link.

I have managed to reference the cell according to documentation using HTML hyperlink tag. However, the workspace and notebook, and cell IDs are hard-coded so anytime it is changed, adaptation is necessary.

%md
<a href="https://adb-[some_id].azuredatabricks.net/?o=[some_id]#notebook/[some_id]/command/[some_id]">business questions</a>

How to link a markdown header without hardcoding any IDs?


Solution

  • As @Saideep Arikontham mentioned there is no way to retrieve the cell's URL programmatically. Fortunately, the cell's URL is not changed if the cell's order or content changes. It will also not change if the workspace is detached from the cluster or restarted.

    Therefore it is safe to use the hyperlink tag for referencing the cell.

    %md
    <a href="https://adb-[some_id].azuredatabricks.net/?o=[some_id]#notebook/[some_id]/command/[some_id]">business questions</a>
    

    NOTE: Be aware that if the cell is deleted then the cell URL is also removed. So cell URL adaptation would be necessary. More information about identifiers.