All Unkept

Leading whitespace in comments

Posted in: Python, Blogging and bloggers  — 

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 §

blog comments powered by Disqus