Sunday, August 3, 2008

Indenting code

Frustratingly, there doesn't appear to be a good way to tell blogger not to mess with the indentation when you paste in python code. The best solution I've found is to do a find-and-replace before pasting, replacing every tab or set of 4 spaces with:

    

Bleurgh.

Update: Greg Houston's handy Format my source code Javascript app tipped me off that the key is simply to add the following tags around your code.

<pre class="source-code"><code>
your code shows up in Courier font

and it keeps the tabs
</code></pre>

will appear to the reader as:


your code shows up in Courier font

and it keeps the tabs


Or for extra-special badness:

<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #ffffff; background-color: #111;font-size: 14px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>
your code shows up in Courier font

and it keeps the tabs
</code></pre>

becomes:


your code shows up in Courier font

and it keeps the tabs

No comments: