TextMate Renders Styled HTML Now

I use TextMate and just love it. I particularly like the syntax highlighting and formatting and the ability to pick themes. My current favorite is Twilight.

The way TextMate understands various languages (e.g. HTML, CSS, Ruby) is via “bundles”. Bundles also define extra “commands” to the editor e.g. there’s a command to run the W3C syntax validator on the current document. There are a bunch of bundles that ship with TextMate, and there are also a bunch being developed by the community.

Anyhoo, over on #refreshdallas IRC yesterday evening I was asking if anyone knew of a way to induce TextMate to output a styled HTML file for whatever file you were currently editing. The idea was that if I was editing Ruby, or CSS, or HTML or whatever, and I’d chosen a particular theme, and I liked the way that looked — I’d like to be able to press a button and generate an HTML document that I could drop into my blog or into an S5 presentation. The way I’ve been doing this lately is to capture a TIFF of the TextMate window via Grab but that’s just tedious (have to convert to GIF and then there are all the sizing limitations associated with images.)

While I was on the #refreshdallas IRC I was also on the ##textmate IRC asking similar questions and some really helpful people told me about the “Experimental” bundle. It had a command very close to what I needed called “View Document as HTML”. That one did not use the current theme to generate the CSS (it had a hard-coded CSS embedded) and it didn’t show the HTML — it rendered to a WebKit HTML window directly. They suggested I use that command as a starting point, so I played around w/ it a bit and made a little progress.

And then I watched a movie and went to sleep…

And when I woke up this am, ready to go do this thing, I decided to start clean and do a fresh “svn co” on the Experimental bundle before getting down to the business of writing a TextMate-theme-to-CSS transformation (XSLT) and wrapping that in a TextMate command and mashing it up with the “View Document as HTML” genetic material. When lo I noticed in the Experimental/Commands a new entry: “Create HTML from Document / Selection”.

So I ran it.

Up popped a new editor window containing an HTML document with loads of delicious CSS and the target document rendered in the body all formatted nice w/ spans w/ class attrs.

I hit command-B to render that file in the browser and pow! Up popped a Firefox window that looked very much like the original TextMate window! The layout was great. The colors perfect. The font was a little off, but hey, that can be tweaked.

So what elf was responsible for delivering this overnight gift? A bit of poking around on ##textmate revealed it was a certain Brad Choate had contributed this blessed addition. Now I’m off to plumb the sublime depths of his implementation.

About these ads
This entry was posted in TextMate. Bookmark the permalink.

2 Responses to TextMate Renders Styled HTML Now

  1. You’re welcome!

    Alan recently added a feature that exports all the scope information necessary to do it. And, it was a good way to learn some Ruby too.

  2. Pingback: Bill Burcham’s memeRocket » Sample of TextMate HTML Rendering

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s