Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I know I can use "code" in GitHub Flavored Markdown to highlight a code snippet. But I am not able to display line numbers for a snippet. Is there a way to do so?

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

I want a line number to be put at the beginning of each line, like this:

1    var s = "JavaScript syntax highlighting"; 2    alert(s); 
like image 980
derek Avatar asked Mar 21 '16 03:03

derek


People also ask

How do you show line numbers in Markdown?

Now here is the solution for adding line numbers in Markdown. You can enable line number for a code block by adding line-numbers class. Dude, this is MPE and not part of GitHub... "Markdown Preview Enhanced is a SUPER POWERFUL markdown extension for Atom and Visual Studio Code.

How do you format inline code Markdown?

There are two ways to format code in Markdown. You can either use inline code, by putting backticks (`) around parts of a line, or you can use a code block, which some renderers will apply syntax highlighting to.

What GitHub Flavored Markdown is and how it is used?

GitHub Flavored Markdown, often shortened as GFM, is the dialect of Markdown that is currently supported for user content on GitHub.com and GitHub Enterprise. This formal specification, based on the CommonMark Spec, defines the syntax and semantics of this dialect. GFM is a strict superset of CommonMark.


2 Answers

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

like image 95
denysdovhan Avatar answered Sep 23 '22 05:09

denysdovhan


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.

like image 45
Birch Avatar answered Sep 22 '22 05:09

Birch