<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joe Maller &#187; JavaScript</title>
	<atom:link href="http://joemaller.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://joemaller.com</link>
	<description>.com</description>
	<lastBuildDate>Tue, 15 May 2012 03:40:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Toodledo linkfixer bookmarklets</title>
		<link>http://joemaller.com/1685/toodledo-linkfixer-bookmarklets/</link>
		<comments>http://joemaller.com/1685/toodledo-linkfixer-bookmarklets/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 05:55:07 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[misc.]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[todo]]></category>
		<category><![CDATA[Toodledo]]></category>

		<guid isPermaLink="false">http://joemaller.com/?p=1685</guid>
		<description><![CDATA[I&#8217;m a very happy user of Toodledo, it&#8217;s almost always open on my computer and syncs with Appigo Todo on my iPhone. I recently suggested that links in task item notes should open in new windows, or at least they should add the option to choose that behavior. Toodledo responded that they originally had this, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a very happy user of <a href="http://www.toodledo.com/index.php?ref=td48a0594c33847">Toodledo</a>, it&#8217;s almost always open on my computer and syncs with <a href="http://itunes.apple.com/us/app/todo/id282778557?mt=8">Appigo Todo</a> on my iPhone. </p>
<p>I recently suggested that links in task item notes should open in new windows, or at least they should add the option to choose that behavior. Toodledo responded that they originally had this, but some people wanted every link to open in a new window, while others wanted subsequent links to recycle the new window. With both camps complaining, they just removed targets from the links altogether.</p>
<p>Anyway, here are two bookmarklets for Toodledo. Clicking these will modify the task note links to open in a different window.</p>
<ul>
<li>Open each task note link in a new window: <a href="javascript:void($$(%27.note%20a%27).each(function(i){i[%27target%27]=%27_blank%27}))">&#x2714;</a></li>
<li>Open task note links in a reusable window: <a href="javascript:void($$(%27.note%20a%27).each(function(i){i[%27target%27]=%27toodledo_out%27}))">&#x2714;°</a></li>
</ul>
<p><strong>Note:</strong> You will need to click this each time you load the page, or add a new item. Yes it&#8217;s clumsy, but this is only a band-aid until Toodledo adds the feature.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/1685/toodledo-linkfixer-bookmarklets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NYTimes search bubbles begone!</title>
		<link>http://joemaller.com/1395/nytimes-search-bubbles-begone/</link>
		<comments>http://joemaller.com/1395/nytimes-search-bubbles-begone/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 04:32:15 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[misc.]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[New York Times]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://joemaller.com/?p=1395</guid>
		<description><![CDATA[Those little search bubbles that popup on the New York Times website whenever you select text really annoy me. Clicking this bookmarklet on any NYTimes page will prevent them from appearing: NYTfix This is a 2-minute solution, there&#8217;s no domain checking or anything, all it does is remove existing bubbles then cancel the document&#8217;s mouseup [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://joemaller.com/wordpress/wp-content/uploads/2009/06/nytimes-search-balloons-1.png" alt="nytimes-search-balloons-1" title="nytimes-search-balloons-1" width="462" height="101" class="alignnone size-full wp-image-1397" /></p>
<p>Those little search bubbles that popup on the New York Times website whenever you select text really annoy me. Clicking this bookmarklet on any NYTimes page will prevent them from appearing:</p>
<p><a href="javascript:(function(){d=document;e=d.getElementById('nytd_selection_button');if(e){e.remove()};d.stopObserving('mouseup')})()">NYTfix</a></p>
<p>This is a 2-minute solution, there&#8217;s no domain checking or anything, all it does is remove existing bubbles then cancel the document&#8217;s mouseup observer, which the NYTimes site uses to trigger the search balloons.  The bookmarklet was very quickly checked in Safari, Firefox and IE8, NYTimes text selection doesn&#8217;t work at all for me in IE6 or IE7.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/1395/nytimes-search-bubbles-begone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iTransmogrify update</title>
		<link>http://joemaller.com/879/itransmogrify-update/</link>
		<comments>http://joemaller.com/879/itransmogrify-update/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 21:17:27 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[itransmogrify]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://joemaller.com/2008/01/23/itransmogrify-update/</guid>
		<description><![CDATA[The main iTransmogrify! script has been updated with a bunch of new functionality: YouTube.com pages are now supported (see notes) Daily Motion videos are supported for new-style urls (see notes) Kink.fm player and listings page are now supported Sideload.com play links are now supported WordPress Blogs using Viper Video QuickTags are supported for YouTube All [...]]]></description>
			<content:encoded><![CDATA[<p>The main <a href="http://itransmogrify.googlecode.com">iTransmogrify!</a> script has been updated with a bunch of new functionality:</p>
<ul>
<li>YouTube.com pages are now supported (see <a href="#notes">notes</a>)</li>
<li>Daily Motion videos are supported for new-style urls (see <a href="#notes">notes</a>)</li>
<li><a href="http://www.kink.fm">Kink.fm</a> player and listings page are now supported</li>
<li><a href="http://www.sideload.com">Sideload.com</a> play links are now supported</li>
<li>WordPress Blogs using <a href="http://wordpress.org/extend/plugins/vipers-video-quicktags">Viper Video QuickTags</a> are supported for YouTube</li>
<li>All media links now open into new windows, so you won&#8217;t have to re-transmogrify a page with several media files after playing one. Note that this is dependent on the iPhone, sometimes it will blank other windows)</li>
<li>Some content in iframes will now be converted.</li>
<li>MotionBox, Viddler and Vimeo embedded videos, while not supporting iPod/iPhone alternate content, now link to their respective detail pages.</li>
</ul>
<p>The main bookmarklet code was updated. This was necessary to workaround a <a href="http://joemaller.com/2008/01/22/itransmogrify-update-ready-but/">frustrating oversight with Google Code hosting</a>. Everyone will need to update their bookmarklet, in the future all updates will be automatic.</p>
<p>This has turned out to be far bigger than I ever imagined. Thank you to everyone for the links, feedback, compliments and ideas.</p>
<h3 id="known_issues">Known issues</h3>
<p>LiveJournal pages redefine a bunch of core JavaScript functionality, breaking all kinds of stuff including jQuery. Additionally, they&#8217;re serving media in an iframe from a different domain, meaning JavaScript couldn&#8217;t access the frame even if they hadn&#8217;t broken it.</p>
<h3 id="notes">Notes</h3>
<p><strong>YouTube Internal pages </strong ><br />
Because of a strange iPhone quirk, these links all need to go through the Google redirector, otherwise they bounce back to uk.youtube.com instead of playing.</p>
<p><strong>DailyMotion</strong><br />
DailyMotion videos using new-style urls, which are usually about six digits long, work correctly. Videos using the old-style alphanumeric ID do not work yet. I&#8217;m probably just going to resort to building a simple web-service to grab those. Additionally, there is no way to programatically access the mp4 alternate content url, so I just linked to their iPhone pages. I&#8217;d prefer embedding QuickTime directly, but it&#8217;s just not possible yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/879/itransmogrify-update/feed/</wfw:commentRss>
		<slash:comments>87</slash:comments>
		</item>
		<item>
		<title>iTransmogrify!</title>
		<link>http://joemaller.com/873/itransmogrify/</link>
		<comments>http://joemaller.com/873/itransmogrify/#comments</comments>
		<pubDate>Sat, 12 Jan 2008 05:43:10 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[itransmogrify]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://joemaller.com/2008/01/12/itransmogrify/</guid>
		<description><![CDATA[iTransmogrify! is a bookmarklet for iPhone which transforms embedded Flash content into direct links to natively supported formats. That means YouTube videos and MP3s can now be played from the iPhone&#8217;s Safari web browser with just a few clicks. Seeing it work is the best explanation: On an iPhone? Try it now: iTransmogrify! (works in [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right"><script type="text/javascript">digg_url='http://digg.com/apple/iTransmogrify_embedded_Flash_converter_for_iPhone';</script><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div>
<p>iTransmogrify! is a bookmarklet for iPhone which transforms embedded Flash content into direct links to natively supported formats. That means YouTube videos and MP3s can now be played from the iPhone&#8217;s Safari web browser with just a few clicks. </p>
<p>Seeing it work is the best explanation:</p>
<p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/djkYrLoZBb0&#038;rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/djkYrLoZBb0&#038;rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></p>
<p>On an iPhone? Try it now: <strong><a href="javascript:if%28typeof%28iTransmogrify%29%3D%3D%27undefined%27%29%7Bvar%20s%3Ddocument.createElement%28%27script%27%29%3Bs.src%3D%27http%3A%2F%2Fjoemaller.com%2FiTransmogrify-latest.js%3Fq%3D%27%2B%28new%20Date%29.getTime%28%29%3Bdocument.getElementsByTagName%28%27head%27%29%5B0%5D.appendChild%28s%29%7Dvoid%280%29">iTransmogrify!</a></strong> (works in Safari and Firefox too)</p>
<blockquote><p>Sorry, it took YouTube a long time to re-encode that for iPhone, here&#8217;s a baby panda:</p></blockquote>
<p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/ysTmUTQ5wZE&#038;rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ysTmUTQ5wZE&#038;rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object></p>
<h3>Installation</h3>
<p>To install the bookmarklet, just drag the link to your Safari or Firefox Bookmarks, IE users should right click and choose &#8220;Add To Favorites&#8230;&#8221; After adding the link, sync your iPhone. </p>
<p>Grab it now: <b><a href="javascript:if%28typeof%28iTransmogrify%29%3D%3D%27undefined%27%29%7Bvar%20s%3Ddocument.createElement%28%27script%27%29%3Bs.src%3D%27http%3A%2F%2Fjoemaller.com%2FiTransmogrify-latest.js%3Fq%3D%27%2B%28new%20Date%29.getTime%28%29%3Bdocument.getElementsByTagName%28%27head%27%29%5B0%5D.appendChild%28s%29%7Dvoid%280%29">iTransmogrify!</a></b></p>
<p>You can also <a href="http://joemaller.com/___?javascript:if%28typeof%28iTransmogrify%29%3D%3D%27undefined%27%29%7Bvar%20s%3Ddocument.createElement%28%27script%27%29%3Bs.src%3D%27http%3A%2F%2Fjoemaller.com%2FiTransmogrify-latest.js%3Fq%3D%27%2B%28new%20Date%29.getTime%28%29%3Bdocument.getElementsByTagName%28%27head%27%29%5B0%5D.appendChild%28s%29%7Dvoid%280%29">add iTransmogrify from your iPhone</a>!</p>
<p>More information, source code and bug-tracking is available on the <a href="http://itransmogrify.googlecode.com/">iTransmogrify Google Code page</a>.</p>
<ul>Currently supported content:</p>
<li>Default YouTube Object-Embed code</li>
<li>YouTube bare Embed</li>
<li>YouTube bare Object</li>
<li>A variety of Flash-based MP3 players including <a href="http://digg.com/podcasts">Digg Podcasts</a></li>
</ul>
<p><em>Lots more added: <a href='http://joemaller.com/2008/01/23/itransmogrify-update/'>iTransmogrify update</a></em></p>
<p>Support for other embedded media sites will be added as I figure them out. Please report broken sites or suggest additional sources using <a href="http://code.google.com/p/itransmogrify/issues/list">Google Code issue tracker</a>.</p>
<h3>Acknowledgements</h3>
<p>The first robust, script insertion bookmarklets I ever saw was Sumaato&#8217;s original <a href="http://sumaato.typolis.net/stories/4323/">Flickr GeoCoding bookmarklet</a>.</p>
<p>Other sites also deserving links:
<ul>
<li>Jan Wolter&#8217;s <a href='http://unixpapa.com/js/dyna.html'>Dynamic Script Loading</a></li>
<li>Andrew Sumin&#8217;s <a href="http://jsx.ru/Texts/ModulesInJS/indexeng.html">Modularity in JavaScript</a></li>
<li>Mike West&#8217;s <a href='http://www.digital-web.com/articles/scope_in_javascript'>Scope in JavaScript</a> was the refresher I needed to resolve one especially annoying object-scope bug.</li>
</ul>
<p>iPhone graphic reference: </p>
<ul>
<li><a href='http://www.hackthatphone.com/112/iphone_graphics_locations.html'>iPhone Graphics locations</a></li>
<li><a href='http://www.flickr.com/photos/34818713@N00/sets/72157601845495751/'>Huge iPhone icons</a></li>
</ul>
<p>Also, John Resig&#8217;s amazing <a href="http://jquery.com/">jQuery JavaScript library</a>. This project was the excuse I&#8217;d been looking for to finally dig in and learn it. </p>
<p>The name came from a late-night brainstorming chat with <a href="http://movielibrary.lynda.com/authors/author/?aid=1">Bruce</a> and was far more fun and interesting than the utilitarian ones I was thinking of. So thank you Bruce, and of course,  Bill Watterson.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/873/itransmogrify/feed/</wfw:commentRss>
		<slash:comments>306</slash:comments>
		</item>
		<item>
		<title>SlickSpeed</title>
		<link>http://joemaller.com/759/slickspeed/</link>
		<comments>http://joemaller.com/759/slickspeed/#comments</comments>
		<pubDate>Mon, 03 Sep 2007 20:46:09 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://joemaller.com/2007/09/03/slickspeed/</guid>
		<description><![CDATA[Valerio Proietti, author of the MooTools JavaScript framework wrote a benchmarking tool called SlickSpeed. This tool runs a number of JavaScript libraries against a suite of CSS selector tests. The source is available from Google Code, I downloaded a copy so I could run tests against the most recent versions of Prototype, MooTools and JQuery [...]]]></description>
			<content:encoded><![CDATA[<p>Valerio Proietti, author of the <a href="http://mootools.net">MooTools JavaScript framework</a> wrote a benchmarking tool called <a href="http://mootools.net/slickspeed/" title="SlickSpeed Selectors Test">SlickSpeed</a>. This tool runs a number of JavaScript libraries against a suite of CSS selector tests. The source is available from <a href="http://slickspeed.googlecode.com/svn/trunk" title="SlickSpeed on Google Code">Google Code</a>, I downloaded a copy so I could run tests against the most recent versions of <a href="http://www.prototypejs.org/">Prototype</a>, <a href="http://mootools.net">MooTools</a> and <a href="http://jquery.com/">JQuery</a> against one another.</p>
<style type="text/css" media="screen">
	table#js {font-size: 0.85em;}
	table#js tr {text-align: right;}
	table#js th {width: 5em;}
	table#js td {background: #eee; padding: 3px;}
	table#js tr.odd td {background: #fcfcfc;}
</style>
<table id='js'>
<thead>
<tr style='text-align: right;'>
<th style='width: auto;'></th>
<th>prototype <br />1.5.1.1</th>
<th>jQuery <br />1.1.4</th>
<th>MooTools <br />r873 (svn)</th>
<th>MooTools <br />v1.2dev</th>
</tr>
</thead>
<tr class="odd">
<td style='text-align: left'><strong>Firefox 2.0.0.6</strong><br /> (Gecko/20070725, Mac)</td>
<td>210</td>
<td>454</td>
<td>218</td>
<td>243*</td>
</tr>
<tr>
<td style='text-align: left'><strong>Firefox 2.0.0.6</strong><br /> (Gecko/20070725, Windows XP)</td>
<td>177</td>
<td>339</td>
<td>180</td>
<td>164*</td>
</tr>
<tr class="odd">
<td style='text-align: left'><strong>Safari 2.0.4</strong><br /> (419.3)</td>
<td>1385**</td>
<td>372</td>
<td>837</td>
<td>727*</td>
</tr>
<tr>
<td style='text-align: left'><strong>Webkit</strong><br /> (AppleWebKit/523.5)</td>
<td>120</td>
<td>185</td>
<td>154</td>
<td>149</td>
</tr>
<tr class="odd">
<td style='text-align: left'><strong>iPhone</strong><br /> (AppleWebkit/420+ Version 3.0 Mobile/1C28)</td>
<td>35975</td>
<td>13224</td>
<td>25594</td>
<td>22811</td>
</tr>
<tr>
<td style='text-align: left'><strong>Microsoft Internet Explorer 7</strong><br /> (Windows XP)</td>
<td>969**</td>
<td>421</td>
<td>867</td>
<td>811*</td>
</tr>
</table>
<p>Results are in milliseconds (ms), smaller numbers are better. Asterisks indicate errors returned during the test.</p>
<p>All tests were served and run from a MacBook Pro 2.16 GHz Core Duo, iPhone tests were run on a 1st Generation 8 GB model. Firebug was disabled for the Firefox tests.</p>
<h3>A few things which are immediately apparent:</h3>
<p>MooTools is a solid performer. Not the fastest and not the slowest, but Valerio Proietti&#8217;s code is consistently impressive.</p>
<p>JQuery has gotten significantly faster in the most recent version, John Resig is also writing really good code.</p>
<p>At least as applies to Valerio&#8217;s set of selector tests, JQuery is the fastest library on iPhone, nearly twice as fast as MooTools and almost three times faster than Prototype. Joe Hewitt&#8217;s <a href='http://code.google.com/p/iui/'>iUI project</a> uses Prototype, how much would iPhone performance benefit from switching to JQuery?</p>
<p>The Webkit team is writing some seriously crazy speed optimizations. If they could just get Safari to stop leaking memory we&#8217;d be all set (don&#8217;t go looking all smug Firefox, you&#8217;re standing in a puddle). As it stands now, when Leopard ships Safari will have the fastest JavaScript engine available. The difference between jQuery and Prototype on Webkit and iPhone is surprising, iPhone runs JQuery nearly three times faster than Prototype using the same browser core.</p>
<p>Firefox runs faster in virtualized Windows than it does native on the Mac. Camino (Mac native version of Mozilla/Firefox/Gecko) was slightly faster, but still not as fast as Firefox Windows.</p>
<p>I&#8217;ve got one project wrapping up soon which used MooTools and I&#8217;ve been very happy with it. Lately I&#8217;ve been reading a lot of buzz about JQuery and might be working that into another project. These tests were mostly just done to satisfy my own of curiosity.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/759/slickspeed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web Syntax Coloring</title>
		<link>http://joemaller.com/743/web-syntax-coloring/</link>
		<comments>http://joemaller.com/743/web-syntax-coloring/#comments</comments>
		<pubDate>Thu, 05 Apr 2007 06:35:12 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://joemaller.com/2007/04/05/web-syntax-coloring/</guid>
		<description><![CDATA[February 2011 Update: This post was originally published in 2007 and hasn&#8217;t aged well. For code snippet syntax coloring, I currently use Google&#8217;s Prettify script (prettify.js). The script is dynamically inserted by jQuery if there are code elements to style. Recently I&#8217;ve been experimenting with two very different methods of syntax coloring source code in [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><strong>February 2011 Update:</strong> This post was originally published in 2007 and hasn&#8217;t aged well. For code snippet syntax coloring, I currently use <a href="http://code.google.com/p/google-code-prettify/">Google&#8217;s Prettify script</a> (<a href="http://code.google.com/p/google-code-prettify/">prettify.js</a>). The script is dynamically inserted by jQuery if there are code elements to style.
</p></blockquote>
<style>/* Stylesheet generated from TextMate theme
*
* Blackboard
* 
*
*/
/* Mostly to improve view within the TextMate HTML viewer */
pre.textmate-source{margin:0;padding:0 0 0 2px;font-family:Monaco,monospace;font-size:11px;line-height:1.3em;word-wrap:break-word;white-space:pre;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-o-pre-wrap;}
pre.textmate-source.blackboard{color:#F8F8F8;background-color:#0C1021;}
pre.textmate-source .linenum{width:75px;padding:0.1em 1em 0.2em 0;color:#888;background-color:#eee;}
pre.textmate-source.blackboard span{padding-top:0.2em;padding-bottom:0.1em;}
pre.textmate-source.blackboard ::selection{background-color:#253B76;}
/* Comment */
pre.textmate-source.blackboard .comment{color:#AEAEAE;}
/* Constant */
pre.textmate-source.blackboard .constant{color:#D8FA3C;}
/* Entity */
pre.textmate-source.blackboard .entity{color:#FF6400;}
/* Keyword */
pre.textmate-source.blackboard .keyword{color:#FBDE2D;}
/* Storage */
pre.textmate-source.blackboard .storage{color:#FBDE2D;}
/* String */
pre.textmate-source.blackboard .string,pre.textmate-source.blackboard .meta_verbatim{color:#61CE3C;}
/* Support */
pre.textmate-source.blackboard .support{color:#8DA6CE;}
/* Variable */
pre.textmate-source.blackboard .variable{}
/* Invalid — Deprecated */
pre.textmate-source.blackboard .invalid_deprecated{color:#AB2A1D;font-style:italic;}
/* Invalid — Illegal */
pre.textmate-source.blackboard .invalid_illegal{color:#F8F8F8;background-color:#9D1E15;}
/* Superclass */
pre.textmate-source.blackboard .entity_other_inherited-class{color:#FF6400;font-style:italic;}
/* String interpolation */
pre.textmate-source.blackboard .string .constant_other_placeholder{color:#FF6400;}
/* meta.function-call.py */
pre.textmate-source.blackboard .meta_function-call_py{color:#BECDE6;}
/* meta.tag */
pre.textmate-source.blackboard .meta_tag,pre.textmate-source.blackboard .meta_tag .entity{color:#7F90AA;}
/* entity.name.section */
pre.textmate-source.blackboard .entity_name_section{color:#FFFFFF;}
/* OCaml variant */
pre.textmate-source.blackboard .keyword_type_variant{color:#D5E0F3;}
/* OCaml operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol{color:#F8F8F8;}
/* OCaml infix operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol_infix{color:#8DA6CE;}
/* OCaml prefix operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol_prefix{color:#8DA6CE;}
/* OCaml f-p infix operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol_infix_floating-point{text-decoration:underline;}
/* OCaml f-p prefix operator */
pre.textmate-source.blackboard .source_ocaml .keyword_operator_symbol_prefix_floating-point{text-decoration:underline;}
/* OCaml f-p constant */
pre.textmate-source.blackboard .source_ocaml .constant_numeric_floating-point{text-decoration:underline;}
/* LaTeX environment */
pre.textmate-source.blackboard .text_tex_latex .meta_function_environment{background-color:rgba(255,255,255,0.03);}
/* LaTeX environment (nested) */
pre.textmate-source.blackboard .text_tex_latex .meta_function_environment .meta_function_environment{background-color:rgba(122,150,250,0.03);}
/* Latex support */
pre.textmate-source.blackboard .text_tex_latex .support_function{color:#FBDE2D;}
/* PList unquoted string */
pre.textmate-source.blackboard .source_plist .string_unquoted,pre.textmate-source.blackboard .source_plist .keyword_operator{color:#FFFFFF;}
</style>
<p><script src="/js/code_highlighter.js" type="text/javascript"></script><script src="/js/css.js" type="text/javascript"></script>Recently I&#8217;ve been experimenting  with two very different methods of syntax coloring source code in web pages. The first method uses a Dan Webb&#8217;s <a href="http://jquery.com/demo/code/">CodeHighlighter JavaScript library</a> to convert appropriately tagged content into syntax colored code. It&#8217;s necessarily simple, but easily extensible. As an example, here are the CSS rules I&#8217;m using to style CodeHighlighter&#8217;s conversions:</p>
<pre><code class="css">code.html span.comment         { color: #999;}
code.html span.tag             { color: #07f;}
code.html span.string         { color: #080;}
code.html span.attribute     { color: #07f;}
code.html span.doctype         { color: #07f;}

code.css span.comment          {color: #999;}
code.css span.keywords         {color: #fd2;}
code.css span.selectors        {color: #0b0;}
code.css span.properties    {color: #66f;}
code.css span.units            {color: #33c;}
code.css span.urls            {color: #4a0;}

code.javascript span.comment     { color: #999; }
code.javascript span.brackets     { color: #07f; }
code.javascript span.string     { color: #4a0; }
code.javascript span.keywords     { color: #07f; }
code.javascript span.exp         { color: #808; }
code.javascript span.global     { color: #06e; }</code></pre>
<p>The second method uses two more fantastic <a href="http://macromates.com">TextMate</a> features, <em>Create HTML From Selection</em> and <em>Create CSS from Current Theme</em>. What these two commands do is translate exactly what I&#8217;m seeing in TextMate into very precise and valid XHTML with accompanying CSS rules. The main disadvantage of this is the weight of the code, the above 721 bytes of CSS converts to nearly 36k of HTML and CSS rules. It&#8217;s a seriously heavy pile of span tags, but the cost is immediately outweighed by <a href="http://macromates.com/svn/Bundles/trunk/Bundles/">148 very specific reasons</a>. And that&#8217;s just bundles, there are <a href="http://macromates.com/wiki/Themes/UserSubmittedThemes">dozens of great themes</a> too.</p>
<p>Aaron Quint also deservingly <a href="http://www.quirkey.com/blog/2006/07/13/highlight-me-baby/">gushes over these two commands</a>.</p>
<p>What these do is convert exactly what I&#8217;m seeing in TextMate into very precise and valid XHTML. Here&#8217;s the same CSS as above translated by TextMate:</p>
<pre class="textmate-source blackboard"><span class="source source_css"></span><span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>comment      <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>999<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>tag          <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>string       <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>080<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>attribute    <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>html <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>doctype      <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>

<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>comment       <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>999<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>keywords      <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>fd2<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>selectors     <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>0b0<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>properties    <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>66f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>units         <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>33c<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>css <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>urls          <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>4a0<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span> 

<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>comment    <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>999<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>brackets   <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>string     <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>4a0<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>keywords   <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>07f<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>exp        <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>808<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
<span class="meta meta_selector meta_selector_css"></span><span class="entity entity_name entity_name_tag entity_name_tag_css">code</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>javascript <span class="entity entity_name entity_name_tag entity_name_tag_css">span</span><span class="entity entity_other entity_other_attribute-name entity_other_attribute-name_class entity_other_attribute-name_class_css"></span><span class="punctuation punctuation_definition punctuation_definition_entity punctuation_definition_entity_css">.</span>global     <span class="meta meta_property-list meta_property-list_css"></span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">{</span> <span class="meta meta_property-name meta_property-name_css"></span><span class="support support_type support_type_property-name support_type_property-name_css">color</span><span class="meta meta_property-value meta_property-value_css"></span><span class="punctuation punctuation_separator punctuation_separator_key-value punctuation_separator_key-value_css">:</span> <span class="constant constant_other constant_other_color constant_other_color_rgb-value constant_other_color_rgb-value_css"></span><span class="punctuation punctuation_definition punctuation_definition_constant punctuation_definition_constant_css">#</span>06e<span class="punctuation punctuation_terminator punctuation_terminator_rule punctuation_terminator_rule_css">;</span><span class="punctuation punctuation_section punctuation_section_property-list punctuation_section_property-list_css">}</span>
</pre>
</p>
<p>Just for the sake of comparison, below is a screenshot of how my code looks in TextMate. It&#8217;s not a perfect translation, but it&#8217;s a very good start:</p>
<p><img src='http://joemaller.com/wordpress/wp-content/uploads/2007/04/textmate-css.png' alt='Syntax Coloring CSS in TextMate' /></p>
<p>One of the purported advantages of the JavaScript method is that the source code remains unchanged. That&#8217;s sort of true, but not really. The JavaScript functions work by inserting a bunch of spans, so by the time the user sees it the main difference between JavaScript converted code and pre-processed code from TextMate is the detail (and weight) of the TextMate result. Also, any HTML would need to have entities escaped which is another step and a further degradation of the original code.</p>
<p>The main advantage then becomes convenience. A simple block of code doesn&#8217;t need to be run through TextMate (on the off-chance I&#8217;m writing somewhere else), it can be entered directly and tagged for styling without breaking focus.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/743/web-syntax-coloring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>getSelection() Workaround for Safari 1.3, 2.0 and Firefox 1.0.3</title>
		<link>http://joemaller.com/503/getselection-workaround/</link>
		<comments>http://joemaller.com/503/getselection-workaround/#comments</comments>
		<pubDate>Sun, 24 Apr 2005 05:56:20 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[safari]]></category>
		<category><![CDATA[web design]]></category>

		<guid isPermaLink="false">http://joemaller.com/2005/04/24/post503/503</guid>
		<description><![CDATA[A simple workaround for problems introduced by security-based changes to getSelection in Safari and Firefox.]]></description>
			<content:encoded><![CDATA[<p><b>update 2:</b> These workarounds also work with Safari 2.0 in Mac OS X v10.4 .<br />
<b>update:</b> There&#8217;s a simpler fix, <a href="#plusquotequote">jump to the bottom</a>.</p>
<p>Yesterday morning I noticed a change to the JavaScript/DOM getSelection() behavior in the new Safari 1.3 (in 10.3.9) and the most recent version of Firefox 1.0.3.</p>
<p>I&#8217;ve been using this method for years to pull selected text from web pages for several <a href="http://www.joemaller.com/translation_bookmarklets.shtml">of my bookmarklets</a>. The one I use most frequently generates a link from whatever text is selected. If nothing is selected, it grabs the document&#8217;s title. The change in getSelection() broke that bookmarklet, no selected text was recognized.</p>
<p>After a bit of research, I found Mozilla&#8217;s <a href='http://developer-test.mozilla.org/docs/Safely_accessing_content_DOM_from_chrome'>Safely accessing content DOM from chrome</a> page which describes the security fixes behind the modification and detailing other problems the changes had caused.  Based on <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=290777">Mozilla bug 290777</a> and this <a href="http://weblog.scifihifi.com/2005/04/18/cocoalicious-and-safari-13/">post by Buzz Anderson</a>, both browsers seem to have problems with the change. Despite those bugs, I managed to find the simple workaround as described below.</p>
<p>What Safari and Firefox now seem to be doing is creating a DOM selection object from getSelection() instead of treating it as a simple string. The result is that getSelection()  appear to be a string, but few of the string manipulation functions work without additional considerations.</p>
<p>The following examples are all intended to be tested as bookmarklets, drag them to your bookmarks bar for testing:</p>
<ul>
<li>
<a href="javascript:d=window.getSelection();alert(d);">getSelection() test 1</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d);</code></p>
<p>Works as expected in Safari 1.2.4, Safari 1.3 and Firefox 1.03, popping an alert containing the selected text. Trying to measure that returned string fails in Safari 1.3 and Firefox 1.0.3 but works in Safari 1.2.4:
</li>
<li><a href="javascript:d=window.getSelection();alert(d.length);">getSelection() test 2</a><br />
<code>javascript:d=window.getSelection();alert(d.length);</code></p>
<p>The older version of Safari returns a character count for the string of selected text. Firefox and Safari 1.3 return &#8220;undefined&#8221;. There are quite a few other problems:</li>
<li><a href="javascript:d=window.getSelection();alert(d.toString());">getSelection() test  3</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.toString());</code></p>
<p>Works in Firefox and Safari 1.2.4 but not in Safari 1.3.</li>
<li><a href="javascript:d=window.getSelection();alert(d.toString().length);">getSelection() test 4</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.toString().length);</code></p>
<p>Getting the length after toString works in Safari 1.2.4 and Firefox.</li>
</ul>
<p>Further inconsistencies between Safari 1.3 and Firefox 1.0.3:</p>
<ul>
<li><a href="javascript:d=window.getSelection();alert(d.type);">getSelection() test 5</a><br />
<code>javascript:d=window.getSelection();alert(d.type);</code></p>
<p>Returns &#8220;Range&#8221; in Safari with a selection, returns &#8220;Caret&#8221; or &#8220;None&#8221; with nothing selected. Fails with &#8220;undefined&#8221; in Firefox. (I think the <a href='http://developer-test.mozilla.org/docs/index.php?title=Working_around_the_Firefox_1.0.3_DHTML_regression&#038;redirect=no'>Firefox 1.0.3 DHTML regression bug</a> might be preventing it from working in Firefox but I didn&#8217;t try any of the recent nightly builds.)</li>
<li><a href="javascript:d=window.getSelection();alert(d.getRangeAt(0));">getSelection() test  6</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.getRangeAt(0));</code></p>
<p>Fails silently in Safari, returns selected text in Firefox. Safari dumps this into the Console log:<br />
 <code>[5956] :TypeError - Value undefined (result of expression d.getRangeAt) is not object.</code></li>
<li>
<a href="javascript:d=window.getSelection();alert(d.typeDetail);">getSelection() test  7</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.typeDetail);</code></p>
<p>Fails with &#8220;undefined&#8221; in both.</li>
</ul>
<p>There is some good news:</p>
<ul>
<li>
<a href="javascript:d=window.getSelection();alert(d.isCollapsed);">getSelection() test 8</a><br />
<code>javascript:d=window.getSelection();<br />
alert(d.isCollapsed);</code></p>
<p>Works in both Firefox and Safari 1.3; fails in Safari 1.2.4 as &#8220;undefined&#8221;. This means (finally!) there is a workaround for my problem.</li>
</ul>
<p>I was using the length property to determine whether a selection was empty or not, then fetching the title of the window if that value was 0. Knowing that length no longer works in Firefox and Safari, isCollapsed can be used as a conditional switch.</p>
<ul>
<li><a href="javascript:d=window.getSelection();d=(d.isCollapsed||d.length==0)?document.title:d;alert(d);">getSelection() Workaround</a><br />
<code>javascript:d=window.getSelection();<br />
d=(d.isCollapsed||d.length==0)?document.title:d;<br />
alert(d);</code></p>
<p>That will return any selected text or the document title if there is no selection. Tested successfully in Safari 1.2.4, Safari 1.3, Firefox 1.0.3 and presumably Safari 2.0 as well.
</li>
</ul>
<p>Line breaks were added to visible code examples because my style-sheet choked on long lines and I can&#8217;t redo the CSS right now&#8230;</p>
<p><b><a name="plusquotequote"></a>Update:</b> After working through all of the above, I realized there is a far simpler solution: <code>+''</code>. The Safari problem seems to be that string methods do not work on the returned object from getSelection(). Forcing the result into a string by concatenating with an empty string fixes all of my bookmarklets. Concat() fails because it&#8217;s a method of string, use the <code>"+"</code> joining operator and an empty string <code>''</code> instead.</p>
<ul>
<li>
<a href="javascript:d=window.getSelection()+'';d=(d.length==0)?document.title:d;alert(d);">getSelection() Faster Fix</a><br />
<code>javascript:d=window.getSelection()+'';<br />
d=(d.length==0)?document.title:d;<br />
alert(d);</code>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/503/getselection-workaround/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 3/25 queries in 0.022 seconds using disk: basic
Object Caching 543/598 objects using disk: basic

Served from: joemaller.com @ 2012-05-23 21:06:56 -->
