2013-04-23 86 views
15

如何在编写教程/扩展文档时使用phpDocumentor编写代码块?如何使用phpDocumentor编写代码块,教程/扩展文档?

我试过<programlisting>,它可以生成<code>标记,但它不会解析它的内容。

<refentry id="{@id}"> 

<refnamediv> 
    <refname>Guide for MyApp</refname> 
    <refpurpose>To demonstrate ...</refpurpose> 
</refnamediv> 

<refsynopsisdiv> 
    <author> 
    My Name 
    <authorblurb> 
    {@link [email protected] My Name} 
    </authorblurb> 
    </author> 
</refsynopsisdiv> 

{@toc} 
<refsect1 id="{@id intro}"> 
    <title>User Guide for MyApp</title> 

    <para> 
    Some Description 
    </para> 

     <programlisting> 

      $some = 'code'; 

     </programlisting> 

</refsect1> 
</refentry> 
+0

你可以编辑你的问题一个你尝试过的例子吗?你是指在函数/方法之前的注释块内吗? – halfer 2013-04-23 08:30:00

+0

没有人,它不是关于函数之前的注释块,它是关于编写教程/扩展文档。这是不同的。 – Antagonist 2013-05-28 08:02:29

回答

4

这其实很容易,一旦你知道如何。您只需在programlisting元素上设置role属性。

<programlisting role="php"> 
    $some = 'code'; 
</programlisting> 

我找不到这个记录任何地方,除了在release notes简单提一下,但看代码,似乎有被支持的四个角色:

  1. PHP - 为内容添加PHP语法突出显示,并在每行上包含行号。
  2. 教程 - 将HTML语法高亮添加到内容,并在每行上包含行号。
  3. xml - 在内容周围添加pre标签,但否则没有语法高亮和没有行号。
  4. html - 将内容视为原始HTML,因此您可以使用任何您喜欢的标记。

但是,如果您希望使用尖括号,则需要转义这些字符或将内容包装到CDATA部分。这甚至适用于您想要使用原始HTML的情况。否则,解析器将尝试将内容解释为XML。

例如,原始的HTML样本会是这个样子:

<programlisting role="html"> 
    <![CDATA[ 
    <b>This sentence will be bold.</b> 
    ]]> 
</programlisting> 

另外请注意,所有的这适用于的phpDocumentor的初始版本。据我所知,新版本(phpDocumentor 2)似乎不支持教程/扩展文档。

+0

Tnx,这正是我一直在问的。 – Antagonist 2013-05-29 11:16:01

4

我检查了它,我想你可以使用javascriptMVC文档工具。我thik Documentation Tool
及其演示is here。我建议你试试这个( - :

这里是javascriptMVC这是documentJs的输出/我想你想要的东西,或者至少我希望( - :。 enter image description here



和有关的phpDocumentor正如我所说的,我需要一些解释,让你的意思,但现在请这些。link1link2。(如果下面是你想要的东西)。

/** @type int This is a counter. */ 
$int = 0; 

// there should be no docblock here 
$int++; 

或者:

/** 
    * This class acts as an example on where to position a DocBlock. 
    */ 
class Foo 
{ 
    /** @type string|null Should contain a description if available */ 
    protected $description = null; 

    /** 
     * This method sets a description. 
     * 
     * @param string $description A text with a maximum of 80 characters. 
     * 
     * @return void 
     */ 
    public function setDescription($description) 
    { 
     // there should be no docblock here 
     $this->description = $description; 
    } 
} 

另一个例子是记录在foreach明确的变量;许多IDE使用这些信息来帮助您自动完成:

/** @type \Sqlite3 $sqlite */ 
foreach($connections as $sqlite) { 
    // there should be no docblock here 
    $sqlite->open('/my/database/path'); 
    <...> 
} 
+0

我不需要JavaScript文档,标题说phpDocumentator。 – Antagonist 2013-05-07 07:28:39

+0

@Antagonist好的,给我点时间吧。 – ncm 2013-05-08 07:54:00

+0

@Antagonist你能解释一下比'解析它的内容'更重要吗? – ncm 2013-05-09 12:38:20

-2

可以用户Zend Studio的工具,它可以生成选定的项目文档自动