syntax-highlighting - 为什么 "linenos"选项无法在 Jekyll 中添加行号?

标签 syntax-highlighting jekyll line-numbers

我正在使用 jekyll 生成我的网站。我想在我的代码块中添加一个行号列。我搜索了谷歌,每个人都告诉我在hightlight标签中添加一个“linenos”选项,但在我的情况下我不起作用:

{% highlight ruby linenos %}
def foo():
puts 'foo'
end
{% endhighlight %}

亮点运行良好,但行号....

你能帮我解决这个问题吗?如果您想查看源 css/html 文件,请点击 here .

谢谢!

进一步检查:

为本节生成的 html 是:
<div class="highlight"><pre><code class="ruby">
    <span class="k">def</span> <span class="nf">foo</span><span class="p">():</span>
    <span class="nb">puts</span> 
    <span class="s1">&#39;foo&#39;</span>
    <span class="k">end</span>
</code></pre></div>

最佳答案

我克隆了您的存储库,生成了站点,并在浏览器中查看。 一切看起来都很好。 (我喜欢你的布局!)这向我表明你的设置有些时髦。代码突出显示对您有用吗?如果没有,您可能没有正确设置 Pygments。

安装:

sudo apt-get install python-setuptools
sudo easy_install Pygments

要生成 css:
pygmentize -S default -f html > default.css

确保您拥有 pygments: true在你的 _config.yml 中。

确保正确放置此样式表并将其包含在您的 default.html 中。

我看到您的页面中已经包含此样式表,并且您的 _config.yml 看起来不错,但对于其他需要此答案的人来说,它就在那里。

如果您使用 jekyll --no-auto 生成站点您在输出中看到任何错误吗?

让我知道,我很乐意尝试并提供进一步的帮助。 :)

更新 :这是为我为您的高亮测试博客文章生成的 HTML。
<div class="highlight"><pre><code class="c"><span class="lineno">1</span> <span class="cp">#include &lt;stdio.h&gt;</span>
<span class="lineno">2</span> 
<span class="lineno">3</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="lineno">4</span> <span class="p">{</span>
<span class="lineno">5</span>   <span class="n">printf</span><span class="p">(</span><span class="s">&quot;Hello World!</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">);</span>
<span class="lineno">6</span>   <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="lineno">7</span> <span class="p">}</span>
</code></pre>
</div>

关于syntax-highlighting - 为什么 "linenos"选项无法在 Jekyll 中添加行号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14089633/

相关文章:

r - |> 用于 ESS 的语法高亮

javascript - 如何在 Geany 中更改一个关键字的颜色?

xcode - 修复了 Xcode 难以辨认的内联错误突出显示?

ruby - Jekyll:如何将 Ruby 对象传递给模板?

code-analysis - 将 BCI(字节码索引)转换为源代码行号

java - 将 "\t"写入文本文件会创建一行?

html - 自定义 Vim HTML 语法

for-loop - Jekyll _data : How to display the key-value label as a value, 不仅仅是key的值

github - 为GitHub Pages设置Jekyll环境

javascript - codemirror - 空行号?