Spot any errors? let me know, but Unleash your pedant politely please.

Wednesday 27 May 2009

Blogger, spaces, &nbsp; and <pre>

OK, So I've been posting bits of code of late, and Blogger buggers up the spacing. It removed leading spaces and trims multiple spaces to single spaces. This is probably good for the average blog post, but really, really bad for indent dependent Python.

I finally got around to Googling the problem. I'll repeat it here, just in case this helps someone else.

This is how I was doing it until today:

<code>
def double(x):
&nbsp;&nbsp;&nbsp;&nbsp;return x*2
</code>

But now I know about <pre></pre> and I can write this instead:

<pre>
def double(x):
    return x*2
</pre><
To show this:

def double(x):
return x*2

Much better !

2 comments:

  1. This isn't working so well for me. I want to insert white space, just plain white space. Looking at your post, I thought I could use the pre tag with white space in the middle of it.

    But apparently blogger hates it if I ever mention  . I don't even know if that's going to show up right in the comment here. But anyway, I thought I'd be able to insert some white space using the pre tag, but it appears that it won't let me do it without inserting line breaks.

    Is there any way to use the pre tag without it putting the line breaks with it? Thanks.

    ReplyDelete
  2. It is clear on what user should do. Can you kindly make it more elaborate
    Domain Hosting

    ReplyDelete