Follow by Email

Tuesday, November 06, 2007

Code spacing and Blogger

I'm really getting frustrated with Blogger's inability to keep spacing when I provide well-indented code. It makes me want to not supply code samples. It makes me want to not post.

How do people successfully post code samples to Blogger? I could use some help. I don't feel any particular loyalty to Blogger, but making such a switch is always a pain.

Since I work for Google, I feel compelled to say: these are my own opinions and not those of my employer.

9 comments:

swankjesse said...

I write HTML by hand in my posts, with <pre> tags around my code to retain spacing.

I also setup prettify to add painless syntax colouring.

Jeremy Osborne said...

Ditto the above, although I'm using a self-hosted Wordpress.

Does Blogger have some sort of "code" pseudo tag?

NEW METAMORPHOSIS said...

I startied deleting 'div' tags, and using the previous 'p' as a sub w/ some success. I'm going to see if it gets even better by, using 'pre'

New Metamorphosis
asecondcup.blogspot.com

Anonymous said...

Did you have any luck with this? I have tried pre tags, but can't figure out how to prevent line wrapping in IE.

I too find it very frustrating. I can't believe some psuedo-code tag isn't built in...

NEW METAMORPHOSIS said...

I use some very elementary html, and it seems to circumvent the later versions to date. I have had very good luck (most of the time) with inserting the 'br' tag exactly where I want each line to break.

Anonymous said...

Thanks much for the follow up. I have had zero luck in the blogger groups on this topic ;)

Ideally it should display scroll bars for long lines of code instead line wrapping. But some versions of Internet Explorer don't seem to obey "overflow". Have you had any luck with this in any version Internet Explorer?

swankjesse said...

Try this CSS from java.net:

pre {
/*width:100% !important;*/
width: 600px; /*for IE, which doesn't obey !important or width:100% on pre*/
clear: both;
overflow: auto;
padding-bottom: 0 !important;
padding-bottom: 1.5em; /* for IE which doesn't make room at the bottom of the pre for a horizontal scrollbar */
}

Anonymous said...

swankjesse,

Thanks. I will give a try and let you know what happens.

Anonymous said...

Weird. It sort of works but it seems I can either have

- scrollbars and preserved indentation (good) but with line wrapping (bad)

or

- scrollbars with no line wrapping (good) but without preserving identation (bad)

I think the template CSS may be mucking things up, because that CSS should work ..