How to use syntax highlighting in PHP as part of gatchub gist?

I want to include code in the markdown gist on github and cannot decide how to make syntax highlighting.

github flavored labeling - e.g.

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

highlights syntax like php in a problem, for example, but doesn't seem to be in context.

+8
php markdown syntax-highlighting gist
source share
2 answers

Protected blocks of code work in Markdown Gists, and in fact your code is handled that way. If you check the blocks, you will see that they are contained in a div with class="highlight highlight-PHP" .

The problem is that PHP code is only recognized for GFM allocation if it contains a <?php delimiter. Add this to the beginning of each PHP block, and you should be fine, for example:

 ... ```php <?php class GO_Example_Model_Thing extends GO_Base_Db_ActiveRecord { ... 
+25
source share

Use this HTML comment tag before the block:

 <!-- language: php --> 

then your code block and other answers / question:

  Class::function($param); // more code... 

Important rules:

  • Do not back down from the HTML comment.
  • Enter a new blank line after the comment.
  • If you aren’t working, insert a new blank line before the comment and indent.

You can check out Method Help and a more developed meta answer .

-3
source share

All Articles