27 March 2006 ~ 0 Comments

Formatting code in WordPress

Yesterday’s post about the Basecamp API had me quite frustrated for a while. It seemed like no matter what I did, the formatting on the <code> block was all wonky. It was adding spaces in places, and refusing to wrap some lines.

I’ve been using Scott Reilly’s Preserve Code Formatting plugin to handle most of the formatting. It eliminates the need to put your <code> blocks inside <pre> tags, which is quite nice. And I’d say it works about 99% of the time. But it fails on anything with a lot of < and >, such as XML… and yesterday’s post. So I looked into some other options including Geishi and Code Markup, but neither one seemed to fix the problem.

Setting the white-space property in my stylesheet for code did seem to help:

code {
white-space: pre;
text-align: left;
font: 11px, 'Courier New',Courier, Fixed;
display: block;
}

But for some reason, the XML was still not quite right. So I ended up putting my code block inside <pre> tags… blah.

A weblog that’s mostly about Python having trouble with whitespace issues. How ironic!

Leave a Reply