簡單的windows live writer代碼外掛程式(含源碼)

來源:互聯網
上載者:User

建立一個類庫

添加兩個關鍵引用

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定製頁面
這樣設定主要是不讓代碼太寬,撐破頁面

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.