28

Possible Duplicate:
How about newlines within comments?

When posting a comment in stackoverflow how do I add newlines? I pasted some multi-line code example and stackoverflow stipped the newline characters and the code looks ugly!

4
  • 1
    if (args.Length > 0) { bool connected = bool.Parse(args[0]); string connectedString = connected ? "Connected" : "Not Connected"; }
    – Tacky Tacky
    Aug 13 '12 at 13:17
  • 4
    Look how ugly that paste is! Is there a way to paste code which remains formatted?
    – Tacky Tacky
    Aug 13 '12 at 13:18
  • Code should not be posted in comments. Add it to the question itself, or if commenting on answer have its author add it to the post itself where is can be formatted properly. Aug 13 '12 at 14:11
  • Line ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­­ ­ ­ ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­ ­ ­ break May 26 '17 at 21:32
10

From How do comments work?:

Comments are intentionally short, having maximum length of 600 characters, and allow only limited markup.

As such, they intentionally do not support newlines either.

You can use the help link next to a comment box to see what is supported; from the comment formatting help:

Comments support only bold, italic, code and links; in addition, a few shorthand links are available.

1
  • 12
    This is a very annoying limitation as it means a single line of code gets broken across two lines, so you end up having to post it as two comments instead of one. An alternative solution would be if it forced code blocks on to their own line if they exceed more than about 40% of the column width.
    – NickG
    Sep 7 '16 at 8:54
5

This is a question for Meta/FAQ, but you can use ` to delimit a code-portion in comments.

This is an

`example`
3
  • If you hit help beside the comment box, it gives you an example of markdown.
    – David B
    Aug 13 '12 at 13:22
  • if (args.Length > 0) { bool connected = bool.Parse(args[0]); string connectedString = connected ? "Connected" : "Not Connected"; }
    – Tacky Tacky
    Aug 13 '12 at 13:22
  • 2
    i put the "`" char in front of my code (see above) and it still strips the newlines.
    – Tacky Tacky
    Aug 13 '12 at 13:23

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