🏠 back to Observable

Bug report: local anchor link


#1

My cell contains:

md`should generally be [clipped](#map) to that triangle`

The link sends me to a worker-blob url (https://static.observableusercontent.com/worker/worker.41429f6ab0e6ad622d896965f31e125c7a51392b3ce5e5da530ef441930ce3ce.html#map)


#2

Yes, I’m afraid that because the cell output is safely contained in a sandboxed frame, it’s a little more difficult than normal to link directly to other parts of the page.

But it can be done!

You need to target your link to the parent frame, and use the full URL of the published notebook, like so:

html`<a target="_parent" href="https://beta.observablehq.com/@jashkenas/my-cool-notebook#map">clipped</a>`

#3

I know, but I’d still file it as a bug :slight_smile:


#4

This has been fixed! Thanks for the bug report.


#5

I can’t seem to get local anchor links to work in my notebooks. Am I doing something wrong here?

[Not sure if I should have made a new thread or not, but this seemed like a relevant place to ask…]


#6

Hey Bryan - anchor links refer to named cells, so instead of a cell like

md`<a name="anchorplace"></a><sup>1</sup> **The link should lead here!**`

You’ll want to do:

anchorplace = md`<sup>1</sup> **The link should lead here!**`

The distinction is that the output of your cell is actually a separate page - it’s an iframe under the code. Naming the cell like ↑ creates an id on the top frame instead, so it’s linkable from other cells.


#7

Thanks tom! Looks like that does the trick. It’s so basic that I must have missed this in the tutorials…


#8

No problem! It’s a pretty subtle difference, and it’s totally reasonable to expect the former to work given typical web pages - this is one of those parts where Observable does work a little differently.


#9

Any plans to fix this or provide a workaround? The workaround postet doesn’t seem to work anymore, and having to split every paragraph into it’s own cell seems a bit cumbersome and breaks text flow.

I’m writing an paper and have references in the text and an auto generated bibliography at the bottom. The ability to jump from a reference to the point where it’s used would be pretty sweet.