What I want to achieve is to reference a code file from another code file and GitHub would recognize it as it recognizes markdown links in a markdown file.
I have a code base which is a tutorial about how to use a specific framework. People go through the code files by following the explanations in the comments and jump to the next file if the comment references it. For example:
// NEXT STATION: Go to Controllers/AdminController.cs
It would be really practical to let the user go through the GitHub repository on GitHub by clicking these code file references. Not sure if this is possible though.
I've tried but didn't work:
// NEXT STATION: Go to [Controllers/AdminController.cs](AdminController.cs)
// NEXT STATION: Go to https://github.com/username/repo-name/blob/master/src/Controllers/AdminController.cs
So is there a way to make GitHub recognize these references and make them links?
This is not supported through Markdown alone.
You could take advantage of a new GitHub feature being rolled out in Q4 2021/Q1 2022: Precise and search-based navigation
Certain languages supported by GitHub have access to precise code navigation, which uses an algorithm (based on the open source
stack-graphs
library) that resolves definitions and references based on the set of classes, functions, and imported definitions that are visible at any given point in your code.
By adding a dummy function call src.SeeTest()
in main.cs
, with a dummy function SeeTest
in Test.cs
, you could effectively create a link that a user can click to switch from main.cs
to Test.cs
.
However, that feature is implemented for now only with the Python language, as listed in "Navigating code on GitHub". C# should follow shortly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With