Site Navigation

Jun 17, 2009

Workaround for Textile 2.0 PHP 5.2.x Bug

PHP Logo

At work we use the Confluence wiki quite a bit. The wiki markup is based on the textile markup language. Well to save myself some time, I decided I would download the textile php class and work on my document locally. So I downloaded the 2.0.0 zip of the PHP file, installed it on my web server, and linked the document I'm working on. My PHP script worked, but the list output was all messed up. Every list generated by textile would look like this:

    <li>Item One</li>
    <li>Item Two</li>
    <li>Item Three</li>

Very annoying. Anyway after much searching, I have come to the conclusion that this is caused by a bug in PHP 5.2.4 or later. (Although there seemed to be much debate about which version of 5.2 it started with.) I'm running OS X 10.5 and have PHP 5.2.8 and I definitely have the bug. The main solution involves a patch, which I don't really want to attempt. However, after further digging, I found this workaround (Thank you David Green where ever you are.).

Find the fList function in the classTextile.php file. Replace these two lines of code:

foreach($text as $line) {
  $nextline = next($text);

with these two lines of code

foreach($text as $nr => $line) {
  $nextline = isset($text[$nr+1]) ? $text[$nr+1] : false;

Fixed me right up. And hopefully, this note will help other Mac OS X folks out there.

Post a Comment

Favorite Links Feed