Skip to main content
Hi, my name is Al Tobey. For now, go to http://www.tobert.org to learn the grossly-out-of-date details.

I'm investigating whether or not I want to move http://www.tobert.org to Blogger. I'm doing it to save time/money and to take advantage of integration between the various Google tools, where it exists. I've also often considered posting more often, which I avoid because my current setup is still a PITA.

The main snag I'm working on right now is how to post code examples. So far, it looks like nobody is really doing it well. Most of the "solutions" I've found involve stuff like sed 's/ /\ /g', which isn't very elegant when HTML has tags specifically for this kind of thing.

Previously, I defaulted to using the <pre> tag for code examples. So far, I've tried <blockquote> and <p style="white-space: pre;"> (which I learned about at http://www.htmldog.com/ptg/archives/000077.php)

Anyways, I'm going to keep editing this post adding copies of the below code until it works.

Using <pre>:


#!/bin/ksh

for file in *.html
do
# this should be indented by 4 spaces
sed 's/ /\&nbsp;/g' < "$file" > "$file.new"
mv "$file.new" "$file"
done


Problem solved:: It appears that <pre> is ignored in the preview you get in the edit posts view, but not on the published page.