Windows Live Writer Plugin - Source Code Formatter

by Amer Gerzic 12. August 2008 11:22

Couple of days ago, my blog application started crushing. At first, I assumed that my ISP provider is to blame. Somewhat irritated I submitted the question to the support crew and couple of emails later, they informed me that the blog application was taking over 100MB in RAM space (which triggers the server to stop the application). In addition I noticed that the number of visitors increased dramatically over the last couple of weeks. Quick look under the hood revealed that during post rendering, source code is rendered "on-fly", which utilizes Wilco.SyntaxHighlighter.dll control. Considering the fact that there are many posts that display the source code and that there are many visitors viewing them, it is possible that memory usage would increase drastically. To eliminate the issue I decided to render the code at the time of post editing (as opposed to rendering during page loading). The only elegant solution (in my case) was to use Windows Live Writer with source code plugin. However, I could not find a plugin that would satisfy my needs, so I decided to write my own.

 

As mentioned earlier, all of my syntax highlighting is done by Wilco.SyntaxHighlighting.dll control which can be found under reference section. At the same site you can find the source code. Following languages are supported:

  • ASPX
  • C
  • C#
  • C++
  • COBOL
  • Cold Fusion
  • CSS
  • Eiffel
  • Fortran
  • Haskell
  • Java
  • JavaScript
  • JScript
  • Mercury
  • MSIL
  • Pascal
  • Perl
  • PHP
  • Python
  • Ruby
  • SQL
  • Visual Basic
  • Visual Basic Script
  • XML

Sample Code Formatting:

Simplest code formatting - no box, no line numbers, no alternating color lines:

public class SourceCodeFormatter
{
    /* Member 1 */
    public static string member1;
    /* Member 2 */
    private int member2;
    // Constructor
    public SourceCodeFormatter()
    {
    }
}

... now enclose code into a box - very useful if the code might "overflow"

public class SourceCodeFormatter
{
    /* Member 1 */
    public static string member1;
    /* Member 2 */
    private int member2;
    // Constructor
    public SourceCodeFormatter()
    {
    }
}

... now add line numbers and alternating line coloring:

  1: public class SourceCodeFormatter
  2: {
  3:     /* Member 1 */
  4:     public static string member1;
  5: 
  6:     /* Member 2 */
  7:     private int member2;
  8: 
  9:     // Constructor
 10:     public SourceCodeFormatter()
 11:     {
 12:     }
 13: }

 

... now we can select some lines for demonstration:

  1: public class SourceCodeFormatter
  2: {
  3:     /* Member 1 */
  4:     public static string member1;
  5: 
  6:     /* Member 2 */
  7:     private int member2;
  8: 
  9:     // Contructor
 10:     public SourceCodeFormatter()
 11:     {
 12:     }
 13: }

Version History

  • 1.3.0 - Updates
    • Enable/Disable tab replacement - tabs are replaced by specified number of spaces (suggested by Dan)
    • Enable/Disable selection
  • 1.1.0 - Updates
    • Enable/Disable Source Code Box
    • Line Numbering
    • Alternating Line Coloring
  • 1.0.0 - Initial Release
    • Live Preview
    • Source Code Box Width
    • Source Code Box Border Color
    • Source Code Box Background Color
    • Source Code Font Size
    • Saves Most Recent Option Selection

References

Download

Download Source Code Plugin Setup (446.54 kb)
Download Source Code Plugin Source (219.87 kb)

Currently rated 4.8 by 6 people

  • Currently 4.833333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.NET | C# | Windows Live Writer

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

Who is Amer?

Amer Gerzic is IT Director at Presort Services Inc. and founder of Infinity Software Solutions LLC. For futher information please check LinkedIn profile.

View Amer Gerzic's profile on LinkedIn

Recent comments

Comment RSS

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2008