Windows Live Writer Plugin - Source Code Formatter

博客详细描述了作者的源代码渲染应用因访问量激增导致内存占用过高,进而引发应用崩溃的问题。通过分析,发现源代码在页面加载时实时渲染是罪魁祸首。为解决此问题,作者决定在编辑时预渲染代码,而非在页面加载时动态渲染,并最终选择使用Windows Live Writer及自定义插件实现这一目标。

August 12, 2008 at 11:22 AM — Amer Gerzic

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:     // Constructor
 10:     public SourceCodeFormatter()
 11:     {
 12:     }
 13: }

 

http://www.amergerzic.com/post/WLWSourceCodePlugin.aspx

https://www.cnblogs.com/twzy/p/5122520.html
 
2018年10月17日23:00

转载于:https://www.cnblogs.com/superdesigns/p/9807563.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值