Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How link to any local file with markdown syntax?

People also ask

How do you add a link to a readme file?

To link inline, type the text you want to link within brackets, "[x]", followed directly by the link URL parentheses, "(y)". Reference-style linking allows you to give a link a number or "name" and refer to it multiple times.

How do I add a link in Github Markdown?

There are two ways to create links. Or leave it empty and use the link text itself. URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or http://www.example.com and sometimes example.com (but not on Github, for example).

Can I create links with target _blank in Markdown?

So as pointed out in the answers, it is not a feature in markdown. If you wanted to make this a default sitewide to link out, David Morrow has the answer. Or if you just wanted to do it in one instance, then Matchu's answer says that you must actually write that in HTML.


None of the answers worked for me. But inspired in BarryPye's answer I found out it works when using relative paths!

# Contents from the '/media/user/README_1.md' markdown file:

Read more [here](./README_2.md) # It works!
Read more [here](file:///media/user/README_2.md) # Doesn't work
Read more [here](/media/user/README_2.md) # Doesn't work

How are you opening the rendered Markdown?

If you host it over HTTP, i.e. you access it via http:// or https://, most modern browsers will refuse to open local links, e.g. with file://. This is a security feature:

For security purposes, Mozilla applications block links to local files (and directories) from remote files. This includes linking to files on your hard drive, on mapped network drives, and accessible via Uniform Naming Convention (UNC) paths. This prevents a number of unpleasant possibilities, including:

  • Allowing sites to detect your operating system by checking default installation paths
  • Allowing sites to exploit system vulnerabilities (e.g., C:\con\con in Windows 95/98)
  • Allowing sites to detect browser preferences or read sensitive data

There are some workarounds listed on that page, but my recommendation is to avoid doing this if you can.


You link to a local file the same way you link to local images. Here is an example to link to file start_caQtDM_7id.sh in the same directory as the markdown source:

![start_caQtDM_7id.sh](./start_caQtDM_7id.sh) 

After messing around with @BringBackCommodore64 answer I figured it out

[link](file:///d:/absolute.md)    # absolute filesystem path
[link](./relative1.md)            # relative to opened file
[link](/relativeToProject.md)     # relative to opened project

All of them tested in Visual Studio Code and working,

Note: The absolute and relative to opened project path work in editor but don't work in markdown preview mode!