jekyll: Pygments and the startinline option for PHP code blocks

In https://github.com/mojombo/jekyll/issues/31 an option startinline was added to the Liquid tag so we can highlight PHP snippets without the <?php tag:

<% highlight php startinline %>

Unfortunately, the triple backticks syntax has no way to inform this option.

As investigated by the discussion in this issue https://github.com/imathis/octopress/pull/1141, always turning on the startinline option has no drawbacks, and it’s only used by the PHP lexer.

Maybe Jekyll could use it by default for redcarpet? It’s a one line change in lib/jekyll/converters/markdown/redcarpet_parser.rb, resulting in the following:

Pygments.highlight(code, :lexer => lang, :options => { :encoding => 'utf-8', :startinline => true }),

Or maybe provide a global config such as:

pygments:
  options: ['startinline']

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

This seems to be broken again, at least in Jekyll 3.1.6 and 3.2

I dumped these samples into a fresh jekyll project’s index.html:

Works:

  {% highlight php %}
    <?php
      $a = new MyClass;
      $c = new \my\name\MyClass;
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, "example.com");
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    ?>
  {% endhighlight %}

Doesn’t work:

  {% highlight php startinline %}
    $a = new MyClass;
    $c = new \my\name\MyClass;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "example.com");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  {% endhighlight %}

Hmm… only seems to work if the markdown is not inside of html tags.

/sample.md

---
layout: page
---
# an h1 tag
<div>
```php?start_inline=true
$c = new \my\name\MyClass;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com");
```
</div>
{% include code_sample.md %}
```php?start_inline=true
$c = new \my\name\MyClass;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "example.com");
```
## an h2 tag

Markdown gets processed outside the <div>, but not inside. I attempted to {% include code_sample.md %} inside of the div, but that didn’t change anything.

We don’t support Pygments anymore. We use Rouge.