TextileWrapper 2.0 and GeSHiWrapper 1.4

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: , , , , , , , ,

Similar Posts:

23 thoughts on “TextileWrapper 2.0 and GeSHiWrapper 1.4”

  1. Hi,
    I installed your plugin cause I know texttile from my textpattern times very good. I am using WP 2.0.4 and if I activate the plugin the page goes blank. Other plugins than do misbehave (postie e.g.).

    Any idea, do you need more information ?

    thx.

  2. Hi, just a quick note: you can use $geshi->set_header_style(GESHI_HEADER_NONE); to remove the div header/footer that are added, then you can add your own :)

  3. Hi, how can I get the plugin to work correctly with members that receive a wordpress email? They get the original source instead of the textilized one…

  4. Hi there.
    Textile has suddenly weirded out on me. I’ve been happily using it for quite some time and then suddenly the other day all the posts where I’d used it to display images (!imageurl!) just ceased to display. They completely borked my site – not only did the pictures not show, but any entry containing this markup completely failed to display and crashed wordpress. Everything else seems fine. I’ve upgraded WordPress and Textile to the latest versions, but the problem persists.

    I can’t find anybody else who’s had this problem. Does it sound familiar at all? My host is adamant that nothing changed on their end, and I certainly didn’t change anything. If this mysterious gremlin is just one of those things, can you let me know of a way to convert Textile markup back to HTML? I’m sorry if that’s heresy but I’m faced with individually editing every post and adding tags, which I really don’t want to do.

    I’ve tried the solution proposed here: http://wordpress.org/support/topic/48699 – but it just didn’t work for me. Maybe because some of my early posts use HTML? Anyway, any help appreciated.

    Thanks,

    Anthony

  5. Hello,

    I am trying to get rid of bugged wysiwig editors and textile seems really interesting.

    I have installed your version but unfortunately I have troubles using it :

    The h1. doesn’t work the text is missing (but h2. to h6. work well)
    more annoying, p>. p. doesn’t work as signs are translated to html &lt and &gt codes, not interpreted by textile…

  6. Are you typing the text into the rich-text editor? You need to disable it completely (or use a different tool for posting, like the code-view of ScribeFire). If you’re not accidentally using the rich text editor, it sounds like there’s another plugin interfering with the post text.

  7. Bingo !

    You are right, I forgotten to disable the rich-text editor (I am a wordpress beginner) and now it works well.

    Thank you Joel, I am now discovering textile :)

  8. Since I installed the TextileWrapper plugin, I’m having trouble w/ line breaks being properly converted. Previously, a single line break would automatically generate a tag whereas multiple line breaks would be converted to multiple tags as necessary. However, now a single line break isn’t automatically generating the tag. Normally this wouldn’t be a huge concern, but when posting lyrics or poetry content it throws off the spacing. Is this something that should work with the plugin or is this a setting I should look for in WordPress somewhere? (Google is coming up empty for me.)

  9. Very nice plugin. Just a quick question/observation, though. After activating, the paragraph tag around the “more link” text has disappeared. Any idea how to fix that? It throws off the bottom margin and link style if there’s no paragraph wrapped around the link.

  10. Erundur: The simple answer is … What?

    this is a poem
    of the neatest kind
    A rhyming couplet
    or I lost my mind

    you should recognize it
    from the way the rhymes
    are broken nicely
    into separate lines

    It seems to work the way I would expect, at least, it does here… Although I broke the lines an extra time, so the poem doesn’t make much sense ;) I’m not sure what we’re doing differently? One line break is a <br /> tag, and two is a paragraph tag. However, there’s no obvious way to add extra whitespace in textile: that is, to, say, double the white-space between two specific paragraphs.

    The answer, however
    is really quite simple,
    hopefully this will
    make your cheeks dimple.

    If you put the text “p=. “
    on a line of it’s own
    You should get a pair of
    empty p-tags all alone.

    Matt: I think you probably just need to put the —more— comment on a line by itself (with a blank line before it and after it) to explicitly tell Textile that’s what you want. Personally, I like my “more” links at the end of the paragraph, not on their own line.

  11. I will clarify what’s happening.

    With the plugin I was using previously, it would automatically convert line breaks I made in the post to break () tags. The plugin (or WordPress itself) is currently having an issue with this. What is happening is the first “paragraph” (anything I put in prior to having two consecutive line breaks) is being marked up, but it is not automatically creating line breaks in the HTML. As such in posts contain code or poetry, the first “paragraph” looks ridiculous because the line isn’t breaking where it should be.

    I hope this makes more sense now. It’s possible it’s just the way the newer version of WordPress is handling the spacing and nothing to do with the plugin, but if you have any thoughts I would appreciate it.

  12. Well, as you can see,
    That’s not what’s happening,
    On this, my site
    When you leave line breaks.

    It could be a problem related to continuing to use the rich text editor with Textile … you should input in the plain text editor. Are you having this problem with new posts in the plain text editor, or existing ones which had been created with the rich text editor?

  13. The problem is occurring on all posts. It could possibly be a stylesheet/template issue and I’ll have to check into that aspect further. I’ve been using the plain text editor exclusively because the rich text editor annoys me. Anyway, thanks for your help, and I’ll be trying out some other styles to see what I can come up with.

  14. Textile 1.0 came with my WordPress installation. I’m feeling really dumb, but I don’t understand what that plugin does. Is there an easy to understand explanation somewhere what I can do with that plugin? What will happen if I deactivate it?

  15. Basically, it’s an alternative way of writing your posts:

    1. You can choose the rich text editor
    2. You can write your posts in HTML markup by hand
    1. You can write your posts in Textile markup which is translated to HTML by the Textile plugin when a reader requests it.

    If you don’t want to write in Textile, you can absolutely remove the plugin.

  16. Not that you haven’t heard this before, but thank you, thank you, a thousand times thank you for TextileWrapper. Migrating to WP from TXP would have been unspeakable without it.

  17. Thanks for the plugins Jaykul! I'm using them on my website which I just migrated from textpattern to wordpress and they are working great… There is just one little problem I am having… It seems like the textile plugin adds extra

    tags whereever there is a linebreak in my writing. This happens where I am using “real” HTML as well as on textile posts…

    Is there any way to disable the plugin functionality on certain posts? Or so that it only works where it finds some actual textile formatted content? Moving forward I'll probably be using HTML and wordpresses visual editor for new posts. In some circumstances I need to use HTML anyway (e.g. where I need to pass parameters to a shadowbox popup or embed some code for highlighting).

    Thanks,

    Kelvin :)

Comments are closed.