RSS-friendly code samples?

So in the past two days, my posts have contained a lot of code/text samples, that have to be formatted in a fixed with font and have their spacing preserved. Previously, I've just been using <pre></pre> tags around these samples. This work on blogs.sun.com, but I've found that this wreaks havoc with some RSS readers because the whitespace is not preserved. The newlines go missing, or whitespace disappears from the beginning of lines.

In an effort to be more RSS-friendly, I wrote a script that goes through and replaces spaces with &nbsp;, puts <br/> at the end of each line, and encloses the whole thing in <tt></tt> tags. The result is extremely ugly, but it seems to get the job done. I'm wondering, is this the best way to accomplish this? I'm not too familiar with RSS, so if anyone out there knows a better way that works for all varieties of RSS readers, please let me know. My googling abilities have yet to turn up anything...

Comments:

I would call this a bug in those RSS readers, and not worry about it. Reliably displaying HTML in RSS is basically not possible, as each reader implements a different subset of HTML, ranging from "none" to "embeds a full browser." If you switch to using tt tags, it is possible that you will "break" a reader that implements pre, but doesn't implement tt. I say let the human in the loop figure it out.

For reference, it works on my RSS readers (Straw for Gnome on Linux, NetNewsWire for MacOS X).

PS. I love the technical detail. Keep it coming!

Posted by Evan Jones on November 21, 2004 at 02:11 AM PST #

Post a Comment:
Comments are closed for this entry.
About

Musings about Fishworks, Operating Systems, and the software that runs on them.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today