On a Salesforce-focused site, I think there will be a LOT of code snippets, and syntax highlighting makes them easier to read. How would we go about setting up a system of syntax highlighting like they have on other SE sites?

  • This would be a great idea!
    – Matt Lacey Mod
    Commented Aug 8, 2012 at 23:24
  • 1
    @LaceySnr It's been 3.5 years -- any way we can get traction or visible on this? Seems like it must not be very complicated to do...
    – Benj
    Commented Mar 14, 2016 at 16:42
  • 1
    It's not something I have any control over. It needs to be something handled by StackExchange. I'll see who I can get in touch with :)
    – Matt Lacey Mod
    Commented Mar 14, 2016 at 22:06
  • 2
    @LaceySnr This has been activated.
    – Taryn
    Commented Mar 15, 2016 at 18:38
  • Thanks @LaceySnr @bluefeet!
    – Benj
    Commented Mar 15, 2016 at 19:02
  • Thank you so much! Commented Mar 16, 2016 at 19:28

4 Answers 4


This has been turned on for the site. Users can use specific syntax highlighting on a post as mentioned on MSE. Moderators also have the ability to add specific highlighting on a tag info page.

  • I just tried to test out adding syntax highlighting to this this question (see syntax hints in the markdown source) but it doesn't seem to be working -- can you help me troubleshoot? Did I misunderstand the instructions?
    – Benj
    Commented Mar 15, 2016 at 19:06
  • @Benj change it to <!-- language: lang-html -->, etc the lang- is needed.
    – Taryn
    Commented Mar 15, 2016 at 19:13
  • Got it, thanks. This is fabulous, I really appreciate your getting it set up.
    – Benj
    Commented Mar 15, 2016 at 19:14
  • 1
    Is there a process to propose a language hint for a tag?
    – Adrian Larson Mod
    Commented Mar 15, 2016 at 19:32
  • @AdrianLarson I'd maybe post something on your Meta site, then the community could vote and mods would see it.
    – Taryn
    Commented Mar 15, 2016 at 19:34
  • Does this mean that if I tag a post with apex I will automatically get apex syntax highlighting? Because it doesn't seem to work for me.
    – mkorman
    Commented Apr 29, 2016 at 18:07
  • @mkorman I don't believe apex has specific syntax highlighting - you'd have to check the list of highlighting available.
    – Taryn
    Commented Apr 29, 2016 at 18:10

On stackoverflow there are tags to specify the language you want the syntax highlighting: Syntax highlighting language hints

If this is not turned on for salesforce, it should be. I haven't tried it so I don't know for sure.

Java syntax highlighting works pretty well for Apex and XML highlighting works pretty well for Visualforce. I'm pretty sure the Eclipse Force.com IDE is doing something similar to this, though I haven't seen the source so I can't be sure. In Eclipse for example, Javascript and CSS code between style tags does not get highlighted, so it seems like it's something like XML.

In the future it may be possible to get or write a grammar as mentioned, but that doesn't seem totally necessary to start.

Language tags also work on SE, and the Apex and Visualforce tags could be added and mapped to Java and XML.

  • How do we go about requesting that (a) syntax highlighting be made available for this site, and (b) that apex-* be added an a tag alias for java-* and visualforce-* for xml-*?
    – Benj
    Commented Aug 9, 2012 at 14:09
  • I don't know, couldn't figure this out... maybe someone from SE is watching this and can do it?
    – paul
    Commented Aug 9, 2012 at 16:13

Please compare these 2 answers:



Code snippet is essentially the same and I swear I haven't used anything fancy to format it on SO (especially nothing from link in @paul's answer), just clicked the button in editor.

Can it be because of beta and limited control over layout (which I understand to be CSS files mostly)?

  • It's nothing you do when posting - the SE team has to turn it on for this site, and then it'll work pretty automatically.
    – Benj
    Commented Nov 16, 2012 at 21:55

For apex code at least the first step would be to get our hands on an apex grammer spec. To the best of my knowledge this does not exist.

  • 2
    If SF could release the ANTLR files they are most likely using, then a wealth of stuff could be done by the community without us having to start again from scratch... Commented Aug 9, 2012 at 8:40
  • It can probably be derived from the source code on the Apex editor within SF Commented Aug 12, 2012 at 6:58

You must log in to answer this question.

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