EDIT I’m inserting an extra paragraph
Just to test if the textile stuff is misbehaving
Because I had an error report.

I’m releasing a new version of the WordPress Textile 2 plugin, as well as my own plugin for doing syntax highlighting with GeSHi. But I feel like I need to explain what’s going on, rather than just posting the downloads.

There are two big changes to the Textile 2 plugin. I’ve changed the way I’m distributing the plugin: instead of a single file, there are two, which must go together into a folder in your WordPress plugins directory. To simplify that I’ve packaged them as a .7z .tgz .zip which you can just unpack in the plugins folder. The reason for this change is that this allows me to distribute the unmodified classTextile.php from Dean Allen’s last textpattern release, and allows you the option of just replacing that file with the latest from the svn repository in the future.

I’ve changed the name to “TextileWrapper” to be more in line with what’s really going on. I want to make perfectly clear that I am not editing Textile at all this time. Any bugs with the way Textile work are Textile’s bugs, and should be filed via the Textile Homepage. Any bugs with the way it integrates into WordPress should be filed here. As far as the version number … Dean Allen has left Textile as “2.0 Beta” for a very long time, despite the fact that he’s on version 4.3 of Textpattern (which has been using Textile since the beggining). The internal revision number for the file has been divorced from actual revisions to Textile, because Subversion revision’s the whole project, so there’s nothing to go on there, either. At any rate, based on all that, I’ve decided to just call this version 2.8 as it’s really the next version of my “Textile 2” plugin, even though I’ve renamed it … and it really should work with any version of Textile since the first 2.0 Beta.

I finally came to my senses with this release and realized that the problem with code blocks is really not a Textile problem, but rather, a problem of the various syntax highlighters I’ve been using.

After playing around with some regular expressions, I’m releasing my GeSHiWrapper plugin as well. It’s exactly the same concept as TextileWrapper: a simple wrapper around an untouched GeSHi – Generic Syntax Highlighter which should allow you to upgrade GeSHi without waiting for me to release new wrappers. As with Textile, I’ve packaged the whole thing with the current GeSHi: .7z .tgz .zip which you can just unpack in the plugins folder.

The GeSHi wrapper is a little more complicated than the TextileWrapper, because it’s intended purpose is to do code highlighting in a way that works with the various markup plugins (Textile, Markdown, etc) without any problems. To accomplish this, it runs two functions: one before, and one after the actual markup plugin runs (this assumes that you have the priority of the markup plugin set between 2 and 9 — it’s usually 6). The basic idea is that before the markup plugin runs it extracts the code blocks, and afterwards, it syntax-highlights them and puts them back. There are two catches.

The first problem is a GeSHi problem: it throws out the “code” blocks and replaces them with “div“s. This means you can’t use it to syntax highlight code in-line in a paragraph, because it will invalidate your markup … but it doesn’t track that. What it does do, is only replace code blocks with a “lang” or “language” attribute (which tells it which language the code is in — that is: php or csharp, not english). To get GeSHi wrapper to work, you should put your code tags in their own paragraph (GeSHiWrapper will rip off an extra set of p tags), and you must specify the *lang*uage for the source code. If you use Textile’s markup to add code tags that will not be highlighted, since GeSHi looks for code before Textile runs.

The second problem is a style problem: since GeSHi puts it’s code in a <div class="code lang"> block, you need to make sure you style that div appropriately (particularly note the problem of long source-code lines like regular expressions which may not have spaces, and thus, won’t wrap properly in Firefox). Personally, I style the .code class with overflow: auto; to get scrollbars.

The only GeSHi option that’s currently exposed in the wrapper (apart from the code language) is line numbering. If you want line numbering on, you should specify an attribute “line” with a numerical value for the number of the first line (note that the first line of code is on the same line as the code tag). This allows you to quote from the middle of a file and still use the line numbers logically like so: <code lang="csharp" line="104">

Eventuall I’ll release a new version of this wrapper with a config page for some of the options … particularly the choice of div or pre and of using stylesheets and class names instead of embedded styles, but I have a lot of other work to get done first, so if you’re interested in syntax highlighting that won’t break with your Markup plugin, don’t wait for that.

P.S.: To show that it’s all working, I messed around with my most recent test post and added a bunch of highlighted code and a few of the usual Textile torture tests.

Technorati Tags: , , , , , , , ,