How to display line numbers using GitHub Flavored Markdown "code"?

Solution 1:

As you may noticed in Markdown Cheatsheet, GitHub does not show line numbers in code blocks.

Solution 2:

As a hack, you could save a pic of your code at https://carbon.now.sh and post it; they support line numbers as an option.

Solution 3:

You can get something similar that you need using awk '{printf("% 4d %s\n", NR, $0)}' StartDsl.scala where StartDsl.scala is your source code file. Paste the result between

```scala
<your code here>
```

Solution 4:

Although it is not available in GitHub as the question asks, I have discovered today if you add an = sign after the opening line, on some Markdown editors, it gives the desired result.

eg:

```javascript=
var s = "JavaScript syntax highlighting";
alert(s);
```

This works on Markdown editors such as HackMD

See your example on HackMD