使用 Jekyll 和 pygments 突出显示不起作用
我有以下代码:
{% highlight java %}
NullPointerException at org.springframework.core.GenericTypeResolver.getTypeVariableMap
{% endhighlight %}
当我使用 jekyll --pygments
生成网站时,html 结果是:
<div>
<pre><code class="java">NullPointerException at org.springframework.core.GenericTypeResolver.getTypeVariableMap</code>
</pre>
</div>
在此 html 输出中,没有预期的 <跨度class="n">
或 标签,并且代码不突出显示。
我做错了什么吗?
I want to use pygments with jekyll
I have the following code:
{% highlight java %}
NullPointerException at org.springframework.core.GenericTypeResolver.getTypeVariableMap
{% endhighlight %}
When I generate my site with jekyll --pygments
, the html result is:
<div>
<pre><code class="java">NullPointerException at org.springframework.core.GenericTypeResolver.getTypeVariableMap</code>
</pre>
</div>
In this html output there aren't the expected <span class="n">
or <span class="s2">
tags, and the code is not highlighted.
Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要生成 css 才能突出显示。
You need to have the css generated to highlight.
另一种单独安装 pygments 并生成 CSS 的方法是,可以直接从 Jekyllrb 文档中提取 CSS 这里
从我上面提到的文档中提取的直接链接在这里:https://github.com/mojombo/tpw/blob/master/css/ syntax.css
(这是作者在 GitHub 上的官方版本)
该文件名为syntax.css,将其放入您的 css 文件夹中,并在任何/所有文件的标题中创建指向样式表的相对链接以启用语法突出显示。
这可以这样做,例如,我将其放置在
head.html
或css.html
中,其中我拥有所有相关链接,它位于_include< /code> 文件夹,以便它包含在使用它的所有布局中:
您可能还需要将其添加到你的
_config.yml
:highlighter: pygments
经测试可在 Jekyll 和 GitHub Pages 上工作(这是特殊的,因为它只允许非常有限的插件集)
一个相关的 SO 问题也帮助我找到了正确的解决方案是<一href="https://stackoverflow.com/questions/9652490/do-i-need-to-generate-a-css-file-from-pygments-for-my-jekyll-blog-to-enable-col">在这里。我还很困惑为什么即使在
_config.yml
中添加了该行之后,我的代码仍然没有在我要移植的模板中突出显示。它在执行jekyll new test-site
时仅在自动生成的 Jekyll 站点上工作的原因是,生成的模板已经包含用于语法突出显示的 SASS (.scss
) (在_sass
目录中)这有助于将其全部生成到一个main.css
中。An alternative to installing pygments separately and generating the CSS, one can directly pull the CSS from the Jekyllrb documentation here
The direct link extracted from the documentation I mentioned above is here: https://github.com/mojombo/tpw/blob/master/css/syntax.css
(It's the authors official version on GitHub)
The file is called syntax.css, drop it into your css folder, and create a relative link to the stylesheet in the header of any/all files to enable syntax highlighting.
This can be done as such for example, I placed it in
head.html
orcss.html
where I have all the relative links, it's in the_include
folder so it gets included in all layouts that uses it:<link rel="stylesheet" href="/css/syntax.css">
You might also need to add this to your
_config.yml
:highlighter: pygments
Tested to work on Jekyll and also on GitHub Pages (which is special as it only allows a very limited set of plugins)
A related SO question that also assisted me in arriving to the right solution is here. I was also puzzled by why my code still wasn't highlighted in a template I'm porting over even after adding the line in
_config.yml
. The reason it just works on the auto-generated Jekyll site when doingjekyll new test-site
is because the generated template already includes the SASS (.scss
) for syntax-highlighting (in the_sass
directory) which helps generate it all into onemain.css
.