Then select the code you just pasted, and click the toolbar button or press ctrl+k.

Again, all of that is how Stack Overflow has worked for well on 5 years now. Not saying it is perfect or cannot be improved but to argue “the sky is falling, nobody can figure out how to paste code” just doesn’t ring true to me.

I agree with you that a source code button might make sense vs. the preformatted text button as @sam noted, it will just take us a little bit to get there as we want @eviltrout to eventually rewrite the editor in Ember. It is a post-v1 thing.

Default the language parameter to something like plaintext (dunno if that’s a real option) and let admins change that default if they’d like, which in the case of my forum would be java.

You’d also get this result when you highlight a multiline code snippet and click the code button. However, for one-liners, you’d get the 4-space indent instead, effectively teaching users code markdown through discovery.

Auto-detection of code would just teach my users to be sloppy, I don’t want that.

Edit: Here’s another suggestion for the Ember do-over. Autocompletion similar to the super handy @mentions helper. Maybe just as a plugin for the code communities, but I’d sure want this.

Exactly. We have a Sticky explaining how the code tags work both by using the buttons on the editor and “hand coding” them.
The Sticky is pointed to in the FAQ.
Several of us have “How to use code tags” pointing to the Sticky in our Signatures
Moderators and some members frequently ask “newbies” to put their code inside tags.

Yet one of the most frequent whines from Moderators is how often we have to edit posts to the correct format.

So I’m at least assuming you have the ability to detect something has been Pasted into the editor right?

I think it could be easy to add some keywords in the admin panel that get used in a regex against the pasted code. That way the admins of each forum can decide what to look for…

In my case it would be:

setup()loop()pinMode(digitalWrite(
to start out with…

It might not be bad to give us the power of a regex expression to work with as well, for cases likeif( vs. if (.

Then instead of just formatting it for them… it could pop up a helper modal that asks, “Shall I format this code for you?” in case it’s wrongly detecting things or maybe someone just really wants to NOT format code. This modal could also be optionally disabled by admins.

I have no idea why the learner put it that way, but that code - which is more complex than a “Hello, World!” program - has zero indents, so even if they had bothered to press the “Preformatted Text” button and then copy/paste their code in, it still wouldn’t have shown up properly.
(What’s especially interesting about that code to me is that the code editor Codecademy uses automatically indents you when you open a function and all that, just like a normal code editor. So this learner (like a large number of others) had to go out of their way to de-indent their code)

If the code formatting button would use triple backticks instead of four spaces, we could just tell learners to press the button, instead of giving them a short lesson on how Markdown works.

However, there could indeed be a preference for the multiple line code button that uses the triple backtick instead of indent, when multiple lines are selected. @eviltrout can you maybe add this to your list for 1.6?

Realize that programming related discussion is a tiny subset of the audience that Discourse targets. So excellent support for basic preformatted text is much more important to us than specialized support for programmers and coding. It is true that the fenced code block method is largely hidden – you’d have to infer that exists based on the fact that this is Markdown and GitHub uses fenced code blocks in Markdown too.

Now I know.

But does a general audience really use pre-formatted text much? It seems possible that Discourse has say 1,000,000 non-coding users, 1% of which care a little bit about pre-formatted text, and 50,000 coding users, 100% of which care quite a bit about having code blocks.