I was wondering if there is an easy way to indent the code in Stack Overflow. Whenever I paste in code, all the code loses its indentation; what I have been doing is manually indenting every line with the space button. Is there a quicker way to do all of this?
To properly format code you should indent your code in the markdown source, either by a tab character or by 4 spaces.
There is handy button on the toolbar which can do this automatically for you, simply select the code section of your question and press this button (or type it's key shortcut Ctrl + K):
Fixing indentation would be the minimum what I would expect from StackOverflow (by fixing indentation I understand removing unncessary spaces as well as adding them when necessary, for example on if/for/while loops, nested XML tags etc.).
Of course, such features would require choosing the source language of code block - this is another feature that is missing. You can learn by heart
language: lang blocks, but it should be a menu option.
Of course, there are esoteric languages where space is a part of syntax, not formatting (Python AFAIK) so such feature must be optional and activated only by taskbar button.
You could paste you code into
nano in a Unix terminal, say you've got this:
Save it as
sad.txt in nano, then run the following line of code:
Here, we're replacing, as it were, the start of each line with four spaces, so when you open
happy.txt you'll be happy because you'll get the most amazing result:
From here just paste this directly into your post. Hope this helps/makes sense.