Eric Schrock's Blog

RSS-friendly code samples?

November 20, 2004

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…

One Response

  1. 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!

Recent Posts

April 21, 2013
February 28, 2013
August 14, 2012
July 28, 2012

Archives