zoukankan      html  css  js  c++  java
  • OpenLiveWriter代码插件

    1、OpenLiveWriter安装

         Windows Live Writer在2012年就停止了更新,Open Live Writer(以下简称OLW)是由Windows Live WriterWriter更名而来,是由微软推出的一款能够免费使用的博客写作软件,主要为用户提供博客在线撰写和编辑功能,相比Windows Live Writer,OLW首个版本仍然缺少一些功能,不过团队已经制订了更新路线图,一些新功能会陆续推出。相信以后他将是一个写博客的好利器。

        但从github源代码(https://github.com/OpenLiveWriter/OpenLiveWriter)来看,已经有9个月未更新了,而官网更是未见一个插件,“钱途”堪忧呀。

        官网地址:http://openlivewriter.org/ 点击download下载:https://openlivewriter.azureedge.net/stable/Releases/OpenLiveWriterSetup.exe

        image

        image(界面血漂亮)

       默认安装到C:Users用户AppDataLocalOpenLiveWriter目录,结构如下:

       image

        标红色的是OLW的主程序:

        image

        双击OpenLiveWriter.exe即可打开OLW编辑器:

        image

        作为一个开发人员,对代码进行着色是不可缺少的,如何在OLW下实现插入代码并着色呢?

    2、如何实现代码着色

       前奏:从cnblogs的官网获取,在windows live writer下,可用WindowsLiveWriter.CNBlogs.CodeHighlighter进行代码着色,是有有效的,详情查看:http://www.cnblogs.com/cmt/archive/2009/11/27/1611900.html

       实验:将WindowsLiveWriter.CNBlogs.CodeHighlighter.dll插件放到C:Users用户AppDataLocalOpenLiveWriterapp-0.6.0.0Plugins目录下,启动并未有见插件

       image

        分析:通过调试OLW的源码代码调试,加载插件出现异常;通过ILSpy分析WindowsLiveWriter.CNBlogs.CodeHighlighter.dll,如下图

    image

       WindowsLiveWriter.CNBlogs.CodeHighlighter.dll引用WindowsLive.Writer.Api,与现有OLW的新接口OpenLiveWriter.Api不匹配。

       解决方案一:反编译WindowsLiveWriter.CNBlogs.CodeHighlighter.dll修改引用类库,将WindowsLive.Writer.Api.dll更改为OpenLiveWriter.Api.dll,不建议使用本方法。

       解决方案二:由于是从Windows Live Writer Source Code plugin for SyntaxHighlighter(http://sourcecodeplugin.codeplex.com/)进行优化而来,可以从本开源项目进行优化。

       封装编译之后的dll为:OpenLiveWriter.CNBlogs.SourceCode.dll,下载地址为:OpenLiveWriter.CNBlogs.SourceCode.zip

       插件安装之后:

       image

        image

    3、代码着色项目下载

    3.1 项目下载

       (1)原始项目下载地址:http://sourcecodeplugin.codeplex.com/SourceControl/latest

        image

        点击“download”下载,只需按照3.2修订WindowsLiveWriter.SourceCode项目编译。

       (2)修改后的项目可从github下载:

        https://github.com/zsy619/OpenLiveWriter.SourceCode,下载编辑即可使用。

    3.2 编译配置

       (1)修改类库引用,WindowsLive.Writer.Api.dll更改为OpenLiveWriter.Api.dll(可以从OLW安装的目录下找到)

       (2)修改输出地址:

       image

        OpenLiveWriter.CNBlogs.SourceCode类库输出地址:copy "$(TargetPath)" "C:UsersxxttAppDataLocalOpenLiveWriterapp-0.6.0.0Plugins"

       (3)CodeForm窗体代码修订

        修改Code属性:

            public string Code
            {
                get
                {
                    return this._code;
                }
                set
                {
                    this._code = value;
                }
            }

       新增博客园的远程代码着色方法(可参考WindowsLiveWriter.CNBlogs.CodeHighlighter.dll):

            private string RemoteCodeHighlight()
            {
                string requestUriString = "http://util.cnblogs.com/CodeHighlight/LiveWriterHightlight";
                HttpWebRequest httpWebRequest = WebRequest.Create(requestUriString) as HttpWebRequest;
                httpWebRequest.Method = "POST";
                httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                string value = string.Format("language={0}&code={1}", HttpUtility.UrlEncode(this.comboBrush.Text.Trim()), HttpUtility.UrlEncode(this.textCode.Text.Trim()));
                using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    streamWriter.Write(value);
                }
                string result;
                using (WebResponse response = httpWebRequest.GetResponse())
                {
                    using (StreamReader streamReader = new StreamReader(response.GetResponseStream()))
                    {
                        result = streamReader.ReadToEnd();
                    }
                }
                return result;
            }

        修改buttonOK_Click方法:

            private void buttonOK_Click(object sender, EventArgs e)
            {
                this._configDb.Config.Brush = this.comboBrush.Text;
                this._configDb.Config.MainFormX = base.Left;
                this._configDb.Config.MainFormY = base.Top;
                this._configDb.Config.MainFormWidth = base.Width;
                this._configDb.Config.MainFormHeight = base.Height;
                this._configDb.SavePluginConfigurationData();
                try
                {
                    this._code = this.RemoteCodeHighlight();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                base.DialogResult = DialogResult.OK;
                base.Close();
            }

    3.3 使用效果

        C#代码展示如上,目前CNBlogs官网http://util.cnblogs.com/CodeHighlight/LiveWriterHightlight接口还不支持go语言,有点遗憾,期待更新!

        温馨提示:有用就帮忙推荐一下,谢谢~~

  • 相关阅读:
    C# 文本,图片 与 Base64的相互转换
    vue3.x 中的自定义组件及使用
    vue 的TodoList 小Demo
    vue中的条件渲染 v-show、v-if、v-else、v-else-if
    vue 使用$refs获取表单内容及v-model双向数据绑定
    python-异常处理&操作数据库&网络编程
    python-接口开发
    python-数据库&邮件
    python-函数和模块
    python-函数&list&dic&集合&文件读取
  • 原文地址:https://www.cnblogs.com/zsy/p/5859928.html
Copyright © 2011-2022 走看看