[英]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 上的降价要点中包含代码,但无法弄清楚如何进行语法高亮显示。
github flavoured markdown - eg github 风味的降价 - 例如
```php
Class::function($param);
```
would highlight the syntax as php in an issue, for instance, but it seems not in a gist.例如,会在问题中将语法高亮显示为 php,但它似乎不在要点中。
Fenced code blocks do work in Markdown Gists, and in fact your code is being rendered that way.围栏代码块在 Markdown Gists 中确实有效,实际上您的代码就是这样呈现的。 If you inspect the blocks you'll see that they are contained in
div
s with class="highlight highlight-PHP"
.如果您检查这些块,您会发现它们包含在
div
并且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).问题在于,如果 PHP 代码包含
<?php
分隔符(很像 PHP 代码仅在<?php
块内运行),则 GFM 只能识别它以突出显示。 Add this to the top of each PHP code block and you should be good to go, eg:将此添加到每个 PHP 代码块的顶部,您应该很高兴,例如:
...
```php
<?php
class GO_Example_Model_Thing extends GO_Base_Db_ActiveRecord {
...
Use this HTML comment tag before the block:在块之前使用此 HTML 注释标记:
<!-- language: php -->
then your block of code and the rest of que answer/question:然后是您的代码块和其余的 que 答案/问题:
Class::function($param);
// more code...
Important rules:重要规则:
You can check the Stack Overflow's Markdown help and a more elaborated meta's answer .您可以查看Stack Overflow 的 Markdown 帮助和更详细的元答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.