I usually use fenced code blocks in order to get code syntax-highlighted, as in

some C++ source

This used to work for quite some time. However, since a couple of days or so, it looks like it doesn't work anymore.

Examples: here and here.

The weird thing is: while editing, the syntax highlighting does work in the preview... sometimes!

Did I do something wrong? Is this feature deprecated? Is it just a glitch in the Matrix?

  • 2020-06-17: Arduino Stack Exchange was migrated to CommonMark. use ```cpp – Juraj Mod Jun 23 '20 at 7:00

I removed the c++ in the first question, and now the syntax highlighting is working.

If it worked before (with the c++), my best guess is Stack Exchange made some changes in the back end.

There is another way to force syntax highlighting for all code blocks in a particular Q or A.

<!-- language-all: lang-cpp -->

There is more information here: Markdown help, and according to this page, the c++ should work.

Clearly there is something wrong or something changed. I'll see what I can find out...

  • Thanks! I knew about this option, but I find it somewhat clumsy. I prefer fenced code blocks and have been using them since I noticed stackexchange started supporting them. – Edgar Bonet Jun 22 '20 at 20:25
  • You might also need to add a space ``` cpp - it's another commonmark thing – marcellothearcane Jul 27 '20 at 10:12

As mentioned by VE7JRO, the language can be specified using a specially-formatted HTML comment.

For those who prefer the more standard “fenced code blocks”, my tests show they still work when the fence is labeled cpp or lang-cpp, but not with the labels c++ or lang-c++:

for (int i = 0; i < 42; i++)  // be insistent

is rendered:

for (int i = 0; i < 42; i++)  // be insistent

Edit: This may be the cause of the issue: We're switching to CommonMark.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .