<?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>Matt Shelton &#187; SyntaxHighlighter</title>
	<atom:link href="http://www.mattshelton.net/tags/syntaxhighlighter/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattshelton.net</link>
	<description>scribbling geekery, things and stuff</description>
	<lastBuildDate>Thu, 09 Feb 2012 13:38:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Adding SyntaxHighlighter QuickTag Support to WordPress</title>
		<link>http://www.mattshelton.net/2009/01/13/adding-syntaxhighlighter-quicktag-support-to-wordpress/</link>
		<comments>http://www.mattshelton.net/2009/01/13/adding-syntaxhighlighter-quicktag-support-to-wordpress/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 19:44:00 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[blogging]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[SyntaxHighlighter]]></category>
		<category><![CDATA[WindowsLiveWriter]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.mattshelton.net/?p=147</guid>
		<description><![CDATA[<p>Posted in <a href="http://www.mattshelton.net/topics/blogging/" title="blogging">blogging</a><a href="http://www.mattshelton.net/topics/code/" title="code">code</a></p>Edit: The latest version of the SyntaxHighlighter plugin, called SyntaxHighlighter Evolved, now supports version 2.0 and has built-in shortcode support which is way cooler than what I did here. :-) I&#8217;ve been using SyntaxHighlighter to highlight code portions on my &#8230; <a href="http://www.mattshelton.net/2009/01/13/adding-syntaxhighlighter-quicktag-support-to-wordpress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Edit:</strong> The latest version of the <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter" title="SyntaxHighlighter - Alex Gorbatchev">SyntaxHighlighter</a> plugin, called <a href="http://wordpress.org/extend/plugins/syntaxhighlighter/" title="WordPress &#8250; SyntaxHighlighter Evolved &laquo; WordPress Plugins">SyntaxHighlighter Evolved</a>, now supports version 2.0 and has built-in shortcode support which is way cooler than what I did here. :-)<br />
<span id="more-147"></span><br />
I&#8217;ve been using <a href="http://www.mattshelton.net/2007/12/13/code-highlighting-with-googles-syntaxhighlighter/">SyntaxHighlighter</a> to highlight code portions on my site for a while. Ok, I haven&#8217;t posted in seven months, but when I <em>was</em> posting more often, I did all of the code formatting by hand, and the capabilities were about 90% of what I wanted them to be. There were a few <a href="http://code.google.com/p/syntaxhighlighter/wiki/Brushes">brushes</a> that didn&#8217;t quite work right &#8212; (The perl brush, for instance, replaced all of the &gt;&#8217;s with &amp;gt;. Thankfully, one of the user community stepped up and fixed it.) &#8212; but, on the whole, it really did a nice job. Posting said code, however, was a bit of a formatting pain and I was looking for a more <em>convenient</em> way to do so.</p>
<p><a href="http://www.hanselman.com/blog/BestCodeSyntaxHighlighterForSnippetsInYourBlog.aspx">Scott Hanselman</a> blogged that he uses a plug-in for <a href="http://windowslivewriter.spaces.live.com/">Windows Live Writer</a> called <a href="http://www.codeplex.com/precode">PreCode</a> which works pretty well. Since I tend to use the web-based editor to craft 90% of my posts, that wasn&#8217;t as appealing to me, though I did play with it a bit and should I ever convert myself to WLW, I&#8217;d certainly go that route. Also, I had finally converted the site to use a <a href="http://wordpress.org/extend/plugins/syntaxhighlighter/">plug-in for SyntaxHighlighter</a> which has really excellent <a href="http://wordpress.org/extend/plugins/syntaxhighlighter/other_notes/">BBCode</a> support rather than the manual javascript includes that I had before.</p>
<p>The end result was that, to save myself about 2-3 minutes per piece of code, I added a QuickTag to the wordpress HTML editor so that I could wrap code in the proper [<code>code=''</code>] block with a single click. To so requires editing <code>{wordpress_install_dir}/wp-includes/js/quicktags.js</code> :</p>
<p><strong>1.</strong> Just past line 125, add:</p>
<pre class="brush: jscript; title: ; notranslate">edButtons[edButtons.length] =
new edButton('ed_sh'
,'syntax'
,''
,'{/code}'    //Replace {} with [] here. SH munges '['/code']'
,'h'
);</pre>
<p><strong>2.</strong> A bit further down, in <code>edShowButton()</code>, add an additional <code>else if()</code> block:</p>
<pre class="brush: jscript; title: ; notranslate">else if (button.id == 'ed_sh') {
	document.write('&lt;input type=&quot;button&quot; id=&quot;' + button.id + '&quot; accesskey=&quot;' + button.access + '&quot; class=&quot;ed_button&quot; onclick=&quot;edInsertSH(edCanvas, ' + i + ');&quot; value=&quot;' + button.display + '&quot; /&gt;');
}</pre>
<p><strong>3.</strong> Finally, you need to provide <code>edInsertSH()</code>. I just re-used <code>edInsertLink()</code> at what is now line 391:</p>
<pre class="brush: jscript; title: ; notranslate">function edInsertSH(myField, i, defaultValue) {
	if (!defaultValue) {
		defaultValue = 'sh';
	}
	if (!edCheckOpenTags(i)) {
		var SH = prompt('Enter Syntax Type', defaultValue);
		if (SH) {
			edButtons[i].tagStart = &quot;1&quot;;
			edInsertTag(myField, i);
		}
	}
	else {
		edInsertTag(myField, i);
	}
}</pre>
<p>If you happen to post a lot with a particular language, feel free to change the <code>defaultValue</code> to something more relevant. I chose sh because it's short. You could, alternatively, choose nothing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattshelton.net/2009/01/13/adding-syntaxhighlighter-quicktag-support-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Perl Support for Google SyntaxHighlighter</title>
		<link>http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/</link>
		<comments>http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 12:40:52 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[SyntaxHighlighter]]></category>

		<guid isPermaLink="false">http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/</guid>
		<description><![CDATA[<p>Posted in <a href="http://www.mattshelton.net/topics/code/" title="code">code</a></p>I&#8217;ve been enjoying playing with Google&#8217;s SyntaxHighlighter. Another user came up with a Perl brush file, so I thought I&#8217;d give it a shot. One note from the author of the brush file is that -&#62; gets converted to -&#38;gt; &#8230; <a href="http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been enjoying <a href="http://www.mattshelton.net/2007/12/13/code-highlighting-with-googles-syntaxhighlighter/">playing with Google&#8217;s SyntaxHighlighter</a>. Another <a href="http://opticalgarbage.com/sh/">user</a> came up with a Perl brush file, so I thought I&#8217;d give it a shot. One note from the author of the brush file is that -&gt; gets converted to -&amp;gt; rather than being translated properly. It&#8217;s definitely the highlighter that does it, too, because when you disable the brush it shows up properly.</p>
<pre class="brush: perl; title: ; notranslate">#!/usr/bin/perl

use strict;
use Mail::Box::Manager;

#################################
# User Variables
#
# Set $password to your password (encoded):
# . only the low four bits of each character count
# . character 0x3f gets split into 0x?3 and 0x?f,
# . fill in the ?'s with anything you like
# . man ascii =)
#

my $server = 'pop.server.name';
my $username = 'username';
my $password = 'tSvx6!f&gt;v7V%d=fU'; # the word &quot;ChangeMe&quot; encoded

#################################
# Get em!
#

my $mgr = Mail::Box::Manager-&gt;new;
my $pop = $mgr-&gt;open(type =&gt; 'pop3',
username =&gt; $username,
password =&gt; decodePassword($password),
server_name =&gt; $server);

my @messages = $pop-&gt;messages;

print
&quot; 33[00;30;1m: 33[00;36m: 33[00;36;1m: &quot;, scalar @messages, &quot; messages in mailbox : 33[00;36m: 33[00;30;1m: 33[mn&quot;;

foreach my $message (@messages) {
	my $fr = $message-&gt;get('From');
	$fr =~ s/s+&lt; .*$//; $fr =~ s/&quot;//g;

	printf &quot; 33#7 33[1m %-28.28s %-45.45s 33[0mn&quot;, $fr, $message-&gt;get('Subject');
	my $lbls = $message-&gt;labels;
	while( my ($k, $v) = each %$lbls ) {
		print &quot;key: $k, value: $v.n&quot;;
	}
}

$pop-&gt;close;

#################################
# methods
#

sub decodePassword($) {
	my ($password_split) = @_;
	my $password = &quot;&quot;;
	my ($high, $low);

	$password_split = reverse($password_split);
	while (length($password_split) &gt; 1) {
		$high = (ord(chop($password_split)) &amp; 0xf) &lt; &lt; 4;
		$low = ord(chop($password_split)) &amp; 0xf;
		$password .= chr($high|$low);
	}

	return $password;
}</pre>
<p>About three years ago I was living in the shell. I had a script aliased to &#8216;m&#8217; that would run a perl script for each of my IMAP accounts and show me all of the unread messages. The script had been originally written by a fellow Help Desk supervisor at UB and then given colorization support by another fellow supervisor, <a href="http://drakkhen.net/">Doug</a>, who has since become a perl and python guru.</p>
<p>The trouble then was that, while this worked for my home email server, I had to change some of the socket code to work on all of the other IMAP servers I used. That wasn&#8217;t too tough since IMAP is a relatively straightforward protocol. Getting POP support to work looked to be a lot harder, however. I couldn&#8217;t find anyone that had written something similar for me to hack, so I wrote my own.</p>
<p>This script above uses the perl module Mail::Box which installs straight out of CPAN. It&#8217;s probably been updated since this was written, and I don&#8217;t even know if the script still works (who still uses POP??)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattshelton.net/2008/01/28/testing-perl-support-for-google-syntaxhighlighter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Code Highlighting With Google&#8217;s SyntaxHighlighter</title>
		<link>http://www.mattshelton.net/2007/12/13/code-highlighting-with-googles-syntaxhighlighter/</link>
		<comments>http://www.mattshelton.net/2007/12/13/code-highlighting-with-googles-syntaxhighlighter/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 17:30:59 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[SyntaxHighlighter]]></category>

		<guid isPermaLink="false">http://www.mattshelton.net/2007/12/13/code-highlighting-with-googles-syntaxhighlighter/</guid>
		<description><![CDATA[<p>Posted in <a href="http://www.mattshelton.net/topics/code/" title="code">code</a><a href="http://www.mattshelton.net/topics/how-to/" title="how-to">how-to</a></p>This is (mostly) a test post to see how well Google&#8217;s SyntaxHighligher works. As you hopefully see below (if your browser supports javascript), it works well. I approve! I use a combination of plugins that all fight to figure out &#8230; <a href="http://www.mattshelton.net/2007/12/13/code-highlighting-with-googles-syntaxhighlighter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is (mostly) a test post to see how well Google&#8217;s <a href="http://code.google.com/p/syntaxhighlighter/">SyntaxHighligher</a> works. As you hopefully see below (if your browser supports javascript), it works well. I approve!</p>
<pre class="brush: php; title: ; notranslate">function safe($num) {
	// there has to be a smarter way to do this!
	// make sure that $num is always above 65
	$diff = date(&quot;w&quot;,$now) + 65;
	if ($num &lt; 65) {
		$num+=$diff;
	}

	// make sure that $num is in 65-90 or 97-122
	if (($num &gt; 90) &amp;&amp; ($num &lt; 97)) {
		$num+=7;
		return $num;
	}
	elseif ($num &gt; 122) {
		// be formulaic rather than arbitrary
		$d = $num-122; $e = $d%7; $f = $d+$e;
		$num-=$f;
		return $num;
	}
	else {
		return $num;
	}
}</pre>
<p>I use a combination of plugins that all fight to figure out what to do with PHP soure code. In order to make this work, I used <a href="http://www.village-idiot.org/archives/2006/04/09/wp-simplecode/">SimpleCode</a> to translate the source into HTML entities so that <a href="http://bluesome.net/post/2005/08/18/50/">Exec-PHP</a> wouldn&#8217;t try to execute the code block.</p>
<p>The default font set for the code display is <a href="http://en.wikipedia.org/wiki/Consolas">Consolas</a>, and then the standard Courier New, Courier and then whatever your system&#8217;s default mono-space or serif fonts are. If you haven&#8217;t <a href="http://www.microsoft.com/downloads/details.aspx?familyid=22e69ae4-7e40-4807-8a86-b3d36fab68d3">downloaded</a> Consolas, I&#8217;d highly suggest it. <a href="http://www.hanselman.com/blog/">Scott Hanselman</a> wrote a couple of <a href="http://www.hanselman.com/blog/InSearchOfThePerfectMonospacedProgrammersFontInconsolata.aspx">articles</a> <a href="http://www.hanselman.com/blog/ConsolasFontFamilyNowAvailableForDownload.aspx">about</a> it, including <a href="http://www.hanselman.com/blog/UsingConsolasAsTheWindowsConsoleFont.aspx">making Consolas your default Console font</a>, which I do with reckless abandon.</p>
<p>SyntaxHighlighter has a couple of nifty <a href="http://code.google.com/p/syntaxhighlighter/wiki/Configuration">options</a>, such as disabling some extra controls, removing the line numbers and keeping the &lt;pre&gt; block collapsed by default, ideally so that you could have links to expand them as needed. I made one change to the style sheet &#8211; making the grey left-hand border 20px thinner. I thought a 45px band of nothing was a bad use of space. The highlighting loads absolutely last on the page so you, the user, don&#8217;t sit there waiting for it to work in order to begin browsing content.</p>
<p>Sadly, there is currently no highlighting set for Basic, else <a href="http://www.mattshelton.net/2007/12/11/basically-silly/">Tuesday&#8217;s post</a> would have looked better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mattshelton.net/2007/12/13/code-highlighting-with-googles-syntaxhighlighter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

