Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 157 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

Possible Duplicate:
Add feature to WMD for re-aligning code blocks

People seem to be prone to just paste code from their IDE into stackoverflow, often with reams of whitespace on the left-hand side. This unnecessarily wastes space and often also cuts lines on the right side.

Repairing that manually is almost as annoying as the breakage itself.

Example: http://stackoverflow.com/posts/2178418/revisions

Proposal: after detecting a code-block, remove (smallest number of leading spaces) - 4 spaces from every line.

share|improve this question

marked as duplicate by Adam Davis, jjnguy, Shog9, Robert Cartaino, perbert Feb 1 '10 at 17:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
That wouldn't work if it is a code block inside of a list item. – Brad Gilbert Feb 1 '10 at 17:07
    
@brad: replace 4 with $current_wmd_syntax_indent when reading my proposal. The point would be not to render unneeded left-hand-side whitespace, regardless of positioning. – David Schmitt Feb 1 '10 at 17:11
3  
oh, darn. this is a duplicate of meta.stackexchange.com/questions/35577/… and Jeff's answer was "It's open source!" – David Schmitt Feb 1 '10 at 17:13
    
Testing revealed that using ^K repeatedly on the block removes all whitespace, except for the last (indent mod 4) spaces. – David Schmitt Feb 1 '10 at 17:20
    
The doCode function is at github.com/derobins/wmd/blob/master/wmd.js line #2106 – David Schmitt Feb 1 '10 at 17:21

Even giving us a button to strip that amount of spaces would be good. It's a pain to do it manually every time.

share|improve this answer

If your code example is too long that it's a pain to do manually, consider shortening the code example.

Alternately, put it in a code editor, highlight it, press shift - tab a couple times, then copy and paste.

share|improve this answer

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