Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write code block using phpDocumentor, tutorials/extended documentation?

How to write code blocks using phpDocumentor while writing tutorials/extended documentation?

I have tried <programlisting>, it can generate the <code> tag , but it does not parse its contents.

<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>
like image 590
Antagonist Avatar asked Apr 23 '13 08:04

Antagonist


People also ask

How to write a DocBlock?

A DocBlock begins with the three character line /** and each line of the body begins with a space-asterisk * and the characters */ make the last line of the DocBlock. A DocBlock is placed immediately above the element being documented. A Page-level DocBlock is the first DocBlock and contains the @package tag.

Why must you use phpDoc syntax to document code?

PhpDoc, short for PhpDocumentor, is a powerful tool that allows you to easily document your code via specially formatted comments. The documentation will be available not only in the source code, but also in professional documentation extracted using either the web or command-line interface.

What is phpDoc comment?

phpDoc blocks are descriptive comments that are part of the application code. They are used to describe the PHP element in the exact location in the code where the element appears. The block consists of a short description, long description, and phpDoc tags.


2 Answers

This is actually very easy once you know how. You just need to set the role attribute on the programlisting element.

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

I couldn't find this documented anywhere, other than a brief mention in the release notes, but from looking at the code, there seem to be four roles that are supported:

  1. php - adds PHP syntax highlighting to the content and includes a line number on every line.
  2. tutorial - adds HTML syntax hightlighting to the content and includes a line number on every line.
  3. xml - adds pre tags around the content, but otherwise no syntax hightlighting and no line numbers.
  4. html - treats the content as raw HTML, so you can use whatever markup you like.

Any time you want to use angle brackets, though, you will need to escape those characters or wrap the content in a CDATA section. This even applies when you want to use raw HTML. If not, the parser will try and interpret the content as XML.

For example, a raw HTML sample would look something like this:

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

Also note that all of this applies to the initial version of phpDocumentor. The new version (phpDocumentor 2) doesn't appear to support tutorials/extended documentation as far as I can tell.

like image 163
James Holderness Avatar answered Oct 25 '22 04:10

James Holderness


I checked it and I think you can use javascriptMVC documentation tool. I thik Documentation Tool.
and a demo of it is here. and I suggest you to try this.(-:

here is an output of documentJs of javascriptMVC which is /i think the thing you want. or at least I hope.(-: enter image description here



and about phpDocumentor As I said I need some explains to get what you mean but for now please check these. link1. link2 . (if the following is the thing you want).

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

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

Or:

 /**
  * 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;
     }
 }

Another example is to document the variable in a foreach explicitly; many IDEs use this information to help you with auto-completion:

 /** @type \Sqlite3 $sqlite */
 foreach($connections as $sqlite) {
     // there should be no docblock here
     $sqlite->open('/my/database/path');
     <...>
 }
like image 25
ncm Avatar answered Oct 25 '22 04:10

ncm