如何向 Google Prettify 中的所有行添加行号?
我正在使用 prettify:
<pre class="prettyprint linenums">
some code
</pre>
它可以工作,但行号每 5 行显示一次,而不是每行显示一次。 使用这些文件
<link href="../src/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../src/prettify.js"></script>
我基本上在本页末尾 http://google-code- prettify.googlecode.com/svn/trunk/styles/index.html 你可以看到我想要的,但我查看了该代码,但无法弄清楚。
I am using prettify:
<pre class="prettyprint linenums">
some code
</pre>
It works but the line number show every 5 lines and not for every line. I am using these files
<link href="../src/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../src/prettify.js"></script>
Basically at the end of this page http://google-code-prettify.googlecode.com/svn/trunk/styles/index.html you can see that I want, but I looked at that code and I can't figure it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根本原因是 prettify.css 中的
list-style-type: none
:您可以删除该规则或使用以下命令覆盖它:
The root cause is
list-style-type: none
in prettify.css:You can either remove that rule or override it with:
解决方案
您无需修改 CSS,只需添加一行 CSS 即可实现所需的行为:
示例
完整的示例可能包含以下代码。 通过 jsfiddle 查看结果或参见下文
Solution
Instead of modifying the CSS you can simply add in a line of CSS to achieve the desired behavior:
Example
A full example might have the code below. View results via jsfiddle or see below
我喜欢交替的背景颜色,所以这样做:
I like having the alternating background colors, so did it this way: