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 が私のサイトを構築した後は、次のようになります。

<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 リポジトリの Liquid と jekyll の両方を使用してみました。また、Liquid テンプレートの処理とは関係ありませんが、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"]

それが整ったら、コードの強調表示を次のように変更しました

```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 日間、これと戦っています。しかし、それがマークダウン プロセッサではないことがわかりました。

何かアイデアがあれば、何でも試してみたいと思います。

4

2 に答える 2

17

タグを避けたい場合は<?php、Pygment オプションを指定できますstartinline

{% highlight php startinline %}

phpinfo();

{% endhighlight %}

このようにして、適切にレンダリングする必要があります(私にとってはうまくいきました)。

于 2013-12-13T20:06:53.040 に答える
5

コードブロックの開始タグを含める必要があるだけでなく、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;
}
```
于 2012-12-22T15:09:38.953 に答える