Archive for the 'Code' Category

Rich text blog editor (with inline images)

While composing a blog entry today (which was subsequently eaten by a Safari crash, despite Saft valiantly saving my tabs), I became frustrated by the difficulty of putting screenshots and text together into a simple blog post.

So, here’s my idea: Someone needs to write a blog editor, similar to MarsEdit or ecto, that supports simple HTML, graphical tables and image insertion.

Let’s see what current OS X frameworks and applications can do in this vein:

  • TextEdit can export HTML and has a decent table creation interface, but chokes on saving images into its HTML, opting for a “Web Archive” file instead. These Web Archives aren’t packages as I originally thought; they contain their images inline in the file, relying on a file:///myimage.tiff URL scheme to refer to them.
  • Safari now supports the contentEditable property on objects, but requires quite a bit of JavaScript to fill in the cracks make it into anything useful.
  • Mail.app somehow exploits Safari’s contentEditable system to create a decent-yet-buggy rich text editing environment. This might be the closest thing to what I’m looking for. I wonder if the framework is documented anywhere, or … heh … how many hacks they had to use besides implementing contentEditable in WebKit?

Maybe a better solution would be to create a WordPress plugin to which one can upload a Web Archive and automatically create a post, saving the embedded images out into a unique directory keyed to the post slug. I thought of saving the images right into the database, but that would lock the user into using the plugin forever. It’s not good practice to store data in a non-standard way.

Since writing the previous paragraphs, I’ve found out about textutil, which you can run web archives through to convert them to plain old HTML and JPGs (if images are in the archive). Why not create an AppleScript Studio app that uses XML-RPC and textutil to simply allow the user to utilize the existing OS X rich text editing environment (like in TextEdit), and upload a post to WP.

Better yet, how about just making rich text editing a feature of the next version of MarsEdit or ecto? Brent? Adriaan? Are you listening? :) (Remember, I paid for MarsEdit and donated for Kung-Tunes.) Seems like I heard something about that in plans for one or the other of those two.

Update: I haven’t played with ecto in a while, it seems. ecto supports rich text editing, but not with inline images. Gotta have those inline images. No reason not to. TextEdit does it. C’mon.

Safari Crasher

This code crashes Safari 2.0 (412), the build included in Mac OS X 10.4.1. I’ve no idea why. If you type something in the field and then click or tab away, Safari (or any other WebCore instance) instantly freezes and/or quits. But it doesn’t always happen the first time.

<input type="text" onblur="this.type='password';" onfocus="this.type='text';" />

View an actual crashing field (don’t if you have open tabs that you want to keep).

FireFox handles it just fine, though some internal JavaScript errors show up in the JavaScript Console. IE just complains of an error … it doesn’t know how to set the .type of an input type="text".

I should submit a WebCore bug, but I’ve never done that before. Looks like I have to search for the issue in BugZilla first.

Can anyone confirm this?