18

I have a small JavaScript file in assets that I'd like to link to as a direct download.

The following link simply opens the file in the current tab:

[myFile.js]({{file name='myFile.js'}})

I'd like the file to actually download on clicking the link. Is that at all possible in markdown?

ktouchie
  • 371
  • 1
  • 3
  • 9

4 Answers4

9

It's the same as a link. [File Name](url). It works for me on Github pages' Jekyll implementation of markdown.

Johnson Zhou
  • 443
  • 3
  • 13
6

Try using inline HTML <a href="myFile.js" download>Click to Download</a>

Âishik Pyne
  • 201
  • 3
  • 5
6

On GitHub.com

The GitHub wiki site strips out the download attribute, so conventional approaches as mentioned before aren't going to work properly. However, I found the following will work:

<a id="raw-url" href="https://raw.githubusercontent.com/github-username/project/master/filename">Download FILE</a>

Replace 'github-username' with your git hub user name, obviously. Replace 'project' with project name, 'filename' with the actual file name. This also assumes the file is not in a sub folder. Also, notice, it is actually hosted on raw.githubusercontent.com.

However, due the difficulty, I'm almost wondering if the site was intentionally deterring such behavior.

James John McGuire 'Jahmic'
  • 11,728
  • 11
  • 67
  • 78
0

Incase of using remarkable markdown parser, you can use remarkable-seo package to define download attribute in markdown.

Sample Markdown:

[Download Minion](https://octodex.github.com/images/minion.png "download")

Output:

<a href="https://octodex.github.com/images/minion.png" title="Download" download>Download</a>

Leaving this as an answer over here so might help someone else.

Sami Ahmed Siddiqui
  • 2,328
  • 1
  • 16
  • 29