168

Stack Overflow already uses its own markdown extensions, and there is already overlap with GitHub Flavored Markdown. There are very few additional pieces of syntax left to bridge the gap completely.

Specifically:

Fenced blocks in particular are quite useful when getting indentation right is annoying.

Additionally, if you attempt to use fenced code block on Stack Overflow, it sorta appears to work — just poorly. This is because the triple backticks render as an inline code comment. Like below:

Image showing how triple backtick code blocks used to be rendered as inline code, where as space-indented code blocks render like a full code block.

12
  • 1
    Related - Is there any markdown to create tables? You do know about the existing Stack Overflow mark-down options for each of those (with the exception of tables, obviously), right? Commented Apr 17, 2014 at 21:14
  • 1
    Syntax highlighting in SO is the worst. Those awkward HTML comments need to go. I'd love to see fenced code blocks w/ syntax highlighting hints in SO. Commented Apr 18, 2014 at 4:38
  • 3
    On the roadmap, some day: Implement ```-style Markdown code blocks.
    – Arjan
    Commented Jun 14, 2014 at 7:24
  • Related: meta.stackexchange.com/questions/238957/…
    – Ajedi32
    Commented Jan 15, 2015 at 15:01
  • 2x 3 backticks does not work. The first and last two are read as empty. So in the end 1 backtick is read. Btw. Fully support the request.
    – snh_nl
    Commented May 3, 2015 at 15:07
  • 2
    I've been itching for this for the longest time. Relying on indentation is a huge pain. It makes copy-pasting between SO and an IDE a huge pain the butt. Working with triple-backticks is vastly easier for my workflow. It works in Github and Slack, why not here?
    – acjay
    Commented Jun 2, 2015 at 15:17
  • I wanted to request a similar feature today (in terms of markdown table support), but came across the many posts with not so satisfactory answers... How can we make this gain more traction? Commented Sep 30, 2015 at 5:11
  • 8
    +1000. It's amazing StackOverflow doesn't support this.
    – ffxsam
    Commented Oct 13, 2015 at 21:01
  • Agreed! Hate it when I paste in my XAML and SO thinks it's C# or something. Specifying the language (and code blocks) would be much appreciated!
    – James Ko
    Commented Nov 15, 2015 at 21:41
  • 1
    It's almost like SO lives in their own little bubble while the rest of the programming world has embraced gfm.
    – user128511
    Commented Nov 27, 2017 at 5:20
  • 3
    It's unbelievable that this website still doesn't support standard markdown after all these years of people asking for it. @jeffatwood What the heck??? This place is going to go the way of Experts Exchange one day.
    – MgSam
    Commented Feb 23, 2018 at 15:36
  • 1
    A thousand times please.
    – user7236046
    Commented Apr 19, 2018 at 13:20

5 Answers 5

145

Triple backtick support please!!!!

It's super annoying that in order to paste code into Stack Overflow, I have to copy my code to a new file in my text editor and then indent it. Or, I copy some snippet and then have to manually add 4 spaces in front of each line.

With triple backtick like GitHub flavored markdown that problem would disappear.

Some people suggest hitting {} or using Ctrl + K but that doesn't work inside blockquotes (like when quoting a spec) nor inside ordered/unordered lists (like when listing steps).

9
  • 11
    What about the {} button? Or Ctrl+K?
    – brasofilo
    Commented Jun 14, 2014 at 9:07
  • 14
    @brasofilo How to do Ctrl+K on an ipad? I also find selecting the lines of code quite unwieldy on an ipad too. So +1 for this. Commented Jun 14, 2014 at 18:28
  • 5
    @MartinSmith, I think it's the first time tablets enter the argument for the feat-req... Seems legit!
    – brasofilo
    Commented Jun 14, 2014 at 20:22
  • @MartinSmith there's a {} button on the asking/answering textbox that you can use without a shortcut key
    – phuclv
    Commented Oct 17, 2014 at 5:54
  • 7
    @LưuVĩnhPhúc - The problem I have on an ipad is even selecting just the desired section of code in the first place. If the code section is larger than the text area and requires scrolling this can be extremely difficult. Also sometimes the Ipad tooltips when text is selected obscure the toolbar buttons anyway (tend to notice that one when trying to apply a link to a word towards the top left of the post. Commented Oct 17, 2014 at 8:02
  • 3
    @brasofilo I'm not sure what I'm doing differently, but when I paste a block of code using {} if the code wasn't indented already then it doesn't get formatted as code in my post. I end up using emacs to put 4 spaces in front of each line then cut/paste the code from there. Commented Dec 4, 2015 at 2:10
  • @bmacnaughton, as far as I know, there's no sandbox here on meta.so for us to play with formatting, but there's one at meta.se: Formatting Sandbox. Just add an answer and try anything you want over there.
    – brasofilo
    Commented Dec 4, 2015 at 3:31
  • 1
    @bmacnaughton it seems ridiculous that you have to do that
    – jcollum
    Commented Dec 4, 2016 at 19:41
  • 2
    It's an insult to all users that the triple backtick syntax is not supported. IMO a very poor decision for a platform that is used by so many coders around the world. Even worse that it still is not here as of 2018. What is the single good argument to not add this feature that prevents it from being added for four years?
    – Neonit
    Commented Sep 18, 2018 at 9:41
72

Another benefit that I'm surprised hasn't been given more emphasis is the ability to specify the language

```php
class PleaseAdd { 
    public function tripleBackTicks() {
        echo "please";
    }
}
```

```javascript
console.log("add triple");
alert("backticks");
// please add them
```

Instead of the horrific

<!-- language: lang-php -->
5
  • This would be quite useful. There are libraries to handle many languages, it's an extensible syntax, and not reinventing the wheel makes a lot of sense - github seems to be the standard here. Commented Dec 4, 2015 at 2:07
  • Especially horrific due to the additional required newline. Commented Sep 26, 2016 at 22:05
  • 1
    "horrific" is a bit of hyperbole don't you think?
    – jcollum
    Commented Dec 4, 2016 at 19:42
  • 17
    @jcollum no. I have nightmares about it Commented Dec 4, 2016 at 20:28
  • 2
    This <!-- language: lang-php --> is horrific! I always need to go Google to remember the exact syntax
    – Yves M.
    Commented May 9, 2018 at 9:14
12

Code fences have now been implemented! Secret MSE announcement, updated formatting help. Unsurprisingly this doesn't apply to SO chat, but let's not be too grasping.

2
  • Chat formatting has, and always will, suck. There's no need to implement code fences because you can't have code blocks be a part of a message - a message is either a code block, or it doesn't contain any. Considering chat is also not maintained, it was never likely to receive an update. Commented Jul 6, 2021 at 17:12
  • @Zoe you'd be surprised how many people post code blocks in separate messages---but with code fences. I'd guesstimate at least 50% of malformed code blocks are such. Commented Jul 6, 2021 at 18:51
4

Another thing to consider is, that some people write the code directly inside the answer. Ctrl+K works ok if you have everything as you want it and then format it at the end. However, this is often times not the reality so while writing code the preview looks strange since the first and last line will not be part of the code block. Then the more annoying issue is when you think you are done and format the code and then realize that you've missed something you have to format each new line you add (you are in luck if they are connected then its only one action per block).

For these reasons, I end up using the <pre><code></code></pre> blocks most of the time, but they are cumbersome especially if you have multiple code blocks. And as andrewtweber pointed out the ability to specify the language without having to google how that <!-- language: lang-java --> tag format was again is a really nice thing.

<pre><code>
<!-- language: lang-java -->
</code></pre>

vs.

```java
```

56 vs. 12 chars

Furthermore, so many coders use github (or gitlab) and fenced code blocks have become a de-facto standard. So please improve the UX by adding them to SO.

3

In addition to what the other people have said, adding the triple backtick code blocks would save a some work for the editors.

Many people post code, expecting triple backticks to work. Unfortunately it does not, wasting many person-hours to correct it every day.

4
  • 2
    I've only ever seen this twice in the last year that I recall, do you have any example of many person-hours getting wasted daily due to this issue as you claim? I'm just not sure it's as urgent of an issue as you make it sound.
    – Davy M
    Commented Apr 15, 2018 at 1:11
  • @DavyM I've done two today. I've tried to find them, but the suggested edits are hard to search. It's not that urgent of an issue, you are right, but having to do it by hand it annoys me every time I see it.
    – Azsgy
    Commented Apr 15, 2018 at 1:18
  • 2
    stackoverflow.com/review/suggested-edits/19436563 An example of what @Azsgy is talking about.
    – idmean
    Commented Apr 15, 2018 at 6:59
  • You can see how content will render before you post it so I don't really see why specifically the missing feature would be the cause of wasted time. Carelessness is more the cause, that is not going to go away with support for triple backticks. Editing will always be required for carelessly posted content. I would get used to the idea of having to endlessly repeat the same fixes if you take up the hard task of reviewing.
    – Gimby
    Commented Apr 19, 2018 at 8:05

You must log in to answer this question.

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