Add line numbers to markdown code blocks

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

  • Close this issue

I am using the GitLab markdown in both projects README.md and within the GitLab Wiki to produce internal training documents.

Quite often I include code blocks, either using the three back-ticks, or indenting by four spaces. I would like the option of showing line numbers within those blocks to make references in the training text simpler.

For example, say I have this bit of YAML code:

---
all:
  children:
    database:
      hosts:
        db01.example.com:
      vars:
        user: DB_user
    web_servers:
      hosts:
        web01.example.com:
      vars:
        user: web_user

Referencing a specific hosts: or vars: line is challenging without being too wordy.

A code block could which provides dynamic line numbers would be helpful. Referencing the specific line in a block like this is much easier:

     1  ---
     2  all:
     3    children:
     4      database:
     5        hosts:
     6          db01.example.com:
     7        vars:
     8          user: DB_user
     9      web_servers:
    10        hosts:
    11          web01.example.com:
    12        vars:
    13          user: web_user
    14

In a more complex example, referencing...

... the user: variable on line 13.

...is much easier than referencing...

... the user: variable two lines down from the web01.example.com line.

Thank you for the consideration.

Edited Aug 25, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading