2006-08-27

Poor Code Formatting with Blogger

In reviewing my previous post, "Initial Experience with Detours from Microsoft Research", I must say that I am not impressed with the way the code was formatted. Blogger ate up all of the nbsp's that I had put in. When I put them back in, Blogger chewed them up again.

Anyone know of a way to get source code to keep its formatting when posting? Hope I'm not missing something overly simple! <g>

Or is there simply a better way to do it? Thoughts / suggestions welcomed!

10 comments:

Hakan Filiz said...

Im not happy with this issue neither...

Bad thing is, I already reviewed blogspot's how to pages, not even a single word on it.

put   chars on the html, wtich to normal view, come back again all gone...

If you could find the solution please let me know...

B00MER said...

use textarea to wrap your code in and be sure to give it a class or id with some good height and width and you can paste code all day with blogger.com. Just be sure and disable the auto line breaks or else you end up with <br /> tags in your code.

«/\/\Ø|ö±ò\/»®© said...

Thanks, b00mer - it took a bit of finessing, and the Blogger preview doesn't work so well with it, but I was able to use the technique in my latest post, "The Case of the Sluggish Internet Explorer 7" at http://mygreenpaste.blogspot.com/2006/12/case-of-sluggish-internet-explorer-7.html.

«/\/\Ø|ö±ò\/»®© said...

Sadly, I had to modify the post "The Case of the Sluggish Internet Explorer 7" (http://mygreenpaste.blogspot.com/2006/12/case-of-sluggish-internet-explorer-7.html) to NOT use the TEXTAREA technique, because of the Blogger "Convert line breaks" setting - I had to change it to "NO" to get the TEXTAREA to work, and when I did that, ALL of the previous posts were formatted poorly. I didn't feel like going back and reformatting each one, so I left "Convert line breaks" at "YES", and chose to use an alternative technique for dealing with the kind of things that otherwise would have worked well in a TEXTAREA.

Tom said...

The way I have solved this is by adding the code between "pre" tags. This way you can leave the "Convert line breaks" on and just use blanks and everything where you want them.
It still isn't perfect and sometimes weird things happen like certain parts of the text disappearing and other strange things alike, but if you format your code, put "pre"..."/pre" between them and then publish your text, it will most probably come out the way you want it to.

«/\/\Ø|ö±ò\/»®© said...

Thanks for the input, tom.

I've tried "pre" and "code" tags in the past, but in each case I have been less than satisfied with the outcome. I don't recall the specific disappointments, which probably indicates I should give them a shot again. Perhaps what once was not tolerable becomes more tolerable with time...

jeteve said...

I found a not so bad solution.

In the editor I format my code as a numbered list and I added the following css in the template:

.post ol{
white-space: pre ;
font-family: courier;
margin: 0px;
margin-top: 5px;
margin-bottom: 5px;
padding: 10px;
background-color: lightgray;
line-height: 1em;
}

It's not so bad even if we lost the benefits of numbered list (but who needs them really ?)

Clark Updike said...

I've used this with good success:

http://formatmysourcecode.blogspot.com/Formatting

Thanks to Greg Houston. Shame on Blogger for extremely lame publishing experience.

«/\/\Ø|ö±ò\/»®© said...

Thanks for the info, Clark!

Looks like the URL is:
http://formatmysourcecode.blogspot.com/

Mr K said...

Check this out, this is even better than the link above (even though you need to download a CSS); you get code coloring and stuff: http://www.manoli.net/csharpformat/format.aspx