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);
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.
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.
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.
As you may noticed in Markdown Cheatsheet, GitHub does not show line numbers in code blocks.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With