Showing posts with label blogger. Show all posts
Showing posts with label blogger. Show all posts

Wednesday, March 4, 2009

Using CSS To Wrap Your Pre-Formatted Blogger Text

Hey There,

Today's post is going to be a bit short, by which I mean that it's not going to be long. Of course, it also won't be short in the sense that it won't be abrupt and rude.

See ya,





Just kidding... ;)

I spent most of the time I had to come up with something to write about today, driving myself nuts trying to figure out how I could make this blog's code examples and block-quotes work in IE, FireFox and Opera; not to mention all of the other browsers out there. I don't think I'll ever be able to get the code examples to properly indent on Lynx, but at least it's readable now.

Even as I worked on that issue, I had this nagging feeling that I was going to have to go back and re-tag all 520 odd posts we've already put out, like I had to with our follow up on the absorption of knowledge in the computer age, which was the first post we'd ever done where the entire post had to look like a letter when seen from a bird's eye view. So, that was a bummer.

I started noticing that pretty much every forum I visited was filled with nothing but useless flaming. Guys who had the same question as I did, but were answered with some variation of "Why would you want your lines to wrap if you've already pre-formatted your text?" after which non-solution after non-solution would be offered up to not-answer the question ;)

Of course, there are some good reasons to want to be able to word-wrap your pre-formatted text. For instance, in this blog, we put up code from time to time. Sometimes a lot, sometimes none. But when we do put up code, we wrap it in the <pre> tags to preserve the indentation. This might not be necessary, but there's only so much leeway you have on Blogger. You have to use the tools they give you. No use putting in format tags that they don't honour. So, anyone can see that a loop within a loop within a conditional, with tabbed indents, can move the code out pretty far from the left-hand margin. So, if one of the triple-indented lines contains a good amount of text, I'd want that text to wrap around (just like it would in a standard terminal editor) instead of disappearing off under the right-side column.

Anyway, this post ends with good news that's both succinct and helpful (especially if you publish code on Blogger, too). All you actually need to do is add a "post pre" section to the CSS style section of your Blogger template. The beauty of this solution is that, not only does it work on all three of the aforementioned browsers, but it also fixed all of our previous code posts in one fell swoop :)

The code itself is here, you can add it anywhere in the:

/* Posts
-----------------------------------------------
*/


section. The CSS code is directly below, and the "post pre" container may not exist in the template you're using, just as it didn't in mine:

.post pre {
white-space: pre-wrap; /* This is for IE and other browsers that just have to be different */
white-space: -moz-pre-wrap; /* This is for FireFox and Mozilla Browsers */
white-space: o-pre-wrap; /* This is for Opera */
}


And, just like that, 500 or so wrongs have been righted. We'll be back tomorrow after we're all done being excited :)

, Mike




Discover the Free Ebook that shows you how to make 100% commissions on ClickBank!



Please note that this blog accepts comments via email only. See our Mission And Policy Statement for further details.

Sunday, December 9, 2007

Publishing Perl, Shell and Other Code on Blogspot

Good Day

Today's post is slightly off-topic, although directly to the point of what this blog is about. Today, I'd like to pass on a few tips that might help fellow bloggers, like myself, in the future.

The tips we'll be going over today will help tremendously (especially if you're just getting started) if you publish a blog that includes lots of examples of scripting and/or code. The default setup and editors for Blogspot and Blogger provide certain mechanisms for making this possible, however, they're not entirely obvious. I spent a good deal of time piecing this stuff together from various posts in the Google Blog Help group and Blogspot's Help Center. Many thanks to all the people who contribute to these sites.

The first thing to note is that Blogspot/Blogger does allow for you to include a <code> tag, which it seems to honor. Unfortunately, this does not preserve the integrity of your code. All it does is indent the entire section of code slightly and remove all indentation!

The <blockquote> tag, also does approximately the same thing.

In order to get your code to post "as it is," you need to include both a <blockquote> and a <pre> tag (with closing tags, of course - e.g. </pre> </blockquote>).

But, that's not the end. If you use < redirects or Perl's while input markers (< and >) you'll get nailed with gigantic "Tags cannot be unclosed" errors that sometimes end up being larger than your post itself, and prevent it from publishing.

The only reason you can see the one's I've put up in this post is that I entered them as "&lt;" and "&gt;" (for < and > respectively). Even more confusing; in order for me to print out those special characters so that they showed up the way you need to type them, I had to enter them differently. For instance &lt; had to be entered as & amp; lt; (Just remove the spaces between the 3 elements. I'm getting dizzy from all the dereferencing ;)

I'll be going through all my old posts and throwing in those format tags (luckily I've only been at this for a few months (about 70 odd posts))

Hopefully, this post will be helpful for anyone looking for information specific to including computer code and script in your Blogspot/Blogger posts.

BTW, you would not believe how convoluted this post looks in the editor ;)

Example straight code:


if [ this -gt that ]
then
how_about_that=1
fi < /export/home/food.txt
<-- Note space added before /export to avoid getting the publishing error.

Example formatted code:


if [ this -gt that ]
then
how_about_that=1
fi </export/home/food.txt


Best Wishes,

, Mike