Forgive my frustration, please, but, highlighting code with "four spaces for each line" ... is very inefficient.

I had a problem with some code that spit out errors I would like for the community to review. The post about it is here: Possible explanation for error and site crashing randomly without any provocation?

I wanted to get this up very quickly, and I wanted to highlight the code so it could be easily and visually be separated from my comments surrounding the topic.

Instead of getting this thing up and posted so it could be considered by the community, I spent more than a half hour trying to correctly put in "four spaces here, four spaces there" .... AND it is still broken. I have no idea how to fix it. I don't know where the hell to put what four spaces where!

this is ridiculous, especially when 99% of the other sites in the world simply have the requirement of "code" "/code" (in lessthan-greaterhan brackets) to surround their code and the systems takes care of the formatting automatically.

Why is this not a standard here?

Albeit, I am fairly new here. Maybe there is a way to do what I was trying to do more efficiently. But, I have over 1000 rep points with some bronze and silver, and given that, I have been a casually active member of the community for a year.

If there is a more efficient way to do what I was trying to do, then of course by all means teach me. And, if that is the case then it begs the question, "Why in the world is getting this done so complicated and the UX so complicated that it takes more than a year for the contributers to figure it out?"

3 Answers 3


Why is this not a standard here?

I'd imagine it's because StackExchange enforce stricter quality guidelines than other places. It's part of what sets SE aparts from forums and other Q&A service...attention to detail. People who ask questions are expected to to make more time and care over their formatting/language, but in return the quality of answers/answerers is far higher than you'll find elsewhere.

However it is of course understood that endless manually spacing is a pain in the ***, so let me introduce you to the Preformatted Text option on the WYSIWYG :)

enter image description here

Paste your code in as normal (presumably it will be pre-formatted from whatever IDE you use, the onus is obviously on you to format your original code), highlight it, then press the button shown in the image above. Your code will be auto-indented, no effort required.

If that's a bit much effort (I know it is for me) you can use the keyboard shortcut Ctrl+K when the code is highlighted.


Stack Exchange sites use Markdown, where text indented with four characters is rendered as code. This doesn't mean you need to manually indent the code (except in one case): You can do as Clive said, or you can simply select the code, and press ctrl+k.

Also, as some HTML is allowed, you can enter code with <pre><code>, without the need to indent it with four spaces.

if ($user->uid == 1) {
  $access = TRUE;

That is almost not different from the following.

if ($user->uid == 1) {
  $access = TRUE;

In the first case, what I wrote was:

if ($user->uid == 1) {
  $access = TRUE;

The code entered between <pre><code> is automatically highlighted.

I used <pre><code> because <code> doesn't preserve new lines, doesn't avoid Markdown is rendered, and doesn't highlights code. (Code is not highlighted on the meta, in any case.)

For example, see the following code.

SELECT * FROM {users} u WHERE u.name == 'random'

What I wrote is the following.

SELECT * FROM {users} _u_ WHERE
u.name == 'random'

My vote is to add Github-style fenced code blocks, which look like this:

if ($user->uid == 1) {
  $access = TRUE;

You must log in to answer this question.

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