GNOME Bugzilla – Bug 673660
Code tag in XML doc comments destroys line breaks
Last modified: 2012-07-15 11:47:31 UTC
Assuming I had one of my classes documented with the following XML doc comment: /// <summary>Timer for games that advances time in fixed steps</summary> /// <remarks> /// <para> /// Frame rate independent movement can be implemented in two ways: either via /// time scaling or via time stepping. Time scaling will scale the movements of all /// objects in a game by the amount of time passed since the last frame. Time stepping /// advances time in fixed steps, multiple times if more time has passed than the length /// of a single step. /// </para> /// <para> /// This timer is intended for the stepped approach. The advantages are simpler updating, /// improved stability of physics simulations (most physics engines go haywire if time /// jumps by a large amount) and the guarantee for identical rounding errors for all /// players in a multi-player game. /// </para> /// <example> /// <code> /// steppedTimer.Reset(); /// while(!this->quitRequested) { /// GameTime timeStep; /// while(steppedTimer.TryAdvance(timeStep)) { /// UpdateAll(timeStep); /// } /// /// GameTime frameTime = steppedTimer.GetFrameTimeAndReset() /// DrawAll(frameTime); /// /// RunMessagePump(); /// } /// </code> /// </example> class Stepped Timer { /* ... */ }; This will end up as three lines of code, everything being concatenated together until a blank line is encountered. Microsoft's guide for XML documentation comments (which might or might not apply when using Doxygen) has this precise constellation of tags as an example: http://msdn.microsoft.com/en-us/library/9w4cf933.aspx It would be great if Doxygen could preserve line breaks the same way other XML doc comment processors (eg. Visual Studio, Sandcastle) do. Ideally, it would scan for the least indented line within the code tags and adjust indentation according to that, then putting everything in a <pre /> section for HTML output.
Which language was your class written in? For C# code (.cs extension) doxygen treats <code>...</code> the same as @code ... @endcode, and your example will look fine. For other languages <code> is assumed to be a HTML command and is rendered as such.
It's C++. You can view the complete headers here: https://devel.nuclex.org/framework/browser/game/Nuclex.Game.Native/trunk/Include/Nuclex/Game/Timing Microsoft's XML comment format is supported by their C++ compiler as well, it can be enabled in Project Settings - C/C++ - Output Files - Generate XML Documentation Files. I could use Sandcastle with the resulting XML files, but Doxygen generates much better output :) Maybe you could decide how to process code tags based on whether <code> or @code is used? I suspect anyone using the Microsoft style would expect the behavior documented on MSDN, though I've got no clue how popular those XML comments are for C++ developers.
I will treat a <code> block inside a <summary> or <remarks> section as a XML command (so similar to @code), and a <code> outside such section as a HTML command. I think that will give the expected results in most/all cases.
This bug was previously marked ASSIGNED, which means it should be fixed in doxygen version 1.8.1.1. Please verify if this is indeed the case. Reopen the bug if you think it is not fixed and please include any additional information that you think can be relevant.
Thank you for the update! My <code /> block is now displayed with line breaks and is readable in the docs for the first time :) The indentation is a bit distracting: http://i.imgur.com/Qmg95.png But I believe Sandcastle behaves exactly the same. It would be nice of the code block could be scanned for the least indented line and that then used as the starting column, but I don't know if this would be undesirable for the way other people use the @code / <code > tag.
I'll make doxygen strip the leading indentation as well.
Just tested Doxygen 1.8.1.2. The documentation now looks brilliant and the indentation is perfect: http://i.imgur.com/A0o3o.png Thanks for all your effort!