11

I was adding some code to a question, and noticed that I couldn't get syntax highlighting to work. I added a language hint as is used on Stack Overflow, but it had no effect.

I appreciate that most SE sites won't need syntax highlighting (which is presumably why it's not enabled by default), but obviously it could be very useful for us. Is that something which will be sorted out if/when we graduate to 'proper' SE status, or can we realistically do something about it just now?

6

This is enabled, and on by default in the tag.

You can use language hints to fine-tune the highlighting if the defaults aren't acceptable.

  • Thanks Shog. I wonder if it ought to be extended to all questions though? I suspect there will be several instances where we need to include code of some kind, even when the question isn't directly about programming. – Peter Bloomfield Feb 25 '14 at 9:51
  • 2
    As I said, you can use the language hints for more precise control of this - including enabling highlighting in posts where it wouldn't otherwise occur. A moderator here (once you have them) can set defaults on other tags if need-be. – Shog9 Feb 25 '14 at 14:15
  • 1
    What about Arduino specific support? Arduino is in itself a language, of sorts. – asheeshr Feb 26 '14 at 16:30
  • We use Prettify for highlighting. If it ain't supported by Prettify, it ain't supported here. – Shog9 Feb 26 '14 at 16:36
  • @Shog9 Why isn't the highlighting working here: arduino.stackexchange.com/q/692/275 I edited in the language hint plus added the programming tag. – Philip Allgaier Mar 10 '14 at 8:53
  • Looks fine to me, @Philip – Shog9 Mar 10 '14 at 15:01
  • @Shog9 True, now it does. Although I am not sure whether it's thanks to the programming tag or the language hint. Could it be, that as long as an edit is under review, even I cannot see the syntax highlighting? – Philip Allgaier Mar 10 '14 at 17:08
  • @Shog9 Simply adding the language hint doesn't seem to work as proven here: arduino.stackexchange.com/q/699/275 – Philip Allgaier Mar 10 '14 at 21:39
  • 1
    Needs to be on its own line, not abutting the previous paragraph, @Philip. – Shog9 Mar 10 '14 at 21:41
  • @Shog9 Ah, thanks. Good to know. Perhaps a respective note should be added to the language hints markdown page. – Philip Allgaier Mar 10 '14 at 21:43
  • Very interesting approach, but often code is included but is not the core of the question so the OP might not think to use that tag. Also, how many more tags trigger special operations here? Can we add a LaTex tag to allow us to describe things mathematically? – SDsolar Jun 1 '17 at 7:34
  • Not sure what you're asking in the first part of your comment, @SDsolar. As for LaTeX, yes that can be enabled here if it would be routinely useful; you can post a separate request with examples of posts where such formulas would be beneficial. – Shog9 Jun 2 '17 at 14:49
1

Simply edit the question to add the following text before the code:

<!-- language-all: c++ -->

Note: This should not be indented by the 4 spaces and should have a carriage return before and after.

This also works:

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

Stack Exchange uses Google Prettify for all of the syntax highlighting. Markdown Editor Help

Code blocks can be highlighted using Google Prettify. In many cases, the syntax highlighting language will be inferred from the question's tags.

  • And I suppose people are expected to be born with this knowledge? – SDsolar Jun 1 '17 at 7:35
  • 1
    @SDsolar I agree. That is why I have put this answer here, so people can find it here and add it to their post/edit. – sa_leinad Jun 1 '17 at 9:25
  • 1
    It is documented on the Markdown Editor Help page (arduino.stackexchange.com/editing-help#syntax-highlighting). I have added this to my answer. – sa_leinad Jun 1 '17 at 9:33
  • TNX, @sa_leinad. The fact that I found here it is proof that your method worked. Have a great day. – SDsolar Jun 1 '17 at 15:41

You must log in to answer this question.

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