0
votes

My question is not easy to describe in a short caption, so i try to explain it more detailed:

I want to generate documentation from comments in the source code. My favorite way would be a separately generated markdown file which contains the collected comment blocks.

Here is an example sourcecode of what I want to do:

/*!
 * @brief   Command management
 */
void DoCommands()
{
    // \HTML Variant
    /*!
    This part is a html sequence \n
    Here \b<a table> will appear \n
    <table>
    <tr><th> Command </th> <th> Function </th></tr>
    <tr><td> ? </td><td> Dummy </td></tr>
    */
    switch (Cmd)
    {
        /*!
        <tr><td>v </td><td>Get version </td></tr>
        */
        case 'v': SendVersion(); break;
        /*!
        <tr><td>q </td><td> Quit program </td></tr>
        </table>
        */
        case 'q': Quit(); break;
    }

    // XRefItem Variant
    /*!
    This part is a xrefitem sequence \n
    Here \b<a table> will appear \n
    \cmditem Command, Function
    \cmditem ?, Dummy
    */
    switch (Cmd)
    {
        /*!
        \cmditem v, Get Version
        */
        case 'v': SendVersion(); break;
        /*!
        \cmditem q,  Quit program
        */
        case 'q': Quit(); break;
    }


    // Markdown Variant
    /*!
    This part is a markdown sequence \n
    Here **a table** will appear \n
    Command | Function \n
    ----|-------
    ? | Dummy
    */
    switch (Cmd)
    {
        /*!
        v | Get Version
        */
        case 'v': SendVersion(); break;
        /*!
        q | Quit program
        */
        case 'q': Quit(); break;
    }
}

The function handles different commands and I want to put the description of the command into the case to have source code and documentation at one place.

As you can see, I tried several possibilities to collect this information with Doxygen. The first solution with html tags works not too bad. The resulting html looks like this:

Doxygen result

But its not perfect. As the table is built over several blocks, an extra newline is added after "Dummy" and "Get version" and therefore they are not in line with the "?" and the "v".

My next try was with the \xrefitem. I defined an ALIAS in Doxygen cmditem=\xrefitem cmditems "Commands" "Command overview" and used it for documenting the single items. Doxygen generated additionally to the function an extra "Related pages" entry which looks like this:

XRefItem output

The problem is, I don't know how to get this formatted pretty as a table...

And last I tried to write the table in markdown syntax but this works only for the first entry of the table. The second entry which is in a separate comment block was not added to the table.

Does anyone know a way how to get a pretty formatted documentation with separated comment blocks for the different commands?

I need the documentation of the commands to give it to a customer. He does'nt need all the other stuff about the code and the function. So "the cherry on the cake" whould be an instruction/command which tells doxygen to take the comment block "as it is" and put/append it to a separate file.

In this example I'd like to have the markdown comments in one file which could look like this (off course after a little modification of the lines above):

This part is a markdown sequence  
Here **a table** will appear  
| Command | Function |
|----|-------|
|? | Dummy|
|v | Get Version|
|q | Quit program|
2
Which version of doxygen are you using?albert
I'm using Doxygen version 1.8.20Stephan

2 Answers

0
votes

you are right, every comment block is a separate paragraph and therefore Doxygen inserts <p> ... </p> in the table which causes the extra lines.

The generated html code looks like this:

</p><table class="doxtable">
<tr>
<th>Command  </th><th>Function  </th></tr>
<tr valign="top">
<td>? </td><td><p class="starttd">Dummy </p>
<p class="endtd"></p>
</td></tr>
<tr valign="top">
<td>v </td><td><p class="starttd">Get version </p>
<p class="endtd"></p>
</td></tr>
<tr valign="top">
<td>q </td><td><p class="starttd">Quit program </p>
<p class="endtd"></p>
</td></tr>
</table>

Your workaround helps to get a uniform layout of the table entries:

HTML table with valign

Thank you!

0
votes

To understand the behavior a bit one has to know that different comment blocks are not directly appended to each other but that that each block is seen as a different paragraph and thus that the markdown table entries have empty lines and thus break the table.

Regarding the xrefitem possibility, these are formatted wit <dl>, <dd> and <dt> in the normal paragraph and just as paragraphs on the related page. Hence not really possible to create a table out of it.

Regarding the HTML solution. It is indeed a bit strange that there is an extra newline for ? and v row, this is also due to the extra new lines (though a bit strange to me as the new lines are after closed rows (this has be investigate in the doxygen code why this happens). To get a better output here I would suggest

  • get the </table> out of the switch so also the q has the extra line
  • use the attribute valign="top" in the <tr> tag

So in general we get for the HTML part:

/*!
 * @brief   Command management
 */
void DoCommands()
{
    // \HTML Variant
    /*!
    This part is a html sequence \n
    Here \b<a table> will appear \n
    <table>
    <tr valign="top"><th> Command </th> <th> Function </th></tr>
    <tr valign="top"><td> ? </td><td> Dummy </td></tr>
    */
    switch (Cmd)
    {
        /*!
        <tr valign="top"><td>v </td><td>Get version </td></tr>
        */
        case 'v': SendVersion(); break;
        /*!
        <tr valign="top"><td>q </td><td> Quit program </td></tr>
        */
        case 'q': Quit(); break;
    }
        /*!
        </table>
        */
}

I think this table does look a little bit better as e.g. the ? is not in the middle of the cell anymore, the extra empty line is not easily removed. For people who know css it would be possible to create an HTML_EXTRA_STYLESHEET with the setting if e.g:

p.endtd {
        margin-bottom: -14px;
}

but this would influence all tables there the paragraph tag is used inside a cell (doxygen adds the paragraph tag).