At least on Stack Overflow, new users tend to insert their code using the { } "code sample" button in the formatting bar, which uses 4 spaces to pad the code and create a code block.

However, I've seen several occasions where this formatting goes awfully wrong, especially when the code uses HTML tags. This leads me to believe that it's difficult for users to count and maintain the 4-space padding syntax for code blocks.

The problem with the padding being difficult to maintain is that this small mistake can easily lead to incomprehensible questions and answers. Consider this example snippet of HTML, with a single missing space on line 2:

_   <div>
^        <i>world</i>
         <OfHiddenPossibilities />

     <br />

The above will render as this garbled mess, with content malformed or missing altogether:

<br />

This issue isn't hypothetical; here's an actual posted example that I faced recently: https://stackoverflow.com/posts/56364987/revisions

While reading such a post, most newcomers won't know that something went wrong in the formatting, and experienced users may not bother checking the original Markdown source when editing it.

Another issue with the indent syntax is that there's no (non-deprecated) way of specifying a language hint for the highlighter. This means that any time the highlighter gets it wrong, and someone wants to fix it, the editor usually must swap out the indent syntax for code fences, which can be tedious and frustrating in-editor (even when using Ctrl+K or the code sample button to adjust the indent).

My feature request is this: Can we alter the { } button behavior to use the code fence syntax by default instead of the indent syntax? This will make formatting code in posts more stable and more robust, especially for new users.

(Note that I'm specifically requesting that the "old" editor be updated to swap syntaxes, as the new Stacks editor already made this change.)


You must log in to answer this question.

Browse other questions tagged .