<?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; WindowsLiveWriter</title>
	<atom:link href="http://www.mattshelton.net/tags/windowslivewriter/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>
	</channel>
</rss>

