Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll Pygments Processing

I have been fighting with Jekyll and Pygments highlighting for a while now. I have pygments installed and have generated the css file, however when I run Jekyll to generate the site, the code highlighting does not appear to generate properly.

Here is some example code I have in place for processing

{% 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 %}

and here is what it looks like after Jekyll builds my site.

<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>

As you can see Jekyll seems to be marking every line as class="x" and I am not quite sure why.

I have tried using both the liquid and jekyll from the Github repos, I have even tried using redcarpet even though it has nothing to do with the liquid template processing. I have tried just about everything I can think of but cannot seem to get this to work.

This is what it actually looks like when I view my website

http://i.stack.imgur.com/kCvLN.png

I am running the following versions.

Ruby: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
rdiscount: rdiscount (1.6.8)
redcarpet: redcarpet (2.2.2) pygments: pygments.rb (0.2.13)
Liquid: liquid (2.4.1)
Jekyll: jekyll (0.11.2)

I have just gone as far as using a redcarpet_markdown.rb plugin and setting the configuration settings to use redcarpet2 and I set the extensions for redcarpet.

markdown: redcarpet2
redcarpet:
  extensions: ["no_intra_emphasis", "fenced_code_blocks", "autolink", "strikethrough", "superscript", "with_toc_data"]

Once that was in place I changed the code highlighting to be like this

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

I then tried generating the site again and I got the same result. I am not sure if this is Jekyll causing the issue or Pygments but I have been fighting with this for the last 2 days now. But I now know it is not the markdown processor.

If you have any ideas I would be more than willing to try anything.

like image 813
Joseph Crawford Avatar asked Dec 21 '12 21:12

Joseph Crawford


2 Answers

If you want to avoid the <?php tags you can specify the Pygment option startinline

{% highlight php startinline %}

phpinfo();

{% endhighlight %}

This way it should render properly (it worked for me).

like image 57
Salvatore Zappalà Avatar answered Sep 29 '22 11:09

Salvatore Zappalà


It appears you not only have to include the opening tag for the code block but with PHP you also have to include the

```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;
}
```
like image 28
Joseph Crawford Avatar answered Sep 29 '22 13:09

Joseph Crawford