<?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>blog of ducklink.com &#187; Blog</title>
	<atom:link href="http://libg.org/tag/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://libg.org</link>
	<description></description>
	<lastBuildDate>Tue, 18 Jan 2011 04:54:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to format source code in your blog</title>
		<link>http://libg.org/2008/09/11/how-to-format-source-code-in-your-blog/</link>
		<comments>http://libg.org/2008/09/11/how-to-format-source-code-in-your-blog/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 11:59:00 +0000</pubDate>
		<dc:creator>Mason</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://libg.org/2008/09/11/how-to-format-source-code-in-your-blog/</guid>
		<description><![CDATA[When I was writing my post Include Guard: #pragma once vs. #ifndef #define #endif, I searched from Internet and tried at least 5 WordPress plug-in to insert formatted source code. But none of them works well for me. Some can not support C++ source code, some insert complicated html code to my post. Finally I [...]]]></description>
			<content:encoded><![CDATA[<p>When I was writing my post <a href="http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/" target="_blank"><em>Include Guard: #pragma once vs. #ifndef #define #endif</em></a>, I searched from Internet and tried at least 5 WordPress plug-in to insert formatted source code. But none of them works well for me. Some can not support C++ source code, some insert complicated html code to my post. Finally I found <a href="http://code.google.com/p/syntaxhighlighter/" target="_blank">syntax highlighting</a> is simply and easy to prettify my code. There is WordPress plug-in <a href="http://wordpress.org/extend/plugins/google-syntax-highlighter/" target="_blank">Google Syntax Highlighter for WordPress</a>, and convenient for WordPress users to integrate to your WordPress blog site. The plug-in author may be wrong here, because the true Google Code highlight tool is <a href="http://code.google.com/p/google-code-prettify/" target="_blank">Google Code Prettify</a>.</p>
<p>SyntaxHighlighter is a pure JavaScript based tool and can parse a lot of programming languages:</p>
<ul>
<li>C++ (cpp, c, c++) </li>
<li>C# (c#, c-sharp, csharp) </li>
<li>CSS (css) </li>
<li>Delphi (delphi, pascal) </li>
<li>Java (java) </li>
<li>Java Script (js, jscript, javascript) </li>
<li>PHP (php) </li>
<li>Python (py, python) </li>
<li>Ruby (rb, ruby, rails, ror) </li>
<li>Sql (sql) </li>
<li>VB (vb, vb.net) </li>
<li>XML/HTML (xml, html, xhtml, xslt) </li>
</ul>
<p>To learn format your source code use this tool, please refer to the usage from <a href="http://code.google.com/p/syntaxhighlighter/wiki/Usage" target="_blank">http://code.google.com/p/syntaxhighlighter/wiki/Usage</a>. This post demonstrated the result of SyntaxHighlighter so you can make a quick decision. I used the code from Microsoft MSDN <a title="http://msdn.microsoft.com/en-us/library/w5c4hyx3(VS.80).aspx" href="http://msdn.microsoft.com/en-us/library/w5c4hyx3(VS.80).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/w5c4hyx3(VS.80).aspx</a> as the sample code for testing.</p>
<p><strong>1. Default usage:</strong></p>
<p>&lt;pre name=&quot;code&quot; class=&quot;cpp&quot;&gt; &#8230; code here &#8230; &lt;/pre&gt;</p>
<p><u>Result:</u></p>
<pre class="cpp" name="code">// Exhibits polymorphism/virtual functions.

#include <iostream>
#include <string>
#define TRUE = 1
using namespace std;

class dog
{
public:
	// Source Code Omitted...

private:
   string _dogSize, _earType;
   int _legs;
   bool _bark;

};

class breed : public dog
{
public:
	/*
	Source Code Omitted...
	*/
};

int main()
{
   dog mongrel;
   breed labrador(&quot;yellow&quot;, &quot;large&quot;);
   mongrel.setEars(&quot;pointy&quot;);
   labrador.setEars(&quot;long&quot;, &quot;floppy&quot;);
   cout &lt;&lt; &quot;Cody is a &quot; &lt;&lt; labrador.getColor() &lt;&lt; &quot; labrador&quot; &lt;&lt; endl;
}</pre>
<p><strong>2. Display no gutter:</strong></p>
<p>&lt;pre name=&quot;code&quot; class=&quot;cpp:<font color="#ff0000">nogutter</font>&quot;&gt; &#8230; code here &#8230; &lt;/pre&gt;</p>
<p><u>Result:</u></p>
<pre class="cpp:nogutter" name="code">// Exhibits polymorphism/virtual functions.

#include <iostream>
#include <string>
#define TRUE = 1
using namespace std;

class dog
{
public:
	// Source Code Omitted...

private:
   string _dogSize, _earType;
   int _legs;
   bool _bark;

};

class breed : public dog
{
public:
	/*
	Source Code Omitted...
	*/
};

int main()
{
   dog mongrel;
   breed labrador(&quot;yellow&quot;, &quot;large&quot;);
   mongrel.setEars(&quot;pointy&quot;);
   labrador.setEars(&quot;long&quot;, &quot;floppy&quot;);
   cout &lt;&lt; &quot;Cody is a &quot; &lt;&lt; labrador.getColor() &lt;&lt; &quot; labrador&quot; &lt;&lt; endl;
}</pre>
<p><strong>3. Display no controls at the top</strong></p>
<p>&lt;pre name=&quot;code&quot; class=&quot;cpp:<font color="#ff0000">nocontrols</font>&quot;&gt; &#8230; code here &#8230; &lt;/pre&gt;</p>
<p><u>Result</u></p>
<pre class="cpp:nocontrols" name="code">// Exhibits polymorphism/virtual functions.

#include <iostream>
#include <string>
#define TRUE = 1
using namespace std;

class dog
{
public:
	// Source Code Omitted...

private:
   string _dogSize, _earType;
   int _legs;
   bool _bark;

};

class breed : public dog
{
public:
	/*
	Source Code Omitted...
	*/
};

int main()
{
   dog mongrel;
   breed labrador(&quot;yellow&quot;, &quot;large&quot;);
   mongrel.setEars(&quot;pointy&quot;);
   labrador.setEars(&quot;long&quot;, &quot;floppy&quot;);
   cout &lt;&lt; &quot;Cody is a &quot; &lt;&lt; labrador.getColor() &lt;&lt; &quot; labrador&quot; &lt;&lt; endl;
}</pre>
<p><strong>4. Collapse the block by default</strong></p>
<p>&lt;pre name=&quot;code&quot; class=&quot;cpp:<font color="#ff0000">collapse</font>&quot;&gt; &#8230; code here &#8230; &lt;/pre&gt;</p>
<p><u>Result</u></p>
<pre class="cpp:collapse" name="code">// Exhibits polymorphism/virtual functions.

#include <iostream>
#include <string>
#define TRUE = 1
using namespace std;

class dog
{
public:
	// Source Code Omitted...

private:
   string _dogSize, _earType;
   int _legs;
   bool _bark;

};

class breed : public dog
{
public:
	/*
	Source Code Omitted...
	*/
};

int main()
{
   dog mongrel;
   breed labrador(&quot;yellow&quot;, &quot;large&quot;);
   mongrel.setEars(&quot;pointy&quot;);
   labrador.setEars(&quot;long&quot;, &quot;floppy&quot;);
   cout &lt;&lt; &quot;Cody is a &quot; &lt;&lt; labrador.getColor() &lt;&lt; &quot; labrador&quot; &lt;&lt; endl;
}</pre>
<p><strong>5. Begin line count at <tt>value</tt>. Default value is 1</strong></p>
<p>&lt;pre name=&quot;code&quot; class=&quot;cpp:<font color="#ff0000">firstline[123]</font>&quot;&gt; &#8230; code here &#8230; &lt;/pre&gt;</p>
<p><u>Result</u></p>
<pre class="cpp:firstline[123]" name="code">// Exhibits polymorphism/virtual functions.

#include <iostream>
#include <string>
#define TRUE = 1
using namespace std;

class dog
{
public:
	// Source Code Omitted...

private:
   string _dogSize, _earType;
   int _legs;
   bool _bark;

};

class breed : public dog
{
public:
	/*
	Source Code Omitted...
	*/
};

int main()
{
   dog mongrel;
   breed labrador(&quot;yellow&quot;, &quot;large&quot;);
   mongrel.setEars(&quot;pointy&quot;);
   labrador.setEars(&quot;long&quot;, &quot;floppy&quot;);
   cout &lt;&lt; &quot;Cody is a &quot; &lt;&lt; labrador.getColor() &lt;&lt; &quot; labrador&quot; &lt;&lt; endl;
}</pre>
<p><strong>6. Show row columns in the first line. </strong></p>
<p>&lt;pre name=&quot;code&quot; class=&quot;cpp:<font color="#ff0000">showcolumns</font>&quot;&gt; &#8230; code here &#8230; &lt;/pre&gt;</p>
<p><u>Result</u></p>
<pre class="cpp:showcolumns" name="code">// Exhibits polymorphism/virtual functions.

#include <iostream>
#include <string>
#define TRUE = 1
using namespace std;

class dog
{
public:
	// Source Code Omitted...

private:
   string _dogSize, _earType;
   int _legs;
   bool _bark;

};

class breed : public dog
{
public:
	/*
	Source Code Omitted...
	*/
};

int main()
{
   dog mongrel;
   breed labrador(&quot;yellow&quot;, &quot;large&quot;);
   mongrel.setEars(&quot;pointy&quot;);
   labrador.setEars(&quot;long&quot;, &quot;floppy&quot;);
   cout &lt;&lt; &quot;Cody is a &quot; &lt;&lt; labrador.getColor() &lt;&lt; &quot; labrador&quot; &lt;&lt; endl;
}</pre>
<p><u></u></p>
<p>If you are using WordPress plug-in, please be sure to remove redundant JavaScript files in your plug-in source code and speed up the page loading. Go to WordPress dashboard, Plugins -&gt; Plugin Editor, select &quot;Google Syntax Highlighter for WordPress&quot;, go to the bottom of the source code, I removed the similar lines to the line below and kept this line to highlight CPP code:</p>
<p>&lt;script class=&quot;javascript&quot; src=&quot;&lt;?php echo $current_path; ?&gt;Scripts/<font color="#ff0000"><strong>shBrushCpp</strong></font>.js&quot;&gt;&lt;/script&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://libg.org/2008/09/11/how-to-format-source-code-in-your-blog/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

