doxygenpython-sphinxdocumentation-generationpygments

Doxygen->Sphinx->Pygments code-blocks lexer choice?


Esteemed colleagues!

We've a large C++ project, with documentation created with Doxygen->Sphinx->Pygments. 99% of it works great, since we're documenting C++ code in *.cc files.

However, there are some *.cc files that attempt to create code-blocks for OTHER LANGUAGES. I'm having trouble passing the lexer choice down to Pygments so it can highlight correctly.

Here's my approach within a file, lets call "stackoverflow.cc". These all "work" as I expect:

``` shell
%> This is correctly highlighted as a shell script.
%> Perhaps because Doxygen understands it naitvely?
```

``` c++
class StackOverflow : public Works {
  // This is correctly highlighted as C++.  Natively?
}
````

``` verbatim
class StackOverflow : public Works {
  // This is *ALSO* correctly highlighted as C++.
  //
  // I presume that BECAUSE the file extension is *.cc
  //   that Sphinx(?) selects the C++ lexer.
  //
  // My other presumption is that the "verbatim" block
  //   causes the contents to be passed unmodified from
  //   Doxygen down to Sphinx where it can process
  //   reStructuredText.  No?
}
```

I expect that this block below will choose a different lexer, and emit different highlighting, but it doesn't. It's still highlighted as C++. The reStructuredText, such as the ".. code-blocks:: basemake" directive are emitted and highlighted just like the other text in this block!

``` verbatim

  .. code-block:: basemake

      FOO := $(filter foo,${SOME_VAR})

      target: dependencies
        recipe $(FOO)

  ..

```

Where am I making a mistake? How can I get that block to be highlighted as if it was a Makefile format instead of C++?

Thanks!


Solution

  • I had the same problem and I found the following seemed to work,

    /*!
    \verbatim embed:rst
    .. code-block:: basemake
    
      FOO := $(filter foo,${SOME_VAR})
    
      target: dependencies
      recipe $(FOO)
    
    \endverbatim
    */
    

    which is then highlighted as reStructuredText as expected. Note it required a comment block with an exclaimation after /*! to */