Categories
Software and Programming

Javascript Textile follow-up

I got a comment from the developer of the GreaseMonkey Textile Javascript script I mentioned, which encouraged me to (a) actually try to convert a few entries and (b) once I discovered it was making a bit of a mess of it, look at the code and fix the bug that was giving me the problem.

Apparently, my use of parentheses was confusing a regular expression used to convert textile-style “links” into HTML links.

The change I made is in these lines (in bold):


// links
re = new RegExp('"\b([^"]+?)\(\b(.+?)\b\)":([^\s]+)','g');
r = r.replace(re,'<a href="$3" title="$2">$1</a>');
re = new RegExp('"\b([^"]+?)\b":([^\s]+)','g');
r = r.replace(re,'<a href="$2">$1</a>');

I replaced a match for “a run of characters between parentheses” with a match for “a run of character that aren’t parentheses between parentheses”.

Interestingly through the comments on the Textile Javascript page I found the blog of someone using Movable Type who rejected the Javascript version in favour of the server-side MT-Textile. This way makes sense – you can keep editing the textile-formatted entry, which the Javascript version simply replaces (and destroys), because it stays saved in the database, and gets converted to HTML only when you publish. Funnily enough, I find the Javascript version more useful, because I’ve moved my entries to a different content management system, and lost the meta-data about how to format them.
The point being that the best way to store blog entries is in HTML format, which is portable across CMS systems. (I know WordPress has a textile plug-in or rather two, but who knows if my next CMS will have one?)

1 reply on “Javascript Textile follow-up”

Comments are closed.