Internal links

I know how to link to section headings:

[Title]({{< relref "post.md#title" >}})

...

# Title

How do I link paragraphs? To be very specific, I would like to obtain in-text cross-referencing links like

This goes <a id="↑" href="#↓">down</a>

...

This goes <a id="↓" href="#↑">up</a>

Option 1: Use a Render Hook

Every <a> element will get an id attribute based on the link title specified in the markdown. If the markdown link does not have a title, the id will be based on the link text (this could result in duplicate ids if you are not careful).

layouts/_default/_markup/render-link.html

{{ $id := (default .Text .Title) | plainify | anchorize }}
<a id="{{ $id }}" href="{{ .Destination }}">{{ .Text | safeHTML }}</a>
{{- /* chomp */ -}}

markdown

[Jump to Foo](#foo "bar")
[Jump to Bar](#bar "foo")
...
...
[My **First** Link](#my-second-link)
[My **Second** Link](#my-first-link)

rendered

<a id="bar" href="#foo">Jump to Foo</a>
<a id="foo" href="#bar">Jump to Bar</a>
...
...
<a id="my-first-link" href="#my-second-link">My <strong>First</strong> Link</a>
<a id="my-second-link" href="#my-first-link">My <strong>Second</strong> Link</a>

Option 2: Mix HTML with Markdown

config.toml

[markup.goldmark.renderer]
unsafe = true

markdown

<a id="bar" href="#foo">Jump to Foo</a>
...
...
<a id="foo" href="#bar">Jump to Bar</a>

Future?

Org mode supports this, but the interpreter we use doesn’t currently support dedicated targets. See:
https://github.com/niklasfasching/go-org/issues/32

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.