5

As you all know, there are two ways to format blocks of code, four leading spaces in every line vs. three backticks around the code. Many new users know about the first method, but not the second. When I edit a posting due to a spelling error or some other issue (which I frequently do), I often surround a block of code with ``` as well.

As @moewe pointed out to me, this can leave four leading spaces in each line of code (unless there was no code formatting in the first place at all). Are we supposed to remove those spaces? Is there a policy? Does it matter?

6
  • 2
    What should really matter most is leaving the code in a state easily copied-and-pasted by a potential helper. It should ideally be in the same format originally entered by the OP (if that can be determied). My recommendation, when asked, is to use the {} icon provided with both the question and answer boxes; that produces the four leading spaces. Commented Jun 10, 2022 at 13:55
  • 2
    I'm not quote sure about your usual workflow, but can't you just visually check if the code comes out as a code block in the preview window (or before you click the "edit" button)? In that case you don't have to do anything with the code markup for the code block.
    – moewe
    Commented Jun 11, 2022 at 7:44
  • 4
    If a user used four spaces to mark up their code as code and you want to use three backticks instead, I strongly suggest you remove the four-space indent (I think this can be done by selecting the code and pressing the {} button again). Otherwise the code will display with the four spaces and will be copied-and-pasted with the four spaces, which makes it more awkward to handle. But then I would not change the code markup method in a post unless there is a compelling reason for it (for one it might confuse the OP if there are only familiar with the other method).
    – moewe
    Commented Jun 11, 2022 at 7:47
  • 6
    you should certainly not add ``` if it is already a code block, what purpose would that have? At best it wastes 4 spaces of white space in the output, and at worst it invalidates the code. Commented Jul 20, 2022 at 20:31
  • When I edit a posting due to a spelling error or some other issue (which I frequently do)... | I recommend to read When is (and isn't) it acceptable to edit?: Unacceptable ... Fixing typos or grammar errors. Editing a question/answer for such small issues has the undesired effect of bringing the question back to the homepage, which can become a nuisance for frequent users of the site. There are two obvious exceptions for fixing these types of errors: ... Commented Aug 5, 2022 at 19:48
  • 1
    One of the exceptions (typically nr. 2) practically always applies. I don't go out of my way to edit old postings, they are either current or have been recently bumped by the Community Bot etc.
    – Ingmar
    Commented Aug 5, 2022 at 20:25

1 Answer 1

10

Both four space indent and surrounding with ``` are supported markup for a code block.

If an existing post uses one there is no reason to change to the other.

If an existing post hasn't marked up the code, so line endings are lost in the display, add either form (I usually use ``` these days)

If a existing post uses one form, Never add the other as well, such double markup is a destructive edit. Certainly if any edit did that to one of my posts I would roll it back, no matter what other edits had been made.

You must log in to answer this question.

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