4

Possible Duplicate:
How do I format my code blocks?

I did the following: I wrote my question, paste my code, then click {} from the format toolbar. My code turns to grey-colored, but is not colored as I saw in some other posts (keywords are colored) also I can't insert spaces once I use {}. how can I format my code in my posts ?

7
  • 1
    You will get the proper colors once you add the correct language tag to the question.
    – Bo Persson
    Jun 26, 2012 at 9:16
  • 2
    @BoPersson: there is a delay even if the correct tags are present. Only if you do not make changes and wait a moment does the syntax highlighting kick in. Jun 26, 2012 at 9:22
  • This delay is almost 5 seconds. Jun 26, 2012 at 9:23
  • possible duplicate of How do I format my code blocks? - flagged ( hehe in the same time Yanis ;) ) Jun 26, 2012 at 9:23
  • @Bo Persson: that is it.
    – Jury A
    Jun 26, 2012 at 9:26
  • If you'd probably tag your questions (with e.g. java), the syntax highlighting would work. Jun 26, 2012 at 9:27
  • how do you insert code in comments? I tried to use ctrl + k - but that isn't working
    – Noa Even
    Feb 12, 2019 at 16:36

1 Answer 1

5

Wait a moment. When editing your question or answer, the syntax highlighting is disabled temporarily. If you stop editing, after a timeout the highlighting will kick in and the colours will appear. The delay is around 5 seconds, I believe.

This does depend on the tags present on the question, or you can add hints in the markdown source of your post.

To add hints, simply add a <!-- language: ... --> comment on a line of it's own (not indented) before the code block. If you use language-all instead, the choice is applied to all code blocks in your post. See the site help text on this feature.

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