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?

  • 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. Jun 10 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
    Jun 11 at 7:44
  • 3
    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
    Jun 11 at 7:47


You must log in to answer this question.

Browse other questions tagged .