9

I am using fenced code blocks in Doxygen using the markdown syntax. This makes it easy to add a simple code example, like this:

~~~~~{.cpp}
void doSomething()
   {
   }
~~~~~

When I try to add comments into the fenced code block using two forward slashes, Doxygen seems to remove the slashes. So when I write this:

~~~~~{.cpp}
void doSomething()
   {
   // This function should do something
   }
~~~~~

I get this output:

void doSomething()
   {
This function should do something
   }

How can I tell Doxygen to keep the comments in the fenced code block?

EDIT:

The complete file looks like this (we use the standard Doxygen extension of .dox for documentation-only files):

/*!
\page PATTERN_SAMPLE Sample

~~~~~{.cpp}
void doSomething()
   {
   // This function should do something
   }
~~~~~
*/

The result looks like this: Result

2
  • Can you show how the above markup is embedded in a comment block or .md file? Commented Jul 2, 2013 at 15:09
  • I've added the complete file contents in the question. Commented Jul 3, 2013 at 14:25

2 Answers 2

22

Try with \code

  \code{.cpp}
  class Cpp {};
  \endcode
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed this works. I knew that the \code existed, but I didn't know you could add {.cpp} after it. However, {.cpp} doesn't seem to make a difference. I tested it with a small for-loop, and it only seems to color the "for" keyword. All other words (vector, int, push_back, main) are still shown in black. Luckily, the comments work correctly with it (and they are colored as well).
6

I encountered the same issue. No need to change code format. You can specify STRIP_CODE_COMMENTS as NO: this setting outputs the source code with the comment.

# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
# special comment blocks from generated source code fragments. Normal, C++ and
# Fortran comments will always remain visible.
# The default value is: YES.

STRIP_CODE_COMMENTS    = NO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.