<?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>Digitivity &#187; code excerpt</title>
	<atom:link href="http://digitivity.org/tag/code-excerpt/feed" rel="self" type="application/rss+xml" />
	<link>http://digitivity.org</link>
	<description>The Digital Productivity Blog</description>
	<lastBuildDate>Sat, 24 Dec 2011 17:34: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>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Color Syntax Highlighting for Code WordPress with the wp-syntax Plugin</title>
		<link>http://digitivity.org/248/color-syntax-highlighting-for-code-wordpress-with-the-wp-syntax-plugin</link>
		<comments>http://digitivity.org/248/color-syntax-highlighting-for-code-wordpress-with-the-wp-syntax-plugin#comments</comments>
		<pubDate>Wed, 27 May 2009 04:12:11 +0000</pubDate>
		<dc:creator>Digitivity</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Developer]]></category>
		<category><![CDATA[code excerpt]]></category>
		<category><![CDATA[code highlight]]></category>
		<category><![CDATA[extension]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[syntax coloring]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp-syntax]]></category>

		<guid isPermaLink="false">http://www.digitivity.org/?p=248</guid>
		<description><![CDATA[<p>Posted in <a href="http://digitivity.org/category/blogging" title="Blogging">Blogging</a><a href="http://digitivity.org/category/audience/developer" title="Developer">Developer</a></p>If you ever want to insert code in your WordPress blog, you probably ought to have a syntax highlighting plugin installed. Otherwise, you'll probably mess up your blog template for the pages that have code on them.


Related posts:<ol><li><a href='http://digitivity.org/236/making-minor-changes-in-wordpress-without-updating-the-last-updated-date-with-the-minor-edit-plugin' rel='bookmark' title='Permanent Link: Making Minor Changes in WordPress Without Updating the Last-Updated Date with the Minor Edit Plugin'>Making Minor Changes in WordPress Without Updating the Last-Updated Date with the Minor Edit Plugin</a></li>
<li><a href='http://digitivity.org/795/install-cbnet-ping-optimizer-plugin-wordpress' rel='bookmark' title='Permanent Link: Installing the cbnet Ping Optimizer Plugin for WordPress'>Installing the cbnet Ping Optimizer Plugin for WordPress</a></li>
<li><a href='http://digitivity.org/463/how-to-stop-comment-spam-in-wordpress-with-the-akismet-plugin' rel='bookmark' title='Permanent Link: How to Stop Spam in WordPress with the Akismet Plugin'>How to Stop Spam in WordPress with the Akismet Plugin</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you ever want to insert code in your WordPress blog, you probably ought to have a syntax highlighting plugin installed. Otherwise, you&#8217;ll probably mess up your blog template for the pages that have code on them.</p>
<p>By the way, this applies not only to code, but also anything that you might want to display to the user as-is, without line breaks, maybe even a poem.</p>
<h2>Why a Code Syntax Plugin</h2>
<p>Anyway, if you enter program code in the normal WordPress visual editor, you&#8217;ll lose the indentation:</p>
<p>public static void main(String[] args) throws ClientProtocolException, IOException {</p>
<p>URL url = new URL(&#8220;https://ssl.site&#8221;);<br />
Socket s = new Socket(&#8220;proxy.address&#8221;, 8080);</p>
<p>Also, lines will usually wrap, which, depending on the programming language, may or may not change the meaning of the code, but might also hinder the reader&#8217;s understanding of it.</p>
<p>As well, since the text will be in a proportional font instead of monospace, which is usually used to line up text columns with code.</p>
<h2>Code Syntax Plugins for WordPress</h2>
<h3>Code Snippet</h3>
<p>The top Google result for &#8220;wordpress code plugin&#8221; is <a href="http://wordpress.org/extend/plugins/codesnippet-20/">Code Snippet</a>. It&#8217;s based on the excellent and flexible <a href="http://qbnz.com/highlighter/">GeSHi</a> syntax highlighting engine. Unfortunately, the last time it was updated was 2007, and the total all-time downloads (about 3000) are equal to the weekly downloads for wp-syntax, discussed below.</p>
<h3>Google Code Highlighter</h3>
<p>The <a href="http://wordpress.org/extend/plugins/google-syntax-highlighter/">Google Syntax Highlighter for WordPress</a> also highlights code. It uses the <a href="http://code.google.com/p/syntaxhighlighter">Google Syntax Highlighter</a>. Disadvantages of this plugin as I see it include:</p>
<ul>
<li>JavaScript is required. The code isn&#8217;t highlighted as-is, rather it&#8217;s highlighted when it reaches the user&#8217;s browser. I&#8217;m not quite sure how this is to work in FeedBurner and other readers.</li>
<li>Much fewer languages are supported than GeSHi. While the supported languages are the most common ones in use today, it hardly seems worthwhile to limit your blogging to just these specific languages.</li>
</ul>
<div id="attachment_256" class="wp-caption alignnone" style="width: 495px"><a href="http://www.digitivity.org/blog/wp-content/uploads/2009/05/wordpress-plugin-google-syntax-highlighter-ruby-example-01-ext.png"><img src="http://www.digitivity.org/blog/wp-content/uploads/2009/05/wordpress-plugin-google-syntax-highlighter-ruby-example-01-ext.png" alt="Google Syntax Highlighter WordPress Plugin: Sample 1" title="Google Syntax Highlighter WordPress Plugin: Sample 1" width="485" height="275" class="size-full wp-image-256" /></a><p class="wp-caption-text">Google Syntax Highlighter WordPress Plugin: Sample 1</p></div>
<h3>wp-syntax</h3>
<p><a href="http://wordpress.org/extend/plugins/wp-syntax/">wp-syntax</a> is the best overall plugin for displaying code in WordPress:<br />
<div id="attachment_257" class="wp-caption alignnone" style="width: 387px"><a href="http://www.digitivity.org/blog/wp-content/uploads/2009/05/wordpress-plugin-wp-syntax-php-example-01-ext.png"><img src="http://www.digitivity.org/blog/wp-content/uploads/2009/05/wordpress-plugin-wp-syntax-php-example-01-ext.png" alt="wp-syntax WordPress Plugin: PHP Sample 1" title="wp-syntax WordPress Plugin: PHP Sample 1" width="377" height="144" class="size-full wp-image-257" /></a><p class="wp-caption-text">wp-syntax WordPress Plugin: PHP Sample 1</p></div></p>
<ul>
<li>It&#8217;s based on GeSHi, which supports over a hundred programming languages.</li>
<li>All the highlighting happens on the server, and the syntax coloring is embedded in the HTML instead of being in a separate stylesheet file. What that means is that users reading your webfeed in something like FeedBurner will see highlighted code.</li>
<li>The high number of downloads reduce the possibility that you&#8217;ll have standardized on a plugin that will be abandoned.</li>
<li>The code display is very sleek, unlike a lot of other highlighting plugins. For example, the Google Highlighter has &#8220;view plain&#8221;, &#8220;copy to clipboard&#8221;, &#8220;print&#8221;, and &#8220;?&#8221; menu items. This is partly necessitated by the fact that many code plugins have so much cruft that a normal select-and-copy operation doesn&#8217;t result in copying usably indented code to the clipboard. I&#8217;m put off by the fact that a code display needs a user interface! wp-syntax just works; you select the code, copy, and  paste.</li>
<li>You can choose whether to display line numbers or not, adding to the unburdened display.</li>
</ul>
<h2>Using wp-syntax</h2>
<p>Just put your code in a &lt;pre&gt; block. You can do that by selecting the &#8220;Preformatted&#8221; option in the text Format selector. If that&#8217;s not visible, you may need to press the &#8220;Show/Hide Kitchen Sink&#8221; button, which is the rightmost button on the top row in the Visual Editor.</p>
<p>After you&#8217;re done adding your all your code blocks, switch to the HTML Editor, and add a lang=&#8221;java&#8221; (or whatever language you&#8217;re using) to the &lt;pre&gt; blocks.  You can also add a line=&#8221;1&#8243; to start line number at whatever number you want. (But beware, this&#8217;ll be stripped away after switching back to the Visual Editor.)</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">pre</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;java&quot;</span>&gt;</span></pre></div></div>

</pre>
<p>That's it for basic usage.</p>
<p>Note: be sure to watch for more posts, which will go into more detail about installing and using the wp-syntax plugin.</p>
<p><a href="http://wordpress.org/extend/plugins/wp-syntax/">Get wp-syntax here</a>.</p>


<p>Related posts:<ol><li><a href='http://digitivity.org/236/making-minor-changes-in-wordpress-without-updating-the-last-updated-date-with-the-minor-edit-plugin' rel='bookmark' title='Permanent Link: Making Minor Changes in WordPress Without Updating the Last-Updated Date with the Minor Edit Plugin'>Making Minor Changes in WordPress Without Updating the Last-Updated Date with the Minor Edit Plugin</a></li>
<li><a href='http://digitivity.org/795/install-cbnet-ping-optimizer-plugin-wordpress' rel='bookmark' title='Permanent Link: Installing the cbnet Ping Optimizer Plugin for WordPress'>Installing the cbnet Ping Optimizer Plugin for WordPress</a></li>
<li><a href='http://digitivity.org/463/how-to-stop-comment-spam-in-wordpress-with-the-akismet-plugin' rel='bookmark' title='Permanent Link: How to Stop Spam in WordPress with the Akismet Plugin'>How to Stop Spam in WordPress with the Akismet Plugin</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://digitivity.org/248/color-syntax-highlighting-for-code-wordpress-with-the-wp-syntax-plugin/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: digitivity.org @ 2012-05-22 17:20:05 -->
