A nice touch to your blog is to have a link to copy the code you have entered. Another great feature is to have your code colored as it would be in Visual Studio. There a couple of ways you can do this. Here is how I prefer to do it!
I use LiveWriter so I love to use Plug-Ins when appropriate. There are some plugins to make code pretty but some require <style> definitions. The MSDN blogs parse out these styles so you end up having to manually adding these styles to your blog’s theme (yuck).
In LiveWriter, go to the ‘Insert’ tab and choose ‘Add plug-in’
Once there filter by ‘Formatting / clipboard’ and choose ‘Paste from Visual Studio’
Hit the download button, then run the installer.
Now close and restart LiveWriter (don’t forget to save your work).
To use this plugin:
Result:
app.addEventListener("activated", function (args) { if (args.detail.kind === activation.ActivationKind.launch) { if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) { // TODO: This application has been newly launched. Initialize // your application here. } else { // TODO: This application has been reactivated from suspension. // Restore application state here. } if (app.sessionState.history) { nav.history = app.sessionState.history; } args.setPromise(WinJS.UI.processAll().then(function () { if (nav.location) { nav.history.current.initialPlaceholder = true; return nav.navigate(nav.location, nav.state); } else { return nav.navigate(Application.navigator.home); } })); } });
Note: If you disable any plug-in, installing it will not make it show up in the plug-in list. Simply re-enable it.
You can of course sweep out code and copy it from the page. I like to provide a ‘Copy Code’ link so I can ensure the blog reader gets all of the code correctly from me (and it is cool).
To do this you simply need to add a little JavaScript and a give a unique name to the block around the code you just pasted into the document.
Copy Code: <SCRIPT language=jscript> function CopyCode(elemName) { var obj = document.getElementById(elemName); window.clipboardData.setData("Text", obj.innerText); } </SCRIPT>
<SCRIPT language=jscript> function CopyCode(elemName) { var obj = document.getElementById(elemName); window.clipboardData.setData("Text", obj.innerText); } </SCRIPT>
<pre id="CopyCodeCodeSection1"
<strong><a href="javascript:CopyCode('CopyCodeCodeSection1');">Copy Code:</a></strong>
<strong><a style="background: lightgray;" href="javascript:CopyCode('CopyCodeCodeSection1');">Copy Code:</a></strong>
You can feel free to change the formatting or style of you Copy Code: link! I hope you find this useful so drop me a note if you like it!
@JsandersRocks, @WSDevSol
Windows Live Writer
Install point for 'Paste from Visual Studio'