3

This snippet is a valid "Question" but it's an invalid "Answer" on Stack Overflow.

Keep getting this error when I try to submit this code snippet as an answer:

Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.

Tested on multiple browsers (chrome, brave), private, incognito.

The improperly formatted snippet:

function hello(str) {       
    return 'Hello ' + str
}

console.log(hello('world'));

Stack Overflow edit answer

2
  • As you've figured out, based on your comment on the answer here, what you're trying to submit isn't valid Markdown for code, which is what produces the error. Of the There's a couple of issues to unpack here: A) The verification, while technically correct with respect for Markdown, should be reworded to include mentioning that Markdown requires a black line prior to 4 space indented code; (continued)
    – Makyen Mod
    Commented Jul 28, 2022 at 16:24
  • 1
    B) the verification doesn't match what happens in either the JavaScript based preview nor in the backend Markdown➞HTML conversion (i.e. the text in the question is properly rendered in both the preview and backend, so the error is shown even though it's going to properly render). Both of these should be changed so 1) the error doesn't appear when it isn't necessary, and 2) users have a better chance to correct the issue when that verification error does appear.
    – Makyen Mod
    Commented Jul 28, 2022 at 16:24

1 Answer 1

4

An answer that's just code with no explanation of why it answers the question isn't a high quality answer. You should always add some non-code explanation of the answer.

Additionally when I use the snippet editor, babel is either true or false, never null and there are additional blank lines between the HTML comments. So the answer here is not to manually edit the comments that the snippet editor creates.

2
  • 1
    But that isn't the validation error message. Tested it also with a bunch of Lorem ipsum, still "unproperly formatted code".
    – Aldo
    Commented Jul 28, 2022 at 9:28
  • 3
    The issue was not having those additional blank lines between the comments. imgur.com/a/zB6NLCR Still a weird error message, and that there was no issue to use the same styling as a question instead of an answer.
    – Aldo
    Commented Jul 28, 2022 at 9:39

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