<?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>Adam's Continuity at BlackAcid &#187; wordpress</title>
	<atom:link href="http://blogs.blackacid.org/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.blackacid.org</link>
	<description>Experiments in Real Time</description>
	<lastBuildDate>Tue, 27 Jan 2009 23:24:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1-alpha</generator>
		<item>
		<title>WordPress Syntax Highlighting &#8211; Phase 2</title>
		<link>http://blogs.blackacid.org/2007/11/18/wordpress-syntax-highlighting-phase-2/</link>
		<comments>http://blogs.blackacid.org/2007/11/18/wordpress-syntax-highlighting-phase-2/#comments</comments>
		<pubDate>Sun, 18 Nov 2007 09:43:17 +0000</pubDate>
		<dc:creator>aballai</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[code snippets]]></category>
		<category><![CDATA[geshi]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blogs.blackacid.org/2007/11/18/wordpress-syntax-highlighting-phase-2/</guid>
		<description><![CDATA[Since recent times have suggested to me that I better start putting a good collection of code online about how the things I create work, I need to start with a better syntax highlighter which is so important to explaining &#8230; <a href="http://blogs.blackacid.org/2007/11/18/wordpress-syntax-highlighting-phase-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since recent times have suggested to me that I better start putting a good collection of code online about how the things I create work, I need to start with a better syntax highlighter which is so important to explaining how things work in this world.</p>
<p>I started off using google&#8217;s system, but found it too cumbersome.  I shot straight through three more plugins tonight and found they also have strange issues.  This last one I&#8217;m working with today has found all the problems I have had and made it nice to use, besides one large issue with the WordPress TinyMCE Editor. </p>
<p>The winner is<br />
<a href="http://elasticdog.com/2004/09/code-viewer/" alt="CodeViewer">CodeViewer</a> by elasticdog &#8211; <a href="http://elasticdog.com/2004/09/code-viewer/">http://elasticdog.com/2004/09/code-viewer/</a></p>
<p>Below is a Test Program &#8211; this is a C program and you download here to it:
<ol class="codelist">
<li class="tab0 odd"><code><span style="color: #339933;">#include &lt;stdio.h&gt;</span></code></li>
<li class="tab0 even"><code><span style="color: #339933;">#include &lt;stdlib.h&gt;</span></code></li>
<li class="odd">&nbsp;</li>
<li class="tab0 even"><code><span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></code></li>
<li class="tab2 odd"><code><span style="color: #b1b100;">return</span>;</code></li>
<li class="tab0 even"><code><span style="color: #66cc66;">&#125;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://blogs.blackacid.org/code/test.c">test.c</a></li>
</ol>
<p>I found that formatting is more important than the actual syntax highlighting.  So what I&#8217;m doing is using CodeViewer for the display and will use a child extension for doing actual syntax highlighting.  </p>
<p><a href="http://qbnz.com/highlighter/">GeSHi</a> has given a wonderful attempt at writing a variable syntax highlighter.  It works while in chunk-based highlighting too.  GeSHi is a O(n) based parser for syntax highlighting, yet it works pretty quickly as it keeps its use of substr and preg_replace at a minimum where doing character based descent to speed up the system.</p>
<p>I&#8217;ve partially implemented GeSHi for line-based highlighting inside CodeViewer.  You can download and compliment your wordpress installation by grabbing this tarball &#8211; <a href="/code/code-viewer_geshi.tar.bz2">Code Viewer with GeSHi Support</a>.  </p>
<p>To write a proper geshi supported tag, you must use the lang attribute.  </p>
<ol class="codelist">
<li class="tab0 odd"><code>&lt;viewcode src=&quot;cv_geshi_example.html&quot; lang=&quot;html&quot; /&gt;</code></li>
</ol>
<p>If you would like to see the changes I&#8217;ve made to the plugin, please see this diff below:</p>
<ol class="codelist">
<li class="tab0 odd"><code><span style="color: #888822;">--- code-viewer.txt&nbsp; &nbsp; &nbsp;Mon Aug <span style="">29</span> <span style="">07</span>:<span style="">08</span>:<span style="">37</span> <span style="">2005</span></span></code></li>
<li class="tab0 even"><code><span style="color: #888822;">+++ code-viewer.php&nbsp; &nbsp; &nbsp;Sun Nov <span style="">18</span> <span style="">09</span>:<span style="">33</span>:<span style="">15</span> <span style="">2007</span></span></code></li>
<li class="tab0 odd"><code><span style="color: #440088;">@@ <span style="">-9</span>,<span style="">14</span> <span style="">+9</span>,<span style="">15</span> @@</span></code></li>
<li class="tab1 even"><code>*/</code></li>
<li class="odd">&nbsp;</li>
<li class="tab1 even"><code>/* Configuration Settings */</code></li>
<li class="tab0 odd"><code><span style="color: #991111;">-$default_path = &quot;http://elasticdog.com/code/&quot;; &nbsp;// the absolute path of your code folder</span></code></li>
<li class="tab0 even"><code><span style="color: #00b000;">+$default_path = &quot;http://<span style="">&#123;</span>$_SERVER<span style="">&#91;</span>'HTTP_HOST'<span style="">&#93;</span><span style="">&#125;</span>/code/&quot;; &nbsp;// the absolute path of your code folder</span></code></li>
<li class="odd">&nbsp;</li>
<li class="tab1 even"><code>/* --- STOP EDITING --- &nbsp;*/</code></li>
<li class="tab0 odd"><code><span style="color: #00b000;">+require_once<span style="">&#40;</span>'geshi/geshi.php'<span style="">&#41;</span>;</span></code></li>
<li class="even">&nbsp;</li>
<li class="tab1 odd"><code>function code_viewer<span style="">&#40;</span>$text<span style="">&#41;</span> <span style="">&#123;</span></code></li>
<li class="tab2 even"><code>global $default_path;</code></li>
<li class="odd">&nbsp;</li>
<li class="tab0 even"><code><span style="color: #991111;">-&nbsp; &nbsp; &nbsp; &nbsp;$count = preg_match_all<span style="">&#40;</span>'/&lt;viewcode src=&quot;<span style="">&#40;</span><span style="">&#91;</span>^&quot;<span style="">&#93;</span>+<span style="">&#41;</span>&quot;<span style="">&#40;</span>?: link=&quot;<span style="">&#40;</span>?i:<span style="">&#40;</span>yes|no<span style="">&#41;</span><span style="">&#41;</span>&quot;<span style="">&#41;</span>?\s?\/&gt;/', $text, $matches<span style="">&#41;</span>;</span></code></li>
<li class="tab0 odd"><code><span style="color: #00b000;">+&nbsp; &nbsp; &nbsp; &nbsp;$count = preg_match_all<span style="">&#40;</span>'/&lt;viewcode src=&quot;<span style="">&#40;</span><span style="">&#91;</span>^&quot;<span style="">&#93;</span>+<span style="">&#41;</span>&quot;<span style="">&#40;</span>?: link=&quot;<span style="">&#40;</span>?i:<span style="">&#40;</span>yes|no<span style="">&#41;</span><span style="">&#41;</span>&quot;<span style="">&#41;</span>?<span style="">&#40;</span>?: lang=&quot;<span style="">&#40;</span>?i:<span style="">&#40;</span><span style="">&#91;</span>a-z<span style="">&#93;</span>+<span style="">&#41;</span><span style="">&#41;</span>&quot;<span style="">&#41;</span>?\s?\/&gt;/', $text, $matches<span style="">&#41;</span>;</span></code></li>
<li class="even">&nbsp;</li>
<li class="tab2 odd"><code>for <span style="">&#40;</span>$i = <span style="">0</span>; $i &lt; $count; $i++<span style="">&#41;</span> <span style="">&#123;</span></code></li>
<li class="tab3 even"><code>// Determine if the specified path is absolute, or relative to the root path</code></li>
<li class="tab0 odd"><code><span style="color: #440088;">@@ <span style="">-29</span>,<span style="">6</span> <span style="">+30</span>,<span style="">9</span> @@</span></code></li>
<li class="tab4 even"><code>$path = $default_path . $matches<span style="">&#91;</span><span style="">1</span><span style="">&#93;</span><span style="">&#91;</span>$i<span style="">&#93;</span>;</code></li>
<li class="tab3 odd"><code><span style="">&#125;</span></code></li>
<li class="even">&nbsp;</li>
<li class="tab0 odd"><code><span style="color: #00b000;">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if<span style="">&#40;</span>strtolower<span style="">&#40;</span>$matches<span style="">&#91;</span><span style="">3</span><span style="">&#93;</span><span style="">&#91;</span>$i<span style="">&#93;</span><span style="">&#41;</span> != &quot;&quot;<span style="">&#41;</span> <span style="">&#123;</span></span></code></li>
<li class="tab0 even"><code><span style="color: #00b000;">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$language = $matches<span style="">&#91;</span><span style="">3</span><span style="">&#93;</span><span style="">&#91;</span>$i<span style="">&#93;</span>;</span></code></li>
<li class="tab0 odd"><code><span style="color: #00b000;">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="">&#125;</span></span></code></li>
<li class="tab3 even"><code>// Open the file</code></li>
<li class="tab3 odd"><code>// If the file can't be found, print an error message</code></li>
<li class="tab3 even"><code>if <span style="">&#40;</span>$lines = @file<span style="">&#40;</span>$path<span style="">&#41;</span><span style="">&#41;</span> <span style="">&#123;</span></code></li>
<li class="tab0 odd"><code><span style="color: #440088;">@@ <span style="">-44</span>,<span style="">8</span> <span style="">+48</span>,<span style="">11</span> @@</span></code></li>
<li class="tab5 even"><code><span style="">&#125;</span> else <span style="">&#123;</span></code></li>
<li class="tab6 odd"><code>$numtabs = strlen<span style="">&#40;</span>$line<span style="">&#41;</span> - strlen<span style="">&#40;</span>ltrim<span style="">&#40;</span>$line<span style="">&#41;</span><span style="">&#41;</span>; &nbsp;// determine the number of tabs</code></li>
<li class="tab6 even"><code>$line = trim<span style="">&#40;</span>$line<span style="">&#41;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// trim leading/trailing whitespace</code></li>
<li class="tab0 odd"><code><span style="color: #991111;">-</span></code></li>
<li class="tab0 even"><code><span style="color: #991111;">-&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $codelist .= &quot;\t&quot; . '&lt;li class=&quot;tab' . $numtabs . ' ' . $toggle . '&quot;&gt;&lt;code&gt;' . htmlspecialchars<span style="">&#40;</span>$line<span style="">&#41;</span> . '&lt;/code&gt;&lt;/li&gt;' . &quot;\n&quot;;</span></code></li>
<li class="tab0 odd"><code><span style="color: #00b000;">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if<span style="">&#40;</span>isset<span style="">&#40;</span>$language<span style="">&#41;</span><span style="">&#41;</span> <span style="">&#123;</span></span></code></li>
<li class="tab0 even"><code><span style="color: #00b000;">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$codelist .= &quot;\t&quot; . '&lt;li class=&quot;tab' . $numtabs . ' ' . $toggle . '&quot;&gt;&lt;code&gt;' . geshi_highlight<span style="">&#40;</span>$line, $language, null, true<span style="">&#41;</span> . '&lt;/code&gt;&lt;/li&gt;' . &quot;\n&quot;;</span></code></li>
<li class="tab0 odd"><code><span style="color: #00b000;">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="">&#125;</span> else <span style="">&#123;</span></span></code></li>
<li class="tab0 even"><code><span style="color: #00b000;">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$codelist .= &quot;\t&quot; . '&lt;li class=&quot;tab' . $numtabs . ' ' . $toggle . '&quot;&gt;&lt;code&gt;' . htmlspecialchars<span style="">&#40;</span>$line<span style="">&#41;</span> . '&lt;/code&gt;&lt;/li&gt;' . &quot;\n&quot;;</span></code></li>
<li class="tab0 odd"><code><span style="color: #00b000;">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="">&#125;</span></span></code></li>
<li class="tab5 even"><code><span style="">&#125;</span></code></li>
<li class="tab4 odd"><code><span style="">&#125;</span></code></li>
<li class="even">&nbsp;</li>
<li class="tab0 odd"><code><span style="color: #440088;">@@ <span style="">-76</span>,<span style="">4</span> <span style="">+83</span>,<span style="">4</span> @@</span></code></li>
<li class="even">&nbsp;</li>
<li class="tab1 odd"><code>add_filter<span style="">&#40;</span>'the_content', 'code_viewer', <span style="">9</span><span style="">&#41;</span>;</code></li>
<li class="tab1 even"><code>add_filter<span style="">&#40;</span>'the_content', 'fix_bad_p'<span style="">&#41;</span>;</code></li>
<li class="tab0 odd"><code><span style="color: #991111;">-?&gt;</span></code></li>
<li class="tab0 even"><code><span style="color: #aaaaaa; font-style: italic;">\ No newline at end of file</span></code></li>
<li class="tab0 odd"><code><span style="color: #00b000;">+?&gt;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://blogs.blackacid.org/code/code-viewer_geshi.diff">code-viewer_geshi.diff</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blogs.blackacid.org/2007/11/18/wordpress-syntax-highlighting-phase-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

