How do I use syntax highlighting in PHP within a markdown github gist?

derekdreery picture derekdreery · Feb 12, 2014 · Viewed 18.1k times · Source

I want to include code in a markdown gist on github, and cannot work out how to do syntax highlighting.

github flavoured markdown - e.g.

```php
    Class::function($param);
```

would highlight the syntax as php in an issue, for instance, but it seems not in a gist.

Answer

Chris picture Chris · Feb 13, 2014

Fenced code blocks do work in Markdown Gists, and in fact your code is being rendered that way. If you inspect the blocks you'll see that they are contained in divs with class="highlight highlight-PHP".

The problem is that PHP code is only recognized for highlighting by GFM if it includes the <?php delimiter (much like PHP code only runs inside a <?php block). Add this to the top of each PHP code block and you should be good to go, e.g.:

...

```php
<?php
class GO_Example_Model_Thing extends GO_Base_Db_ActiveRecord {
    ...