【发布时间】:2013-12-30 01:15:58
【问题描述】:
相关How to add line numbers to all lines in Google Prettify?
我正在查看 google 的 http://code.google.com/p/google-code-prettify/ 以在网页中显示我用 Mathematica 编写的代码。
Mathematica 不是支持的语言。所以,甚至认为我可以做到以下几点
<pre class="prettyprint linenums">
Manipulate[
tick;
Module[{a1, a2, a3, v1, v2, v3, h1, a1d, a2d, a3d, z},
]
</pre>
这在显示行号方面有效,但使用的语法突出显示已关闭,并且对于我使用的语言不正确,因为我理解它当然不受支持。
我很乐意仅列出代码,使用 nocode 类,没有突出显示,但我也希望能够获得行号。所以,我尝试了这个:
<pre class="prettyprint linenums">
<span class="nocode"> <!-- also tried <span class="nocode linenums"--->
Manipulate[
tick;
Module[{a1, a2, a3, v1, v2, v3, h1, a1d, a2d, a3d, z},
</span>
</pre>
但行号不会显示在 nocode 类中。
有没有办法修改prettify.js 并使其也显示nocode 的行号?我主要是用它来列出代码,但需要看行号。
这是一个完整的 MWE
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
</head>
<body onload="prettyPrint()">
<pre class="prettyprint linenums">
<span class="nocode linenums">
Manipulate[
tick;
Module[{a1, a2, a3, v1, v2, v3, h1, a1d, a2d, a3d, z},
Which[state == "init" || state2 == "on",
state2 = "off";
If[state == "init", state = "paused"];
state == "running" || state == "step",
If[currentTime > maxTime, currentTime = 0]
];
]
</span>
</pre>
</body>
</html>
更新
感谢 Gaby,它现在正在运行。这是最终结果
【问题讨论】:
标签: javascript prettify google-code-prettify