All Unkept
Posted in: Blogging and bloggers, Python  —  1 May 2006

Leading whitespace in comments

I fixed my blog comments so that leading whitespace is now preserved -- making it much more friendly to posted Python code.

It was a matter of adding these lines of PHP:

  $comment_text = preg_replace("/^(\s*)/me", 
      'spaces_to_nbsp("$1")', $comment_text);

...where the implementation of spaces_to_nbsp() should be obvious. Old comments won't be fixed, but new ones can contain Python code without worrying about whitespace issues. At work we use Sharepoint, and I noticed that it handles leading whitespace the same way as the above -- it would be nice to see more web apps doing this.

Comments §

No comments.

Add comment

Format:

  • Javascript has to be on to get past my spam protection, and cookies, and there is a delay, sorry for any inconvenience!
  • I reserve the right to moderate comments.