Jos*_*ord 9 highlighting pygments jekyll
我一直在和Jekyll和Pygments争吵一段时间.我安装了pygments并生成了css文件,但是当我运行Jekyll来生成网站时,代码突出显示似乎没有正确生成.
这是我用于处理的一些示例代码
{% highlight php lineos %}
/**
* Passing by reference
*
* Outputs
*
* 10 - before add() call
* 10 - after add() call
* 15 - after addref() call
*/
$a = 10;
echo $a;
add($a);
echo $a;
addref($a);
echo $a;
function addref(&$a)
{
$a += 5;
}
function add($a)
{
$a += 5;
}
{% endhighlight %}
Run Code Online (Sandbox Code Playgroud)
这是Jekyll建立我的网站后的样子.
<div class="highlight"><pre><code class="php"><span class="x">/**</span>
<span class="x"> * Passing by reference</span>
<span class="x"> *</span>
<span class="x"> * Outputs</span>
<span class="x"> *</span>
<span class="x"> * 10 - before add() call</span>
<span class="x"> * 10 - after add() call</span>
<span class="x"> * 15 - after addref() call</span>
<span class="x"> */</span>
<span class="x">$a = 10;</span>
<span class="x">echo $a;</span>
<span class="x">add($a);</span>
<span class="x">echo $a;</span>
<span class="x">addref($a);</span>
<span class="x">echo $a;</span>
<span class="x"> </span>
<span class="x">function addref(&$a)</span>
<span class="x">{</span>
<span class="x"> $a += 5;</span>
<span class="x">}</span>
<span class="x"> </span>
<span class="x">function add($a)</span>
<span class="x">{</span>
<span class="x"> $a += 5;</span>
<span class="x">}</span>
</code></pre>
</div>
Run Code Online (Sandbox Code Playgroud)
你可以看到Jekyll似乎在标记每一行class="x",我不太清楚为什么.
我尝试过使用Github repos中的液体和jekyll,我甚至尝试过使用redcarpet,尽管它与液体模板处理无关.我已经尝试了我能想到的所有东西,但似乎无法让它发挥作用.
这是我查看我的网站时的实际情况
http://i.stack.imgur.com/kCvLN.png
我正在运行以下版本.
Ruby:ruby 1.9.3p327(2012-11-10修订版37606)[x86_64-darwin11.4.2]
rdiscount:rdiscount(1.6.8)redcarpet:redcarpet
(2.2.2)pygments:pygments.rb(0.2.13)
Liquid:液体(2.4.1)
杰基尔:杰基尔(0.11.2)
我刚刚使用了redcarpet_markdown.rb插件,并将配置设置设置为使用redcarpet2,我设置了redcarpet的扩展名.
markdown: redcarpet2
redcarpet:
extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "strikethrough", "superscript", "with_toc_data"]
Run Code Online (Sandbox Code Playgroud)
一旦到位,我改变了代码突出显示为这样
```php
/**
* Passing by reference
*
* Outputs
*
* 10 - before add() call
* 10 - after add() call
* 15 - after addref() call
*/
$a = 10;
echo $a;
add($a);
echo $a;
addref($a);
echo $a;
function addref(&$a)
{
$a += 5;
}
function add($a)
{
$a += 5;
}
```
Run Code Online (Sandbox Code Playgroud)
然后我再次尝试生成网站,我得到了相同的结果.我不确定这是否是Jekyll引起的问题或者Pygments,但是我在过去的两天里一直在与此斗争.但我现在知道它不是降价处理器.
如果你有任何想法我会更愿意尝试任何东西.
Sal*_*alà 17
如果要避免使用<?php标记,可以指定Pygment选项startinline
{% highlight php startinline %}
phpinfo();
{% endhighlight %}
Run Code Online (Sandbox Code Playgroud)
这样它应该正确渲染(它对我有用).
看来你不仅需要包含代码块的开始标记,而且使用PHP还需要包含
```php
<?php
/**
* Passing by reference
*
* Outputs
*
* 10 - before add() call
* 10 - after add() call
* 15 - after addref() call
*/
$a = 10;
echo $a;
add($a);
echo $a;
addref($a);
echo $a;
function addref(&$a)
{
$a += 5;
}
function add($a)
{
$a += 5;
}
```
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1450 次 |
| 最近记录: |