Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Link to Markdown line on Bitbucket
Is there a way to link to specific code lines for a Markdown file[1] in Bitbucket? I have found a UI toggle for each of GitHub, GitLab, and Forgejo that adds a query string to disable the pretty output,[2] but nothing for Bitbucket.
Interestingly, using various values for ?viewer= causes the whole file preview to disappear, but that might be a red herring.
1 answer
It looks like they do have...something. From https://support.atlassian.com/bitbucket-cloud/docs/hyperlink-to-source-code-in-bitbucket/:
URI Template for src
{+bitbucket}{/owner, repository_name}/src{/commitish}{/filepath}{?fileviewer}{#fileline}
Despite the flakiest syntax for describing a URL that I have ever seen, up to the query string represents a normal URL to a file in some repository. The fileviewer query variable specifies a specific view for the file, I gather, but I gather that you don't care about that, though it may (I didn't investigate) affect the output difference that you mention.
The last piece, then, is the key, where they describe fileline as...
The target file name plus the line number, separated by a dash. Without the fileline segment, the URL simply navigates to the target file.
To confirm that they did mean to say "just repeat the name back-to-back for no clear reason," they supply an example of test_auth.py-29. Slap a pound sign in front of that, and you have your specific-line link.
Searching for a random project on Bitbucket to test, then picking a file arbitrarily, I could use that template to verify that it works with https://bitbucket.org/dismine/valentina/src/master/.travis.yml#.travis.yml-29.
If you want a generic approach that'll work anywhere (in other words, doesn't require whatever magic Bitbucket's back-end does to direct to the line without adding an HTML anchor), you can also use the new HTML text highlighting, replacing the file-and-line offset with the horrifying-looking #:~:text= and the text of the line that interests you. For example, you can link to anything on this page, such as https://software.codidact.com/posts/295206#:~:text=most of the time.

0 comment threads