2
votes

I have a Markdown document with a header in it like:

## my-script.sh

I want to create a named anchor as in this Stack Overflow question. So I hoped this would work:

[my-script.sh](#my-script-sh)

It doesn't though. Various examples of what I have tried are available at Github here here here here here.

How can I make this work (without removing the dot from the header)?

2

2 Answers

1
votes

The syntax is incorrect :

  • Only one pad is referenced instead of two.
  • the .sh takes it as a file

An solution

Try you the following :

[my-script.sh](##`my-script.sh`)

## `my-script.sh`

What we have done is to disambiguate what is obtained as a file, converting it into a name when putting it in quotation marks.

Updated 22012019110907

Before an interesting investigation about why the previously proposed did not work, I have achieved a (temporary) solution that works.

The solution is to obtain the link through the readme symbol:

Adding link

Copy the link and generate it in our link:

[test.sh](https://github.com/<nameuser>/<namerepo>/<branch>/test#testsh)

## `test.sh`

For example :

[test.sh](https://github.com/user/myrepo/tree/test#testsh)

## `test.sh`

Try me

This or in code snippet :

<script src="https://gist.github.com/nicolasalarconrapela/3aee67d541271b8775bc1a50f1032c00.js"></script>
5
votes

As far as Github Flavoured Markdown is concerned, which is shown in the update by Nicolás Alarcón R. above, if you have a header:

## my-script.sh

The syntax for creating an inline link to it is:

[my-script.sh](#my-scriptsh)