Testing posting C# code in wordpress using livewriter

I found something which I was looking for last few months i.e. WordPress has inbuilt support for formatting source code. 

This is what wordpress site say:

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

To accomplish the source code formatting, just wrap your code in these tags:

[sourcecode language=”css”]
your code here
[/sourcecode]

Lets try this.

 List<int> list = new List<int> { 1, 3, 2 }; var query = list.AsParallel().Where(l =&gt; l &lt; 3); foreach (var item in query) Console.WriteLine(item); 

Don’t see the result after putting into html directly.  Lets try publishing it

Good News.  After publishing it I can see the result in browser but on my live writer it doesn’t show up.

Let me make one more attempt.  Lets do it in edit window in live writer

</p> <p>List&lt;int&gt; list = new List&lt;int&gt; { 1, 3, 2 }; <p>var query = list.AsParallel().Where(l =&gt; l &lt; 3); <p>foreach (var item in query) <p>Console.WriteLine(item); </p>

The above attempt failed.  Looks like I need to go back and try where I started from i.e. using source tab.  Only draw back was some blank [&nbsp;] spaces got inserted which doesn’t look good.

List<int> list = new List<int> { 1, 3, 2 }; var query = list.AsParallel().Where(l =&gt; l &lt; 3); foreach (var item in query) Console.WriteLine(item);

Somehow directly going to html didn’t work.   Last time I tried wrapping it in <p> tag, lets use that approach

List<int> list = new List<int> { 1, 3, 2 }; var query = list.AsParallel().Where(l =&gt; l &lt; 3); foreach (var item in query) Console.WriteLine(item);

Lets try pasting this code in html:

 Console.Writeline("test"); 

It worked Smile

Lets try one more time by going to source tab

 Console.Writeline("test"); 
 // Array of source files string[] pics = Directory.GetFiles(sourceDir, imageExt); Console.WriteLine(String.Format("Processing {0} Files",pics.Length -1)); // Delete the files before program start string[] filePaths = Directory.GetFiles(destDir); foreach (string filePath in filePaths) File.Delete(filePath); 

 

Interesting above code appeared in full green.  Looks like wordpress pluging is smart in detecting comments in csharp and automatically converts to green.

 // Array of source files string[] pics = Directory.GetFiles(sourceDir, imageExt); Console.WriteLine(String.Format("Processing {0} Files",pics.Length -1)); // Delete the files before program start string[] filePaths = Directory.GetFiles(destDir); foreach (string filePath in filePaths) File.Delete(filePath); 

 

Failed, lets remove the comment and try posting it again.  Now I am on the learning curve Smile

 string[] pics = Directory.GetFiles(sourceDir, imageExt); Console.WriteLine(String.Format("Processing {0} Files",pics.Length -1)); // Delete the files before program start string[] filePaths = Directory.GetFiles(destDir); foreach (string filePath in filePaths) File.Delete(filePath); 

 

Looks like this is a bug in wordpress, or there might be a different way of doing it. The problem here is that when it sees comments it starts making next line green in color.  Sounds like it needs some help in finding the next line after comment.  May be there is another tag for doing that, lets try reading the documentation again:

 string[] pics = Directory.GetFiles(sourceDir, imageExt); Console.WriteLine(String.Format("Processing {0} Files",pics.Length -1)); // Delete the files before program start  <p>string[] filePaths = Directory.GetFiles(destDir); foreach (string filePath in filePaths) File.Delete(filePath); </p> <p>

I give up for now and will get back to it. 

So far I am able to post code but wordpress is treating code after my comment as comments, which is bad.  I really want to make it work.  Need to search on web.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s