In Markdown, what is the best way to link to a fragment of a page, i.e. #some_id?

Viewed 107729

I'm trying to figure out how to reference another area of a page with Markdown. I can get it working if I add a

<div id="mylink" /> 

and for the link do:

[My link](#mylink)

But my guess is that there's some other way to do an in-page link in Markdown that doesn't involve the straight up div tag.

Any ideas?

6 Answers

For anyone use Visual Studio Team Foundation Server (TFS) 2015, it really does not like embedded <a> or <div> elements, at least in headers. It also doesn't like emoji in headers either:

###  Configuration 

Lorem ipsum problem fixem.

Gets translated to:

<h3 id="-configuration-"> Configuration </h3>
<p>Lorem ipsum problem fixem.</p>

And so links should either use that id (which breaks this and other preview extensions in Visual Studio), or remove the emoji:

Here's [how to setup](#-configuration-) // Configuration 
Here's [how to setup](#configuration) //Configuration

Where the latter version works both online in TFS and in the markdown preview of Visual Studio.

In Pandoc Markdown you can set anchors on arbitrary spans inside a paragraph using syntax [span]{#anchor}, e.g.:

Paragraph, containing [arbitrary text]{#mylink}.

And then reference it as usual: [My link](#mylink).

If you want to reference a whole paragraph then the most straightforward way is to add an empty span right in the beginning of the paragraph:

[]{#mylink}
Paragraph text.
Related