Posting a source code on wordpress with syntax highlighter

Having a source code in your post?, try this new tag instead of <code> tag. Here i show you the difference between <code> and [sourcecode] tags

Example :
<code>
 void normalize()
 {
  double sq = x*x + y*y + z*z;
  if (sq > 0.0)
  {
   double div_a = 1.0/sqrt(sq);
   x *= div_a;
   y *= div_a;
   z *= div_a;
   w = 1.0;
  }
 }
</code>

will be rendered as below :

void normalize()
{
double sq = x*x + y*y + z*z;
if (sq > 0.0)
{
double div_a = 1.0/sqrt(sq);
x *= div_a;
y *= div_a;
z *= div_a;
w = 1.0;
}
}

whereas
[sourcecode language=”cpp”]
 void normalize()
 {
  double sq = x*x + y*y + z*z;
  if (sq > 0.0)
  {
   double div_a = 1.0/sqrt(sq);
   x *= div_a;
   y *= div_a;
   z *= div_a;
   w = 1.0;
  }
 }
[/sourcecode]

The result is,

	void normalize()
	{
		double sq = x*x + y*y + z*z;
		if (sq > 0.0)
		{
			double div_a = 1.0/sqrt(sq);
			x *= div_a;
			y *= div_a;
			z *= div_a;
			w = 1.0;
		}
	}

References:
http://alexgorbatchev.com/SyntaxHighlighter/
http://en.support.wordpress.com/code/posting-source-code/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s