How to display line numbers using GitHub Flavored Markdown “code”?

爷,独闯天下 提交于 2019-11-30 10:46:22

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.

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>
```

So, you will need to help yourself by adding css to your html page. As a code goes into <pre> </pre> block in markdown.

You could apply your logic to this block to put line number against each line.

See https://codepen.io/heiswayi/pen/jyKYyg for reference.

Now here is the solution for adding line numbers in Markdown.

https://shd101wyy.github.io/markdown-preview-enhanced/#/markdown-basics?id=line-numbers

You can enable line number for a code block by adding line-numbers class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!