Jekyll Pygments Processing
Asked Answered
R

2

9

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

https://i.sstatic.net/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.

Retro answered 21/12, 2012 at 21:1 Comment(0)
C
17

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

Carrico answered 13/12, 2013 at 20:6 Comment(2)
Definitely the right answer, saved me a lot of time.Uncloak
strangely this doesn't work for me on Ubuntu 14.04 with defautl jekyll installation. (via <?php tag still works)Polacca
R
5

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;
}
```
Retro answered 22/12, 2012 at 15:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.