Wednesday, September 10, 2008

Shame on you Blogger.com

You have failed to provide the tools necessary to blogger/developers trying to publish readable formatted source code to their blogs! There is, of course, nothing in the help about it and very little information elsewhere. If you saw my last blog, then you know I figured it out... so of course I will share with you :).

The key to getting code looking good on your blog is in editing your Layout html. There are various tools for generating nicely formatted HTML out of source code, but they typically require you to add the CSS to your layout manually. Here is a step-by-step of how I did it.

  1. Go here and generate your HTML. Make sure to check the "embed stylesheet" option.
  2. In the outputted HTML, grab everything between the <style type="text/css"> and </style> tags. This is your CSS.
  3. Click the 'Layout' tab here on Blogger.com
  4. Click the 'Edit HTML' tab that comes up under 'Layout'
  5. Paste your CSS (from manoli.net) inside of the <head></head> tags
  6. Save you customized layout
  7. You're almost done! Take the rest of the information from your generated html and paste it directly into your blog.
  8. Finally, in order to protect the text inside of the code from stange formatting and cutting, place these tags around your source code in the blog:
    1. <pre style="background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>
    2. YOUR FORMATTED CODE GOES HERE
    3. </code></pre>

That should do it for ya! Follow this example for other sites that use custom CSS. just insert their (or your) CSS into the layout and it's available for use in your blog! Thanks are owed to:

http://formatmysourcecode.blogspot.com/
http://mygreenpaste.blogspot.com/

No comments: