2

How to make a short link to specific code line from markdown in github issue text?

I have read the question How to link to specific line number on github, but it's about putting full link in markdown.

My question is about some markdown shortcut, like @user or #11 issue

Doc Autolinked references and URLs doesn't help.

Community
  • 1
  • 1
Y.N
  • 4,989
  • 7
  • 34
  • 61
  • This would be a great feature to have. Unfortunate it doesn't exist now. – Akilan Feb 03 '20 at 07:03
  • Besides the link being short, there is the issue of how to link to a specific *line* in a Markdown file within a GitHub repository, which is currently impossible, though there does exist an approximation by specifying in the URL what text to highlight: https://stackoverflow.com/a/63197341/1959808 – 0 _ May 29 '21 at 19:19

1 Answers1

2

There is no way to do this.

When you use @user to point a user page or #17 for a specific issue in the current project, you create a link to a unique object. When you want to provide a link to a file code, maybe you want to point to the latest revision in master (ex: https://github.com/google/apitools/blob/master/apitools/init.py) or on another branch (ex: https://github.com/google/apitools/blob/csl-patch/apitools/init.py). As far as I know, there is no shortcut available in GitHub flavord markdown for linking to a specific file in the project.

As you already noticed, using this long form (the full URL), you will be able to add a #LXXX to the end of the URL to point to specific line in the file (ex: https://github.com/google/apitools/blob/master/apitools/init.py#L5 or https://github.com/google/apitools/blob/csl-patch/apitools/init.py#L8. But if you really want to avoid long links, you could use GitHub URL Shortener to convert any link (with or without line number) to an equivalent short form: https://git.io/vMD6U

Antwane
  • 20,760
  • 7
  • 51
  • 84