Looking to upgrade my blog with live previews I came across several methods, however, since my comments allow for Textile formatting, I wanted to see if that could be processed on the fly.

I googled and was surpised to see that someone had already started working on it. I was quite pleased with the solution I found, but it was missing a few things:

* h tag support
* br tag support
* proper html syntax (a few tags were being closed incorrectly.)
* Various small fixes

So I went and upgraded the JS to include those things and made a demo paged. Check out the Live JS Textile Parsing in action. All of the source code is on there and free for use. I would like credit through, and I am sure Stuart Langridge would appreciate keeping his ;-)

h3. Useage warning

Everything looked great. I had it ready to go, tested it locally and it worked fine…

…until I made the code live of course.

I kept on getting this crazy JS error in FireFox that went something a little like:

@Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLElement.innerHTML]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://www.creatimation.net/textile.js :: reloadPreviewDiv :: line 67" data: no] @

Anyway, I figured out what the problem is: Apparently Gecko has issues with using the javascript property “innerHTML” when the mime type of the page is “application/xhtml+xml”.

Solution? Turn the site back to “text/html” and it works great. Bummer about having to turn it off – I’ll see if I can find another way to do this while still allowing for the use of the correct mime type for these pages.

Update: This error occurs because there is no innerHTML varaiable in XHTML because it is a proper XML derivitive. This means that any inserted code must be done so with proper dom intserting elements. This, however, would either require an incredibly smart function to take a string and convert all the HTML to dom objects, or a complete rewrite of the function to be DOM friendly in the first place — neither of which is a really happy idea.

So, for the time being, the “turn off mime type” is still the best I’ve got.

Let me know if you find it useful!