TextMate News

Anything vaguely related to TextMate and macOS.

Text Transformations Screencast

A month ago I asked for suggestions for an Obfuscate Selection feature in the HTML bundle. This was prompted by the desire of providing an easy out-of-the-box way for people to quickly obfuscate an email address when writing HTML.

At the same time I also posted two email addresses, one in the clear, and another one being entity-encoded (both wrapped in a mailto:-link). The plain text email address has since received 286 emails (not surprisingly) and the entity-encoded one received 1 email. So entity-encoding your email address is (presently) effective.

The solution I chose to include with TextMate does however involve JavaScript (source). There was a lot of good suggestions, a popular one being Enkoder. My goal was however to keep the generated JavaScript to an absolute minimum, and offer a simple way to de-obfuscate the code (incase you later want to edit the obfuscated code).

I have chosen to ROT 13 encode the text and have a JavaScript decode and print the string. Decoding ROT 13 is trivial, and this approach seems to be the one which requires the least amount of JavaScript code.

I took the opportunity to record a screencast demoing the feature. In the process I managed to demonstrate half a dozen other features, so it should be interesting even if you do not need this obfuscation command.

The screencast is recorded with r1292 of TextMate which is the first release which bundles the new HTML (email) obfuscation command. I accidentally said “control” instead of “command” for a few key strokes, but I show the key equivalents in the menu, so hopefully there should be no confusion.

This is the first screencast which is optimized for “fast play” meaning you can view it as it is being downloaded. For some reason this was not the default for me when I exported from QuickTime. This is also the first time I put a blog post in the Screencast category (thanks to Brett Terpstra’s category command for the blogging bundle :) ) — he is also to thank for the Wikipedia link (to ROT 13) which comes with a nice title so you can hover the link to learn where it is going. Something I have yet to integrate into one of the default bundles. See the Search and Hyperlink Screencast for what this is about.

categories Screencasts

15 Comments

I can’t seem to get past a certain point in the screencast…

David Reynolds: Try download the file, it should be 13.26 MB and lasts about 10 minutes.

Thanks Allan, got the file now - great podcast as ever.

Keep up the good work!

Clearly I meant screencast….

Hi Allan, I´m probably wrong, but shouldn´t the “select current scope” grab the end tag? I tried to use the Encrypt Line with the select current scope on a e-mail address in a table cell, but TextMate didn´t select the which lead to a validation error. What I´m doing wrong?

Bruno: Select Scope selects the current unit, as defined by the language grammar.

Since the language grammar marks up a tag as a unit, but not a tag pair, it will not select the tag pair.

One could change the language grammar to also mark up the latter, but we probably won’t do that before 2.0, where some new features in the system will make it more beneficial to do it.

As for the validity of the page, when you use document.write it isn’t possible for the validator to get a true picture of how the page will look after the scripts have been evaluated. However, including the end tag in the script would make the page appear valid, contrary to not including the end tag, so that would definitely be a good idea to do in general.

Thanks Allan, Great screencast!

For some reason I get form-encoded data back when I use “URL Escape Selection”. For example:

Hi Allan,

This is some feedback for your site.

becomes:

Hi+Allan%2C%0A++++%0A++++This+is+some+feedback+for+your+site.

Is this just a weird setting? or something else? Thanks and as always, I learned a ton from the screencast :) (thank goodness for pause buttons)

Stephen Caudill: I recently fixed/changed that. You probably just need to update to Cutting Edge (see System Preferences → Software Update)

Allan, i think you have forgot the point with ROT13. The smart thing in ROT13 is that the kryptation, also works as a decoder.

18 October 2006

by Anonymous

Allan,

I’m running 1292 :\ I’ve been using “Cutting-Edge” for quite some time… otherwise, I wouldn’t be able to “Encrypt Selection (ROT 13)” and have it create that JavaScript and whatnot, eh?

Thanks again.

Henrik: The reason there are two ROT 13 actions is that one does a normal ROT 13 (the one in the Mail bundle), while the other also adds the <script> tag and JavaScript code (the one in the HTML bundle).

Anonymous: You may have a locally modified URL Escape then. Try look in the HTML bundle at ~/Library/Application Support/TextMate/Bundles.

Henrik (continued): And the one in the HTML bundle, which adds the JavaScript, is of course not reversible by the same command. But as I show in the screencast, the string with the actual HTML can easily be decoded, edited, and encoded again (I didn’t show the last step, but that was my point be decoding just the string part).

Really nice screencast, Allan. I learned a bundle!

Thanks for the screencast on this topic. I was able to obfuscate my email, my only issue comes in when validating the page in strict html. I get “end tag for element “A” which is not open” when validating. Am I doing something wrong - sample in my website?

Alexander: Bruno asked the same to which I replied :)