39

One of the things I've noticed quite often is someone will present their code like this:

if( $a > 5) {
    echo $foo;
    // why isn't it showing today?
}
?>

People then comment and sometimes downvote/closevote the question because...

  • "what is $a?"
  • "where do you define $foo?"
  • "Unclear what you're asking"
  • "$foo is not defined, echoing it outputs nothing"
  • and others.

Whenever I notice these, I hit the "Edit" button and if you do that to this post you'll see exactly what happened. The markdown input for the above is (Screenshot here):

One of the things I've noticed quite often is someone will present their code like this:
    <?php
    $foo = "bar";
    $a = intval(date("m"));

    if( $a > 5) {
        echo $foo;
        // why isn't it showing today?
    }
    ?>
People then comment and sometimes downvote/closevote the question because...

The point is, is there a reason code blocks require an empty line before them, particularly since they don't require an empty line after? Couldn't it just detect the four-space-indent and go from there?

Secondary feature request: When hitting Enter, auto-indent to the same indentation as the previous line. It would save so much time! Maybe have it an option, though. I could live with Shift+Enter to do that.

7
  • 3
    I can't click edit.
    – Mark
    Commented May 1, 2014 at 10:48
  • 1
    @neomhmd Screenshot added. Commented May 1, 2014 at 10:49
  • mmm... am not sure anymore of my edit... maybe it spoiled the question? To be true, the external site full of Ads forced my iPad to open the AppStore (it's a new and awful trend in ads)
    – brasofilo
    Commented May 1, 2014 at 11:12
  • @brasofilo I've changed it to just link directly to the image. Commented May 1, 2014 at 11:15
  • @NiettheDarkAbsol: I took the liberty of editing your question to make the bug more explicit. Commented May 1, 2014 at 11:24
  • It's been most of a week, any opinions from mods on this? Commented May 6, 2014 at 9:21
  • 1
    I'ld never noticed this, since logically you WANT a clear line/empty space between your text and the code block visually, I always just sort of did it automatically without realizing I did it. Commented Nov 8, 2014 at 16:46

1 Answer 1

2

This is just the way Markdown works, and it doesn't seem to be that frequent to alter the parser. Instead, we as a community should check the source of posts like these for invalid formatting if we believe that something should be there, but it's not.

The rare occasions when these formatting issues happen can be dealt with easily if someone bothers to check the source of the post. In some cases, these posts may contain small to severe grammatical and other code formatting related errors, and when someone tries to fix them, they will see the badly formatted code and probably correct it.

It's generally a good idea to guide new users when using the site, and in case something like this happens, just edit the question and post a comment, stating:

Don't forget to add new lines before and after code blocks, so your code is properly formatted and indented.`

4
  • 1
    Maybe the question/answer forms can detect this and provide a pop-up hint: "It looks like you meant to start a code block here. Add a blank line." (reworded to not sound like Clippy) Commented Nov 8, 2014 at 16:15
  • I wanted to post an answer mainly to draw a bit of attention while still adding something to the question. I agree that this isn't the best solution, but it's something.
    – SeinopSys
    Commented Nov 8, 2014 at 20:12
  • @JeffreyBosboom: We have a big preview... and lots of help. But we cannot send someone around to force them to read, or even just look. Nor to take a second look after posting, or to wait at least a few minutes for immediate reactions... Commented Jan 22, 2015 at 2:21
  • Or we could standardize on code fences instead. Commented Sep 21 at 20:21

You must log in to answer this question.

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