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

(界面血漂亮)

默认安装到C:\Users\用户\AppData\Local\OpenLiveWriter目录,结构如下:

标红色的是OLW的主程序:

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

作为一个开发人员,对代码进行着色是不可缺少的,如何在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\用户\AppData\Local\OpenLiveWriter\app-0.6.0.0\Plugins目录下,启动并未有见插件

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

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

插件安装之后:

3、代码着色项目下载

3.1 项目下载

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

点击“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)修改输出地址:

OpenLiveWriter.CNBlogs.SourceCode类库输出地址:copy "$(TargetPath)" "C:\Users\xxtt\AppData\Local\OpenLiveWriter\app-0.6.0.0\Plugins"

(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语言,有点遗憾,期待更新!

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

最新文章

  1. JavaScript判断移动端及pc端访问不同的网站
  2. 杂项之pymysql连接池
  3. Hibernated的sql查询
  4. javascript 设计模式1----单例模式
  5. IT电子书网站下载
  6. docker offical docs:Working with Docker Images
  7. No 11.11 in my dictionary
  8. 关于Android WindowManager显示悬浮窗的动画效果
  9. PHP 魔术方法总结
  10. POJ 3671 Dining Cows (DP,LIS, 暴力)
  11. ZOJ 2562 More Divisors
  12. redhat 安装配置samba实现win共享linux主机目录
  13. Android音乐编程:管理音频焦点
  14. shell,bash,zsh,console,terminal到底是什么意思,它们之间又是什么关系?
  15. c 指针函数 vs 函数指针
  16. MySQL进程-状态等参数详解
  17. Windows系统内存分析工具的介绍
  18. Object-C-复制
  19. windows内存体系结构 内存查询,读,写(附录源码)
  20. oracle 数据库添加Java方法

热门文章

  1. JS 判断数据类型的三种方法
  2. JavaScript权威指南 - 对象
  3. Oracle安装部署,版本升级,应用补丁快速参考
  4. 易用BPM时代,企业如何轻松驾驭H3?
  5. Android之DOM解析XML
  6. SQLServer2005创建定时作业任务
  7. windows 7(32/64位)GHO安装指南(U盘制作篇)~
  8. [转]NopCommerce How to add a menu item into the administration area from a plugin
  9. 12个小技巧,让你高效使用Eclipse
  10. /etc/ppp/chap-secrets