-4

Possible Duplicate:
Can we enable syntax highlighting for code in comments?
How to use formatting in comments?

How can I use syntax highlighting in comments, if I need to include some code in the comments?

Use case: I would add some code which I suppose would help the user, but people who don't feel the same start to downvote. So it's safer to post it in comments. But with syntax highlighting for code.

  • Why so many downvotes for the question? – saji89 Nov 18 '13 at 4:49
10

The answer to this is pretty simple. There is no syntax highlighting in the comments. At most you can wrap your code in the usual back-ticks to give it somewhat of a different appearance, but that's about it.

You should not be posting substantial amounts of code in the comments anyway. They are not meant for that. Nor are they meant for extensive discussion or for content which should be guaranteed to stay around for a long time.

If you can, you might be better off making it an answer. If you can't, well, then you're stuck with the current limitations of comments and I can't see that changing any time soon.

  • Thanks for the answer. But I feel that its a feature that needs to be added. – saji89 Oct 18 '12 at 11:35
  • 4
    @saji89 It really doesn't. Code so substantial that it requires syntax highlighting does not belong in the comments. Formatting is off anyway with the absence of any decent indentation. Comments are not meant for such content, nor should they be made to be so IMHO. – Bart Oct 18 '12 at 11:36
  • 2
    I can see the point. Comments should be small and helpful. And more importantly not boringly long. Right? – saji89 Oct 18 '12 at 11:41

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