Ipynb C++ Syntax highlighting?

I have some notebooks in C++ that use the https://github.com/jupyter-xeus/xeus-cling kernel.

I was wondering how to change the syntax highlighting from python to C++? Currently, it formats code as the python syntax.

How a C++ notebook currently looks like https://rohanrajpal.github.io/blog/2020/06/20/xcpp.html

I’m not sure there is a good way to do this, sadly. This is more tractable with Markdown than Notebooks, at the moment. What’s wrong with the current highlighting? Doesn’t look so bad to me

Thanks for the reply, so the main issue in the comments. The current syntax just comments out all the #defines and includes.
Anyhow, I’ll manage, thanks.

@hamelsmu By the way do you know which direction should I head to make this possible? I’ll be happy to make a PR if I figure it out.

If you make use of cling it has automatic code highlighting in jupyter, but it is a full c++ „interpreter“ so you can actually run the code. But maybe you can take only the highlighting pieces from it, if that is what you need:


and jupyter uses codemirror under the hood, which already supports it I think, so probably just a matter of configuration

Thanks. I do get correct highlighting for C++ in jupyter. It’s just that conversion process of fastpages always assumes python.
I’m having a look at the conversion scripts now to see if something can be done

LIkely has to edit the CSS of the site.

my assumtion (although possibly completely wrong) is that at some point the code cell from the notebook just gets turned into a markdown code block.

if that’s the case it should be easy enough to add a #language option we could add at the top of the cell to created a fenced code block so you could add
#language-cpp or #language-sql which would turn into

``` cpp
int main(void){

in the markdown conversion. if you can get it to do that then you don’t need any other changes (although the dracular highlighting fast pages uses by default isn’t that pretty for c++)

Try switching from the dark to the light theme. Instructions are in the README. Perhaps that will accomodate C highlighting since it is supported by Minima

I don’t have any c++ code so it doesn’t bother me. It does work for other languages but for some languages there’s more pink than anything else so it wouldn’t necessarily be your first choice, that’s all.