<?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>Ellis Web Development &#187; javascript</title>
	<atom:link href="http://ellisweb.net/category/code/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://ellisweb.net</link>
	<description>Thoughts &#38; Articles on ASP.net, C#, Software Development and Technology by Yaakov Ellis</description>
	<lastBuildDate>Mon, 07 May 2012 07:45:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Using SyntaxHighlighter to Format Code in WordPress</title>
		<link>http://ellisweb.net/2008/08/using-syntaxhighlighter-to-format-code-in-wordpress/</link>
		<comments>http://ellisweb.net/2008/08/using-syntaxhighlighter-to-format-code-in-wordpress/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 08:04:15 +0000</pubDate>
		<dc:creator>Yaakov Ellis</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[syntaxhighlighter]]></category>

		<guid isPermaLink="false">http://ellisweb.net/?p=228</guid>
		<description><![CDATA[Based on a question in the StackOverflow beta site, I did some quick research into what are the best ways to perform syntax highlighting on code that is posted on blogs. Among the methods that were suggested (by myself or others): Hack together your own display logic to format it … <a href="http://ellisweb.net/2008/08/using-syntaxhighlighter-to-format-code-in-wordpress/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>Based on a <a href="http://beta.stackoverflow.com/questions/9051/what-is-best-blogging-host-for-programmerscode-formatting">question</a> in the StackOverflow beta site, I did some quick research into what are the best ways to perform syntax highlighting on code that is posted on blogs. Among the methods that were suggested (by myself or others):</p>
<ol>
<li>Hack together your own display logic to format it as you see fit</li>
<li>Use the <a href="http://code.google.com/p/syntaxhighlighter/">SyntaxHighlighter</a> JavaScript library</li>
<li>Use <a href="http://windowslivewriter.spaces.live.com/">Windows Live Writer</a> with the <a href="http://gallery.live.com/liveItemDetail.aspx?li=1f57bd9b-a692-4593-9e9e-e2962d9c0eee&amp;bt=9&amp;pl=8">Insert Code</a> plugin (I discuss that <a href="http://ellisweb.net/2007/11/trying-out-windows-live-writer/">here</a>)</li>
<li>For WordPress, use the <a href="http://wordpress.org/extend/plugins/wp-syntax/">WP-Syntax</a> plugin</li>
</ol>
<p>Coincidentally, I had heard Scott Hanselman talking about how he does code formatting just a couple of days ago, in <a href="http://hanselminutes.com/default.aspx?showID=143">Hanselminutes #125</a>, where he described how he posted code on his blog by putting it inside &lt;pre&gt;&lt;/pre&gt; tags, adding specific name and class attributes, and letting some JavaScript library do the formatting work. So I went to his blog, opened up a post with some code, and found my way to the <a href="http://code.google.com/p/syntaxhighlighter/">SyntaxHighlighter</a> JavaScript library. This is a very nifty library that handles formatting very nicely for a number of popular programming and scripting languages, and seemed to have a very easy implementation. So I decided to implement it for formatting code on my site.<br />
<span id="more-228"></span></p>
<p><strong>Installing SyntaxHighlighter</strong></p>
<p>The basic steps that you have to follow are:</p>
<ol>
<li>Download the <a href="http://code.google.com/p/syntaxhighlighter/downloads/list">files</a></li>
<li>Upload the core JavaScript files, any JavaScript files related to languages that you would want to format, the swf and css files to somewhere on your server</li>
<li>Add references in your code to the different files</li>
</ol>
<p>A very good and more detailed guide on how you can do this with your template can be found in this <a href="http://fahdshariff.blogspot.com/2008/07/syntax-highlighting-code-in-webpages.html">blog post</a> by Fahd Sharif.</p>
<p><strong>Displaying Code</strong></p>
<p>Once you have the script, swf and css references integrated with your theme, you can post code using the following convention:</p>
<pre class="html" name="code">&lt;pre name="code" class="langName"&gt;
Type your code here
&lt;/pre&gt;</pre>
<p>If you are doing this in WordPress, you will need to use the HTML editor to insert this. Language name reference is <a href="http://code.google.com/p/syntaxhighlighter/wiki/Languages">here</a>.</p>
<p>Here is what is looks like in action:</p>
<pre class="c#" name="code">public static class StringExtension {
  // Extension method to return first letter of a string
  public static string GetFirstLetter(this string str) {
    string val = (str.Length &gt; 0) ? str.SubString(0,1) : "";
    return val;
  }
}</pre>
<p><strong>Fixing TinyMCE</strong></p>
<p>After I first got this implemented in my theme, I had some problems getting it to work on actual blog posts. I would go to HTML mode in the editor, put in the &lt;pre name=&#8221;code&#8221; class=&#8221;lang&#8221;&gt;&#8230;&lt;/pre&gt; syntax, go back to the Visual editor and finish my post, preview it, and no formatting would be applied. After checking the HTML source being output, I noticed that the <em>name=&#8221;code&#8221; </em>attribute of the <em>pre </em>tag was not being output. After some more investigation, I discovered that this attribute was being stripped by the TinyMCE editor when I switched from HTML to Visual editing modes.</p>
<p>It turns out that TinyMCE has its own built-in HTML validation that it employs when text is loaded into the Visual editor. Included in this is the ability to strip out attributes that are for whatever reason not &#8220;approved&#8221;. Tag:Name seems to be one of those.</p>
<p>One potential workaround would be to only use the HTML editor. Though I could do this, I like the Visual editor better when writing.</p>
<p>The alternative is to change the list of approved attributes for the <em>pre</em> tag so that <em>name</em> will no longer be stripped. After researching this a bit (references: <a href="http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/extended_valid_elements">1</a>, <a href="http://wordpress.org/support/topic/180502?replies=2#post-775393">2</a>, <a href="http://wordpress.org/support/topic/156276?replies=17#post-774445">3</a>), I did the following:</p>
<ol>
<li>Open up /wp-includes/js/tinymce/tiny_mce_config.php</li>
<li>Go to approximately line 298</li>
<li>Make the following edit (what you are doing here is giving tinyMCE an explicit list of attributes that are acceptable for the <em>pre</em> tag):</li>
</ol>
<pre class="php:firstline[298]" name="code">// Original: $content .= $ext_plugins . 'tinyMCE.init({' . $mce_options . '});';
$content .= $ext_plugins . 'tinyMCE.init({extended_valid_elements : "pre[id|class|title|style|dir|lang|name|onclick|onkeypress]",' . $mce_options . '});';</pre>
<ol>
<li>Upload the new file</li>
<li>Clear your browser cache</li>
<li>Delete the /wp-content/uploads/js folder from the server</li>
<li>Do a hard-refresh of your editor page in WordPress</li>
</ol>
<p>You should now be able to toggle back and forth between HTML and Visual editor modes in WordPress without losing the pre:name attribute necessary for SyntaxHighlighter to work. You will have to repeat this whenever you upgrade WordPress.</p>
<p><strong>Why Not Just Use the Plugin</strong></p>
<p>WordPress junkies at this point are muttering to themselves: why go to all this trouble? There is already a <a href="http://wordpress.org/extend/plugins/syntaxhighlighter/">plugin</a> that implements SyntaxHighlighter functionality and spares you all of this hard work. Here are the reasons why I chose to do this the hard way:</p>
<ol>
<li>The plugin ditches the &lt;pre&gt; syntax for a custom syntax that looks like this: [sourcecode language="lang"]CODE GOES HERE[/sourcecode]. While this eliminates the pre:name stripping issue that I mentioned before, it introduces something that in my opinion is much worse: tinyMCE now gets rid of any spatial formatting that you are using. I like to indent my code when necessary. If I am typing in the <em>pre</em> tag, tinyMCE respects all of my spacing, and does not strip any of it out (that is the whole purpose of <a href="http://www.w3schools.com/TAGS/tag_pre.asp"><em>pre</em></a>. Thus, I can save all of my indenting and spacing without any difficulties. If you are using a custom bracketed tag like the plugin does, tinyMCE strips a good deal of indenting and spacing, leaving code that just looks ugly.</li>
<li>The aforementioned code formatting issues carry over to the RSS feed as well. This way just works better.</li>
<li>The plugin includes all language JavaScript files. I don&#8217;t need to print Ruby code right now &#8211; why should I have to include the JS for it with my page?</li>
<li>Doing the implementation yourself gives greater flexibility in terms of using the <a href="http://code.google.com/p/syntaxhighlighter/w/list">different configuration options</a> that are available with SyntaxHighlighter.</li>
<li>It is more fun this way</li>
</ol>
<p><strong>Update:</strong> Engfer <a href="http://www.engfers.com/2008/10/16/how-to-allow-stripped-element-attributes-in-wordpress-tinymce-editor/">lambasts me</a> for editing wordpress core files that will be overwritten whenever wordpress is upgraded. Instead, he created a wordpress plugin that will allow you to override and define the allowable attributes for any elements parsed by TinyMCE. It is available for download <a href="http://www.engfers.com/plugins/tinymce-valid-elements/">here</a> and is definitely a better way to go than manually editing files. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://ellisweb.net/2008/08/using-syntaxhighlighter-to-format-code-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Google Finance Firefox Quicksearch</title>
		<link>http://ellisweb.net/2006/03/google-finance-firefox-quicksearch/</link>
		<comments>http://ellisweb.net/2006/03/google-finance-firefox-quicksearch/#comments</comments>
		<pubDate>Thu, 23 Mar 2006 21:07:56 +0000</pubDate>
		<dc:creator>Yaakov Ellis</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[finance]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[Stocks]]></category>

		<guid isPermaLink="false">http://www.ellisweb.net/2006/03/google-finance-firefox-quicksearch/</guid>
		<description><![CDATA[Want to have a quicksearch link to Google Finance (just entered Beta) in your Firefox Quicksearch? Download this file (googlefinance.zip), unzip the files (not the readme.txt) into your C:\Program Files\Mozilla Firefox\searchplugins directory, restart Firefox and go. Happy Hunting!]]></description>
			<content:encoded><![CDATA[<p>Want to have a quicksearch link to <a href="http://finance.google.com">Google Finance</a> (<a href="http://googleblog.blogspot.com/2006/03/spring-is-season-for-love-and-data.html">just entered Beta</a>) in your Firefox Quicksearch?</p>
<p>Download this file (<a id="p70" title="Google Finance Firefox Quicksearch Plugin" href="http://ellisweb.net/files/googlefinance.zip">googlefinance.zip</a>), unzip the files (not the readme.txt) into your C:\Program Files\Mozilla Firefox\searchplugins directory, restart Firefox and go.</p>
<p>Happy Hunting!</p>
]]></content:encoded>
			<wfw:commentRss>http://ellisweb.net/2006/03/google-finance-firefox-quicksearch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preview Your Links with Unobtrusive JavaScript</title>
		<link>http://ellisweb.net/2005/08/preview_your_links_with_unobtrusive_java/</link>
		<comments>http://ellisweb.net/2005/08/preview_your_links_with_unobtrusive_java/#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>Yaakov Ellis</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[WebDev]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Nifty JavaScript from ParticleTree that appends a little image to a link if it links to a specific document or site (ie: pdf, doc, xls, amazon, etc).]]></description>
			<content:encoded><![CDATA[<p><a href="http://particletree.com/features/preview-your-links">Nifty JavaScript</a> from <a href="http://particletree.com">ParticleTree </a>that appends a little image to a link if it links to a specific document or site (ie: pdf, doc, xls, amazon, etc).</p>
]]></content:encoded>
			<wfw:commentRss>http://ellisweb.net/2005/08/preview_your_links_with_unobtrusive_java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Platypus</title>
		<link>http://ellisweb.net/2005/06/platypus/</link>
		<comments>http://ellisweb.net/2005/06/platypus/#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>Yaakov Ellis</dc:creator>
				<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Take greasemonkey to the next level with platypus. From the site: Platypus is a Firefox extension which lets you modify a Web page from your browser &#8212; &#8220;What You See Is What You Get&#8221; &#8212; and then save those changes as a Greasemonkey script so that they&#8217;ll be repeated the … <a href="http://ellisweb.net/2005/06/platypus/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>Take <a href="http://greasemonkey.mozdev.org/">greasemonkey</a> to the next level with <a href="http://platypus.mozdev.org/">platypus</a>. From the site:</p>
<blockquote><p><a href="http://platypus.mozdev.org/">Platypus</a> is a Firefox extension which lets you modify a Web page from your browser &#8212; &#8220;What You See Is What You Get&#8221; &#8212; and then save those changes as a Greasemonkey script so that they&#8217;ll be repeated the next time you visit the page. Editing pages to suit your needs is dandy &#8212; but making those changes &#8220;permanent&#8221; is the real payoff.</p>
<p>Some of the things you can do with Platypus include:</p>
<ul>
<li>Remove parts of the page you don&#8217;t wish to see.</li>
<li>Move a part of the page to a different location.</li>
<li>Change the style and format of page elements.</li>
<li>Modify all the links on the page using a regular expression.</li>
<li>Insert your own HTML code.</li>
</ul>
</blockquote>
<p>For those of us (myself included) who have not taken the time to learn <a href="http://diveintogreasemonkey.org/">how to compose a greasemonkey script</a>, here is an easy to use took that will do it for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://ellisweb.net/2005/06/platypus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cool greasemonkey scripts that I am using</title>
		<link>http://ellisweb.net/2005/05/cool_greasemonkey_scripts_that_i_am_usin/</link>
		<comments>http://ellisweb.net/2005/05/cool_greasemonkey_scripts_that_i_am_usin/#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>Yaakov Ellis</dc:creator>
				<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[greasemonkey]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[As I find start to use new ones, I&#8217;ll post them here MBTA on Google Maps (info) Autosave Gmail (info) Gmail Delete Button Click on mailto link &#8211; open Gmail Compose message Google Fool (info &#8211; you have to read this first) MSDN Language Filter (info) Also, if you want … <a href="http://ellisweb.net/2005/05/cool_greasemonkey_scripts_that_i_am_usin/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>As I find start to use new ones, I&#8217;ll post them here</p>
<ul>
<li><a href="http://maps.mojodna.net/mbta/mbta_google_maps.user.js">MBTA on Google Maps</a> (<a href="http://mojodna.net/2005/04/19/mbta-maps/">info</a>)</li>
<li><a href="http://www.cs.toronto.edu/~james/greasemonkey/gmail-autosave.user.js">Autosave Gmail</a> (<a href="http://www.cs.toronto.edu/~james/greasemonkey/gmail-autosave.html">info</a>)</li>
<li><a href="http://dunck.us/code/greasemonkey/Gmail_Smart-Delete_Button.user.js">Gmail Delete Button</a></li>
<li><a href="http://youngpup.net/userscripts/gmailto.user.js">Click on mailto link &#8211; open Gmail Compose message</a></li>
<li><a href="http://www.krazydad.com/greasemonkey/googlefool.user.js">Google Fool</a> (<a href="http://www.krazydad.com/greasemonkey/googlefool.php">info &#8211; you have to read this first</a>)</li>
<li><a href="http://blog.monstuff.com/archives/images/MSDNLanguageFilter.user.js">MSDN Language Filter</a> (<a href="http://blog.monstuff.com/archives/000240.html">info</a>)</li>
</ul>
<p>Also, if you want to know more about developing on greasemonkey, then <a href="http://diveintogreasemonkey.org/">dive into greasemonkey (.org)</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ellisweb.net/2005/05/cool_greasemonkey_scripts_that_i_am_usin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add persistent searches to Gmail with greasemonkey</title>
		<link>http://ellisweb.net/2005/05/add_persisten_searches_to_gmail_with_gre/</link>
		<comments>http://ellisweb.net/2005/05/add_persisten_searches_to_gmail_with_gre/#comments</comments>
		<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>
		<dc:creator>Yaakov Ellis</dc:creator>
				<category><![CDATA[Cool Stuff]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[See this blog post from persistent.info. It is a greasemonkey script that adds the ability to define and save persisten searches. Saved searches show up in a little orange box along the left side of the screen. Uses cookies to track the &#8220;contents&#8221; of the searches and might need some … <a href="http://ellisweb.net/2005/05/add_persisten_searches_to_gmail_with_gre/"> Continue reading <span class="meta-nav">&#8594; </span></a>]]></description>
			<content:encoded><![CDATA[<p>See <a href="http://persistent.info/archives/2005/03/01/gmail-searches" target="_blank">this blog post</a> from <a href="http://persistent.info/">persistent.info</a>. It is a <a href="http://greasemonkey.mozdev.org/">greasemonkey</a> script that adds the ability to define and save persisten searches. Saved searches show up in a little orange box along the left side of the screen.</p>
<p><img src="http://ellisweb.net/techblog/media/gmailSearch.gif" border="0" alt="Gmail greasemonkey persisten searches" /></p>
<p>Uses cookies to track the &#8220;contents&#8221; of the searches and might need some page refreshing (I had to log out and log back in to get it to work). Very cool. See <a href="http://dunck.us/collab/GreaseMonkeyUserScripts#head-2b681c0a24baff8899d7163cc7f805c75e1f44e4">here</a> for other <a href="http://www.google.com">Google</a> and <a href="http://www.gmail.com">Gmail</a> greasemonkey scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://ellisweb.net/2005/05/add_persisten_searches_to_gmail_with_gre/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

