56

When responding to potential answers I sometimes like to include a code block to clarify what I'm talking about. Is it possible to have clean code-formatting in comments or only in questions and answers?

  • 5
    You can do inline code in comments, but block-formatting is reserved for questions and answers. See: meta.stackexchange.com/questions/197/… – Shog9 Feb 12 '10 at 18:53
  • 1
    also see meta.stackexchange.com/questions/1149/… – Ether Feb 12 '10 at 19:38
  • 9
    Something like this? (`Something like this`?) – Greg Bacon Feb 12 '10 at 19:53
  • So I suppose the answerer in this question is using some other kind of html markup injection? stackoverflow.com/questions/2643150/… – Anderson Mar 23 '11 at 6:00
  • I see many people commenting multiple lines of code in comment section in a well formatter manner. How do they achieve it? Please help!! – Unbreakable Dec 30 '14 at 15:28
  • There are so many answers in STACKOVERFLOW also which has long code section is comment section which is well formatted. Please tell me how do they do it. I am never able to post multiple lines of code while seeking clarifications. :( – Unbreakable Dec 30 '14 at 15:30
  • 1
    @Unbreakable please post a link to such comment and a screenshot maybe, not sure what you mean. – Shadow The Burning Wizard Dec 30 '14 at 15:54
  • I mean to say sometimes I want to put some code in the comment section. But I am not able to format the code properly in the comment section. Is there any way we can format multiple lines of code the way we do in the "ANSWER" or "QUESTION" section. – Unbreakable Dec 30 '14 at 16:00
  • @Unbreakable no, you did not understand. You said "long code section in comment which is well formatted". Such thing does not exist as far as I know, so I asked you to post link. If you did not actually see such thing please don't say otherwise. – Shadow The Burning Wizard Dec 30 '14 at 16:10
  • Okey I will paste one. I did see it. – Unbreakable Dec 30 '14 at 16:11
33

Comments, by design, are intended to convey brevity. If you have a code-block that you need to bring attention to, append onto your original post beneath a title like Update #2, and then reference it from within a comment if you need to.

If you have small inline examples, you can just wrap them in back-ticks ` var foo = bar.

  • 1
    Also make sure that the backticks (`) are directly abutting the code. I had a tab or some spaces and couldn't get it to work for a while. – agrippa Jul 27 '19 at 22:28
8

I haven't seen this as possible. The best you can do is use the back_tick to shade the code. That's why you don't see much in the way of code-blocks in comments. Only small references to specific pieces within a given answer

  • the next text should be different yes it ? starting now >> code – sirnur Apr 24 '13 at 17:38
  • When did code quit working on stack-overflow? – ebyrob Apr 28 '14 at 20:05
4

Yea this is possible. See this answer.

Code Formating in Comments

3

You mean this or something more like multiple lines?

if you refer to inline coding, It's done with enclosing text with `, otherwise you can't

  • Something like this: int a = 1 – juan Feb 12 '10 at 18:55
  • this is bold ' this should be coe formate'. – sirnur Apr 24 '13 at 17:45

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