1

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!

Lance E.T. Compte
  • 932
  • 1
  • 11
  • 33
  • 1
    I don't know about Doxygen. Try other lexers http://pygments.org/docs/lexers/#lexers-for-makefiles-and-similar Also make sure your reST syntax is correctly indented and spaced. – Steve Piercy Feb 15 '19 at 22:54
  • 1
    A blank line is needed after `.. code-block:: basemake` and the content of the code-block should be indented. See http://www.sphinx-doc.org/en/stable/usage/restructuredtext/directives.html#directive-code-block – mzjn Feb 16 '19 at 07:17
  • @mzjn: My block is indented four spaces, and I've added the blank line (Thanks!) but I still don't get the output. My reST is still emitted as if it's part of the code block. Choosing a different lexer doesn't make a difference. Hmm... – Lance E.T. Compte Feb 19 '19 at 02:09
  • 1
    The *content* of the block (the make rules in this case) must be indented related to `.. code-block:: basemake`. – mzjn Feb 19 '19 at 06:41
  • @mzjn: I'd love to give you an , but I've tried all sorts of indenting and blank lines on simple code and it still just puts the ".. code-block:: basemake" into the document. I've got Sphinx 1.8.1 and Pygments 2.2.0 (and Python 3.6.5). – Lance E.T. Compte Feb 19 '19 at 16:58

1 Answers1

1

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

Ed Smith
  • 12,716
  • 2
  • 43
  • 55