highlight.js 添加行号
使用现成的轮子为 highlight.js 添加行号,略作调整。本文地址:blog.lucien.ink/archives/491
highlight.js 添加行号
highlight.js 添加行号
现成的轮子
GitHub 上有一个为 highlight.js 添加行号的项目 github.com/wcoder/highlightjs-line-numbers.js。
可以直接将 src/highlightjs-line-numbers.js 下载下来魔改一下。
CSS
为了适配 PasteMe,对作者的 CSS 略作修改。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* for block of numbers */
.hljs-ln-numbers {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
text-align: center;
color: #ccc;
vertical-align: top;
padding-right: 5px;
/* your custom style here */
}
/* for block of code */
.hljs-ln-code {
padding-left: 1em;
}
最终效果
This post is licensed under CC BY 4.0 by the author.