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.