Skip to content

Render references to source code lines inline

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Need the ability to see referenced source code lines directly in an issue comment.

Right now if the link to source code is pasted, people still need to:

  1. open new tab to read the code
  2. know where to get permalink to reference the code (so that it won't shift over time)

Proposal

  1. Automatically transform source code URLs into permalinks (#537874)
  2. Render standalone permalinks as code blocks

How to test the issue is solved

When user pastes link to the source code on a separate line, GitLab should:

  1. fetch the permalink for the provided source link (#537874)
  2. fetch source code lines for the provided permalink (say 2 above and 5 below by default)
  3. render source code, in the comment, with appropriate highlighter and referenced line (3) highlighted
  4. render permalink in the comment

Example

Line

https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/project_ci_cd_setting.rb#L20

should turn into this permalink while editing the post

https://gitlab.com/gitlab-org/gitlab/-/blob/3f1076db0d34c46f0bf4f824a268941bbc943e23/app/models/project_ci_cd_setting.rb#L20

and then rendered as


  allow_nil: true

->default_value_for :forward_deployment_enabled, true<------- THIS LINE IS HIGHLIGHTED
  default_value_for :separated_caches, true

  chronic_duration_attr :runner_token_expiration_interval_human_readable, :runner_token_expiration_interval

  def forward_deployment_enabled?

https://gitlab.com/gitlab-org/gitlab/-/blob/3f1076db0d34c46f0bf4f824a268941bbc943e23/app/models/project_ci_cd_setting.rb#L20

Similar issues

#19480 proposes adding menu at line anchor to copy permalink.

Links / references

https://stackoverflow.com/questions/23821235/how-to-link-to-specific-line-number-on-github/45578779#45578779

Edited by 🤖 GitLab Bot 🤖