首页 文章

Jekyll Pygments Processing

提问于
浏览
9

我一直在和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 %}

这是Jekyll Build 我的网站后的样子 .

<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(&amp;$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>

正如你所看到的,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)
液体:液体(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"]

一旦到位,我改变了代码突出显示为这样

```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;
}

然后我再次尝试生成网站,我得到了相同的结果 . 我不确定这是否是Jekyll引起的问题或者Pygments,但是我在过去的两天里一直在为此而斗争 . 但我现在知道它不是降价处理器 . 

如果您有任何想法,我会非常愿意尝试任何事情 .

2 回答

  • 5

    如果要避免 <?php 标记,可以指定Pygment选项 startinline

    {% highlight php startinline %}
    
    phpinfo();
    
    {% endhighlight %}
    

    这样它应该正确渲染(它对我有用) .

  • 17

    看来您不仅需要包含代码块的开始标记,而且还需要包含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;
    }
    

相关问题