39

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
    Commented Aug 13, 2012 at 13:17
  • 4
    Look how ugly that paste is! Is there a way to paste code which remains formatted?
    – Tacky Tacky
    Commented Aug 13, 2012 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. Commented Aug 13, 2012 at 14:11
  • Line ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­­ ­ ­ ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­­ ­ ­ ­ ­ ­ break Commented May 26, 2017 at 21:32

2 Answers 2

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.

3
  • 20
    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
    Commented Sep 7, 2016 at 8:54
  • so why are they in the guidelines? apple.stackexchange.com/editing-help#linebreaks
    – Peter
    Commented Nov 1, 2023 at 16:26
  • @Peter because that’s the help text for posts, not comments. My answer links to the help text for comment formatting. Commented Nov 3 at 13:47
3

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

This is an

`example`
4
  • If you hit help beside the comment box, it gives you an example of markdown.
    – David B
    Commented Aug 13, 2012 at 13:22
  • if (args.Length > 0) { bool connected = bool.Parse(args[0]); string connectedString = connected ? "Connected" : "Not Connected"; }
    – Tacky Tacky
    Commented Aug 13, 2012 at 13:22
  • 4
    i put the "`" char in front of my code (see above) and it still strips the newlines.
    – Tacky Tacky
    Commented Aug 13, 2012 at 13:23
  • but the question asks about new lines not how to format a code Commented Jul 29 at 12:11

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