<?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>thirstymind.org &#187; wordpress</title>
	<atom:link href="http://www.thirstymind.org/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thirstymind.org</link>
	<description>andrew watts' weblog</description>
	<lastBuildDate>Sat, 17 Oct 2009 22:11:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to remove highlight source pro markup from wordpress feeds</title>
		<link>http://www.thirstymind.org/2008/06/30/how-to-remove-highlight-source-pro-markup-from-wordpress-feeds/</link>
		<comments>http://www.thirstymind.org/2008/06/30/how-to-remove-highlight-source-pro-markup-from-wordpress-feeds/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 15:29:51 +0000</pubDate>
		<dc:creator>Andrew Watts</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.thirstymind.org/?p=363</guid>
		<description><![CDATA[A few weeks ago I set out to redesign my blog, and in the process, one thing I wanted to accomplish was creating a way to present code in a &#8220;pretty print&#8221; kind of way on the webpage.  My 4 requirements were:

monospace font
syntax highlighting
include line numbers as needed
optionally be valid html and semantically correct

Luckily [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I set out to redesign my blog, and in the process, one thing I wanted to accomplish was creating a way to present code in a &#8220;pretty print&#8221; kind of way on the webpage.  My 4 requirements were:</p>
<ol>
<li>monospace font</li>
<li>syntax highlighting</li>
<li>include line numbers as needed</li>
<li>optionally be valid html and semantically correct</li>
</ol>
<p>Luckily for me I found a pretty sweet wordpress plugin, <a href="http://wordpress.org/extend/plugins/highlight-source-pro/">highlight source pro</a>, built around the <a href="http://qbnz.com/highlighter/">GeSHI library</a> which did most of these things for me. I thought it was pretty cool that it used a wordpress filter to transform the code upon request, rather than transforming prior to db insert.  However there were a couple downsides I saw:</p>
<ol>
<li>GeSHI mangles the html so badly that it is no where close to semantically correct.</li>
<li>It did this for both the webpage and syndication feed, but I only wanted the webpage.</li>
</ol>
<p>There isn&#8217;t a lot I can do about number one, unless I really want to dig into the GeSHI library, and since it validates I&#8217;ve decided to leave it alone for now. However it was pretty easy to solve number two and here is how I did that.</p>
<p>First, you need to know that highlight source pro plugin uses a <a href="http://codex.wordpress.org/Plugin_API/Filter_Reference">wordpress filter</a> on &#8216;<a href="http://codex.wordpress.org/Plugin_API/Filter_Reference#Database_Reads">the_content</a>&#8216; to transform your code markup into it&#8217;s &#8220;pretty print&#8221; format for display.  The function for this filter is called hsp_clean_and_codify() and is located in the file: wordpress/wp-content/plugins/highlight-source-pro/highlight_source_pro.php.</p>
<p>So, then open wordpress/wp-content/plugins/highlight-source-pro/highlight_source_pro.php and locate the hsp_clean_and_codify() function. Then you want to modify the opening lines of the function to check if the request&#8217;s query string includes &#8216;feed=&#8217;, if so return and avoid transforming the html markup into the GeSHI pretty print format. ie:</p>
<div class="geshi php">
<ol start="91">
<li class="li1">
<div class="de1"><span class="kw2">function</span> hsp_clean_and_codify<span class="br0">&#40;</span><span class="re1">$subject</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// do not want the funky markup in the rss feed, its not pretty.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// so if the request contains a &#39;feed=&#39; in the query string then</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// ignore it</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">preg_match</span><span class="br0">&#40;</span><span class="st0">&quot;/feed=/&quot;</span><span class="sy0">,</span> <span class="re1">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#39;QUERY_STRING&#39;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re1">$subject</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// original code below here</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$original</span><span class="sy0">=</span> <span class="re1">$subject</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>Now, anytime a request comes for a feed, the response will not include the GeSHI generated markup.</p>
<p>In the future it would be nice to see wordpress include separate filters for &#8216;the_content&#8217; and perhaps &#8216;the_feed_content&#8217; or possibly add an argument to the <a href="http://codex.wordpress.org/Plugin_API#Filters">add_filter function</a> which specifies what type of requests this filter should be applied on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thirstymind.org/2008/06/30/how-to-remove-highlight-source-pro-markup-from-wordpress-feeds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
