« DLR Notes 3 | Main | PowerShell Editors and Other Not-So-Fasc... »
I've struggled quite a bit over the past few months trying to come up with a good way of including code snippets in my blog posts. The problem, of course, is making the code look good both when browsing the website as well as in the RSS feed. It's not the first time I've ran into this issue, either.
As I've mentioned in the past, one of the things making it hard is my blog engine, as the dasBlog build I'm currently running doesn't properly respect whitespace in the original HTML code. Because of this, posting code is a big pain in the neck, as you need to format the code in HTML manually since using good old <pre><code></code></pre> tags will render the code unreadable in the RSS feed.
Beyond just having the spacing and indentation right, there's also the matter of posting syntax highlighting. There are several options I've tried over the years:
I'm sure there are many other options out there. I know there are some very nice plugins for other blogging platforms (like wordpress, from what I've been reading), but for obvious reasons that's not very useful.
Another issue that can be a bit bothersome with code formatting is the choice between using CSS rules or using inline tags.
In an ideal world, using CSS rules would be much more preferred, particularly if you can keep them in an external CSS file. One obvious benefit of this is that if you later decide to change your formatting preferences, your color scheme, or simply change your blog's layout and colors and want your code to match them, it becomes a whole lot easier (though this isn't all that possible for someone like me with 6 years of past blog posts with all kinds of code formatting used).
The downside of using CSS is that it's pretty much a website-only option, so it's not very useful for formatting code in your RSS feed. At least, my experience has been that most RSS generators and/or consumers will strip any inline CSS rules found in blog posts (this was, in fact, what happened to my last PowerShell post mentioned above).
I know of no way to easily reference an external CSS for this, but if anyone knows of a way, I'd sure appreciate knowing about it!
So that pretty much leaves, for now, the only option of not using <pre> tags and resorting to inline tags. Yuck! So, what's the secret sauce others are using for this?
About
Tomas Restrepo is co-founder of devdeo. His interests include .NET, Connected Systems, PowerShell and, lately, dynamic programming languages. More...
email: tomas@winterdom.com msn: tomasr@passport.com twitter: tomasrestrepo
Technorati Profile
Syndicate
Ads
Links
Categories
Statistics
Blogroll
Post Archive
Other
Copyright © 2002-2008, Tomas Restrepo.
Powered by: newtelligence dasBlog 2.1.8102.813