Peter's Gekko

Sponsors

The Lounge

Wicked Cool Jobs

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Formatting source code in a blog post

For some time now I'm using Word 2007 to write my blog posts. Which works quite well, except when it comes to source code. This is a public experiment.

This source was inserted with using a straigth copy.

[Test]

public void IsDeceased()

{

VecozoLib.ServiceWrapper sw = new ServiceWrapper();

VecozoLib.VecozoService.RetourinfoCovType data = sw.PersonData(DateTime.Parse("1-5-1945"), 141919723);

Assert.AreEqual(VecozoLib.ResultaatRaadpleging.PersoonIsOverleden, (VecozoLib.ResultaatRaadpleging) data.ResultaatcodeCOV);

}

Looks great in Word, but not that good online. The line spacing is far to great and all the indentation is gone.

To compare, this is the same using CopySourceAsHtml to do the copy.

[Test]

public void IsDeceased()

{

   VecozoLib.ServiceWrapper sw = new ServiceWrapper();

   VecozoLib.VecozoService.RetourinfoCovType data = sw.PersonData(DateTime.Parse("1-5-1945"), 141919723);

   Assert.AreEqual(VecozoLib.ResultaatRaadpleging.PersoonIsOverleden, (VecozoLib.ResultaatRaadpleging) data.ResultaatcodeCOV);

}

Which does not look that good in Word, but looks better on line. The line spacing is still too big, but the indentation is preserved.

And this is CopySourceAsHtml with linebreaks stripped

[Test]



public



void IsDeceased()



{



   VecozoLib.ServiceWrapper sw = new



ServiceWrapper();



   VecozoLib.VecozoService.RetourinfoCovType data = sw.PersonData(DateTime.Parse("1-5-1945"), 141919723);



   Assert.AreEqual(VecozoLib.ResultaatRaadpleging.PersoonIsOverleden, (VecozoLib.ResultaatRaadpleging) data.ResultaatcodeCOV);



}



Which is a mess.

Brendan pointed me to dp.SyntaxHighlighter. Since then this post keeps getting updated.

This source code formatter requires the syntaxhighligher scriptlibrary, which is available on Codebetter. For this tool to work you have to enclose the source code in a pair of tags.

<textarea name="code" class="c#" cols="60" rows="10">   

... source code here ...   

</textarea>   

This is difficult to do in Word 2007, as you cannot directly edit the html it publishes. Just like images this requires some fiddling by hand in the HTML in the blog dashboard. I paste the source as plain text, and do the HTML fiddling in the dashboard.

Due to the "inteligence" built into the CS rich text control this can be quite a job. But as you see the result can be nice.

Word 2007 is a great blogwriter. But the downside is that it's not that good with source code and there is no way (I know) to edit specific HTML. CopyAsHtml can come in handy.


Posted Fri, Mar 2 2007 7:07 AM by pvanooijen

[Advertisement]

Comments

Brendan Tompkins wrote re: Formatting source code in a blog post
on Fri, Mar 2 2007 7:55 AM

Peter, why don't you try using the dp.SyntaxHighlighter (we have it installed you know :) ?

http://www.dreamprojections.com/SyntaxHighlighter/

Brendan Tompkins wrote re: Formatting source code in a blog post
on Fri, Mar 2 2007 11:54 AM

Peter,

I removed the HTML encoding of your source code within the Textareas, and it looks pretty good to me....!

pvanooijen wrote re: Formatting source code in a blog post
on Fri, Mar 2 2007 12:41 PM

That's looking good !

How did you remove the html encoding ? By hand in the "blog-dashboard" ? That's quite an amount of work.

I absolutely admit this is the nicest result. Now I just have to find a way to combine it with Word 2007. To me a big reason for using an office app is the great spelling and grammar support.

Peter's Gekko wrote Formatting source code in a blog post (revisited)
on Tue, Feb 24 2009 5:08 AM

There are a couple of posts I have to write. But before doing that I need to reinvestigate the way to

Community Blogs wrote Formatting source code in a blog post (revisited)
on Tue, Feb 24 2009 5:32 AM

There are a couple of posts I have to write. But before doing that I need to reinvestigate the way to

Andrew Stark wrote re: Formatting source code in a blog post
on Tue, Mar 3 2009 3:55 PM

This is just what I was looking for to enter html code as part of a tutorial I wrote on my blog.

Thanks a lot

Andrew

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Devlicio.us