简体   繁体   English

如何在 Markdown github gist 中使用 PHP 中的语法高亮显示?

[英]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:重要规则:

  • Don't indent the HTML comment.不要缩进 HTML 注释。
  • 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 .您可以查看Stack Overflow 的 Markdown 帮助和更详细的元答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 ZE6B391A8D2C4D45902A23A8B6585703D 解析 GitHub markdown 到 PHP? - How do I parse GitHub markdown to PHP from a URL? 如何在PHP字符串和heredoc语法中获得HTML语法高亮? - How do I get HTML syntax highlighting inside PHP strings & heredoc syntax? 如何使用PHP构建具有动态突出显示功能的网站菜单? - How do I use PHP to build a website menu with dynamic highlighting? 如何在Notepad ++中为输出JS的PHP文件设置语法突出显示? - How do I set syntax highlighting in Notepad++ for a PHP file outputting JS? 如何停止HTMLpurifier在markdown中转义PHP速记语法示例? - How do I stop HTMLpurifier from escaping PHP shorthand syntax examples in markdown? 如何在 Visual Studio Code 中启用 PHP 语法突出显示? - How can I enable PHP Syntax highlighting in Visual Studio Code? 如何使用API​​创建GitHub Gist? - How to create a GitHub Gist with API? Sphinx-如何在PHP API中使用扩展查询语法 - Sphinx - how do I use the Extended query syntax with the PHP API 如何在PHP博客上获取Haskell语法突出显示 - How to get Haskell syntax highlighting on PHP blog 在脚本中突出显示Netbeans SQL语法? (例如PHP) - Netbeans SQL syntax highlighting within a script? (e.g. PHP)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM