建立一個類庫
添加兩個關鍵引用
using WindowsLive.Writer.Api;using System.Windows.Forms;
using System.Web;
第一個引用的dll檔案在你安裝windows live writer的根目錄下
名字叫WindowsLive.Writer.Api.dll
添加一個類檔案,此檔案程式用來處理使用者插入的代碼
public static class ContentProcessor { public static string ProcessedContent { get; private set; } public static void Process(string originalContent) { ProcessedContent = (!string.IsNullOrEmpty(originalContent) ?string.Format("<fieldset style=\"background-color:#E0EFF6;color:#15428B\"><pre>{0}</pre></div>", HttpUtility.HtmlEncode(originalContent)) :string.Empty ); } }
添加一個windows form表單,
給確定按鈕添加的事件為
private void button1_Click(object sender, EventArgs e) { ContentProcessor.Process(this.textBox1.Text); this.Close(); }
其中ContentProcessor.Process(this.textBox1.Text);
就是調用的我們上一個類檔案中的處理常式
新增一個類檔案
[WriterPlugin("7c371eef-e350-4aae-af28-91613a9137e3", "xland", Description = "insert code plugin", Name = "xland", PublisherUrl = "http://www.cnblogs.com/liulun")] [InsertableContentSource("insert code",SidebarText="insert code")] public class MyPlugin:ContentSource { public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content) { new ProcessForm().ShowDialog(); content = ContentProcessor.ProcessedContent; return (!string.IsNullOrEmpty(content) ? DialogResult.OK : DialogResult.No); } }
其中7c371eef-e350-4aae-af28-91613a9137e3為一個GUID
其他的一些資訊是外掛程式在live writer中的資訊
函數中第一句是建立一個視窗(我們剛才製作的視窗)
第二句擷取我們輸入的資料(處理過後的資料)
第三句讓live writer知道有東西要插入。
content變數是live writer中的,所以要用ref修飾
都完成後只要把產生的dll檔案放在live writer安裝目錄下Plugins檔案夾內就可以了
此文章就是用這個外掛程式寫的
貼個圖看下
原始碼下載:LiveWriterPlugin.rar
另外:
我在我的blog中設定了這樣的樣式
pre { white-space: pre-wrap; /* css-3 */ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ white-space: -pre-wrap; /* Opera 4-6 */ white-space: -o-pre-wrap; /* Opera 7 */ }* html pre { word-wrap: break-word; /* Internet Explorer 5.5+ */ white-space : normal ; /* Internet Explorer 5.5+ */ }
具體設定方法是,進入你的部落格園後台》》》選項》》》config》》》通過CSS定製頁面
這樣設定主要是不讓代碼太寬,撐破頁面