How to link to part of the same document in Markdown?
Solution 1:
Github automatically parses anchor tags out of your headers. So you can do the following:
[Custom foo description](#foo)
# Foo
In the above case, the Foo
header has generated an anchor tag with the name foo
Note: just one #
for all heading sizes, no space between #
and anchor name, anchor tag names must be lowercase, and delimited by dashes if multi-word.
[click on this link](#my-multi-word-header)
### My Multi Word Header
Update
Works out of the box with pandoc
too.
Solution 2:
This may be out-of-date thread but to create inner document links in markdown in Github use...
(NOTE: lowercase #title)
# Contents
- [Specification](#specification)
- [Dependencies Title](#dependencies-title)
## Specification
Example text blah. Example text blah. Example text blah. Example text blah.
Example text blah. Example text blah. Example text blah. Example text blah.
Example text blah. Example text blah. Example text blah. Example text blah.
Example text blah. Example text blah.
## Dependencies Title
Example text blah. Example text blah. Example text blah. Example text blah.
Example text blah. Example text blah. Example text blah. Example text blah.
Example text blah. Example text blah. Example text blah. Example text blah.
Example text blah. Example text blah.
A good question was made so I have edited my answer;
An inner link can be made to any title size using - #
, ##
, ###
, ####
I created a quick example below...
https://github.com/aogilvie/markdownLinkTest
Solution 3:
Experimenting, I found a solution using <div…/>
but an obvious solution is to place your own anchor point in the page wherever you like, thus:
<a name="abcde">
before and
</a>
after the line you want to "link" to. Then a markdown link like:
[link text](#abcde)
anywhere in the document takes you there.
The <div…/>
solution inserts a "dummy" division just to add the id
property, and this is potentially disruptive to the page structure, but the <a name="abcde"/>
solution ought to be quite innocuous.
(PS: It might be OK to put the anchor in the line you wish to link to, as follows:
## <a name="head1">Heading One</a>
but this depends on how Markdown treats this. I note, for example, the Stack Overflow answer formatter is happy with this!)
Solution 4:
yes, markdown does do this but you need to specify the name anchor <a name='xyx'>
.
a full example,
this creates the link[tasks](#tasks)
elsewhere in the document, you create the named anchor (whatever it is called).
<a name="tasks">
my tasks
</a>
note that you could also wrap it around the header too.
<a name="tasks">
### Agile tasks (created by developer)
</a>