简体   繁体   中英

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

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

github flavoured markdown - eg

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

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

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 div s 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, eg:

...

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

Use this HTML comment tag before the block:

     
<!-- language: php -->

then your block of code and the rest of que answer/question:

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

Important rules:

  • Don't indent the HTML comment.
  • Enter a new empty line after the comment.
  • If don't work insert a new empty line before the comment and the indented code too.

You can check the Stack Overflow's Markdown help and a more elaborated meta's answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM