LoginSignup
3
3

More than 5 years have passed since last update.

gollumのMarkdownでPHPのコードをSyntax highlightingする

Last updated at Posted at 2015-09-08

gollumとは?:gitベースのWiki

コマンド一発でローカルサーバをたててWikiが編集できます。文書は全てMarkdownで記述でき、そのまま保存されるので利用をやめたくなっても移行が簡単だと思います。

公式ページ:gollum/gollum

問題:PHPのコードがSyntax highlightingされない

gollumにおいて、以下の様なPHPコードのmarkdown(GitHubスタイル)による記述はハイライトされません。

```php
class SimpleClass
{
    public $var = 'a default value';

    public function displayVar() {
        echo $this->var;
    }
}
```

解決策:文頭に<?phpをつける

```php // この行は必須です
<?php // この行が追加されました

class SimpleClass
{
    public $var = 'a default value';

    public function displayVar() {
        echo $this->var;
    }
}
```

<?phpをつけるとちゃんとハイライトされます。Qiitaと若干勝手が違うのでハマりました。

原因:Rougeの仕様です

前提知識:gollumのSyntax highlightingはRougeが使われている

There are a variety of languages/markups to use and they depend on which syntax highlighter is currently used in Gollum:

  • Rouge
    • This is the default, unless Python and Pygments is installed in your system. Then, Pygments have more priority.
    • Language list for Rouge.
  • Pygments
    • Requires Python 2.5+ (2.7.x is recommended).
    • /Language list for Pygments.

Home · gollum/gollum Wiki
(強調は引用者による)

Pythonがインストールされておらず、ターミナルでgem list | grep pygmentsしてPygmentsがインストールされていなければRougeがデフォルト。

Rouge is a pure-ruby syntax highlighter
jneen/rouge

原因特定の手段:Rougeの挙動を確認したら問題が再現出来た

Rougeの公式ページでブラウザで挙動を確認したところ<?phpをつけたときのみハイライトされました。つまり仕様です。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3