2

As per How do we get syntax highlighting?, only the tag has the feature enabled.

But I'm seeing that the tag also is highlighting the code, for example this question.

Are there more tags out there that have syntax highlighting? I edited a couple of questions to add the programming tag but maybe sometimes it won't be necessary and it's a cool feature that all answers follow the question highlight.

| |
  • 1
    I think the C++ tag also has it enabled. – Nick Gammon Jun 15 '19 at 5:18
1

The short answer to your question is to use this syntax: <!-- language-all: lang-cpp --> right above the first block of code.

Here is an example of a question with the syntax highlighting "not working".

enter image description here

  1. Paste in the "html style" syntax as specified in the next image.

enter image description here

  1. Add 4 spaces.

enter image description here

  1. Give it a few seconds, then the highlighting should start working.

enter image description here

Using this method, all of the following code "blocks" will be treated as C++.

The long answer to your question is here: How Do I format my Code Blocks.

| |
  • I was wondering specifically about the tags on the main site that provide syntax highlighting. Does using the HTML language syntax on the Question automatically enables it on Answers? Because that's what I think it's the cool feature of it being associated with a tag, any post on that question will have it enabled. – brasofilo Jun 16 '19 at 1:08
  • More to the point, can moderators see the list of tags with an associated syntax highlighting? – brasofilo Jun 16 '19 at 1:13
  • I'm not sure if tags on the main site provide syntax highlighting. Time for me to do some testing. Here is a question with no highlighting: arduino.stackexchange.com/questions/30312/…. Let's see what happens if I add the C++ tag... – VE7JRO Jun 16 '19 at 1:30
  • It worked :) Keep in mind, there is a limit of 5 tags per question, so if there are 4 or less existing tags, adding the C++ tag fixes the syntax highlighting issue for a question with one block of code (I haven't tested it with multiple code blocks yet). If there were already 5 tags set, which one do you "remove" to add the C++ tag to make the syntax highlighting work? You don't remove any of them, just add the HTML type syntax I've shown you in my answer, and it will apply C++ syntax highlighting to every block of code in the question. – VE7JRO Jun 16 '19 at 2:00
  • Adding the C++ tag to a question will not automatically highlight all the code in every answer. As far as what moderator can and can not see, I am not at liberty to say, but I am confident saying I have never seen any tool, or page, or anything else that gives me a list of tags with their associated syntax highlighting. People often mix C++, Python, HTML, Processing, etc, code in their question/answers, so applying syntax highlighting based on one language is not always desirable. – VE7JRO Jun 16 '19 at 2:20

You must log in to answer this question.

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