代码改变世界

发布一个博客园专用Windows Live Writer代码插件

2010-12-15 23:53  T2噬菌体  阅读(5464)  评论(30编辑  收藏  举报

一直用Windows Live Writer写博客,不过没找到能与博客园配合得很好的代码插件,每次写完文章发布到博客园总要手动修改代码。所以我自己写了一个博客园专用的Windows Live Writer代码插件(我知道这世界上已经有N个代码插件,好吧,我承认我手贱O(∩_∩)O~)。

代码是通过syntaxhighlighter渲染的,插件根据博客园的特点定制了特殊的html格式。

使用方法

插件使用非常简单,在需要插入代码的地方点击“插入”菜单下的“CnblogsCode”:

image

然后就可以再如下的界面中插入代码了:

image

效果如下:

/************************************************************
 * Windows Live Writer 博客园专用代码插件
 * 
 * @Author: 张洋(Eric Zhang)
 * @Blog: leoo2sk.cnblogs.com
 * @E-mail: ericzhang.buaa@gmail.com
 ************************************************************/

using System.Windows.Forms;
using WindowsLive.Writer.Api;

namespace CnblogsCode
{
    /// 
    /// 插件主体
    /// 
    [WriterPlugin("ED97E6E4-5A18-497e-A690-5DE4CF27C327", "CnblogsCode")]
    [InsertableContentSource("插入博客园样式代码", SidebarText = "博客园样式代码")]
    public class CnblogsCodeContentSource : ContentSource
    {
        public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
        {
            FRM_INSERT_CNBLOGS_CODE dialog = new FRM_INSERT_CNBLOGS_CODE();
            dialog.ShowDialog();
            content = dialog.HtmlContent;
            return dialog.DialogResult;
        }
    }
}

安装方法

只要将CnblogsCode.dll(点击这里下载)复制到“你的Windows Liver Writer安装目录\plugins\”下就可以了,一般这个目录是“C:\Program Files\Windows Live\Writer\Plugins”。下面将源代码一并奉上(点击这里下载)。