如何将PHP代码块放入PHPDoc DocBlock [英] How do I put blocks of PHP code into a PHPDoc DocBlock
问题描述
我在玩PHPDoc,并意识到你可以使用markdown来添加一些格式化到DocBlock。特别是,我注意到你可以使用反向蜱突出内联代码。
I'm playing around with PHPDoc and have realised that you can use markdown to add some formatting to a DocBlock. In particular, I notice that you can use back ticks to highlight inline code.
但是,我似乎不知道如何添加代码块到DocBlock ,因为使用4个空格似乎不起作用。
However, I can't seem to figure out how to add blocks of code to a DocBlock, as using 4 spaces doesn't seem to work.
我尝试使用< code>
< pre>
,虽然这些标签确实出现在生成的文档中,但它们中的代码会被HTML注释掉。
I've tried using <code>
and <pre>
too, and whilst those tags do appear in the generated documentation, the code inside them becomes commented out with HTML comments.
例如,这个DocBlock:
For example, this DocBlock:
/**
* This is a test DocBlock
*
* <pre>
* <?php
* echo('hi');
* ?>
* </pre>
*
* @return object[] An array of objects.
*/
生成此HTML:
<pre>
<!--?php echo('hi'); ?-->
</pre>
我在哪里出错?
推荐答案
phpdocumentor使用了markdown的github变体。
phpdocumentor uses the github variant of markdown.
正确的添加代码的方法是:
The proper way to add code, is then:
/**
* This is a test DocBlock
*
* ```php
* echo('hi');
* ```
*
* @return ...
*/
这篇关于如何将PHP代码块放入PHPDoc DocBlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!