0
点赞
收藏
分享

微信扫一扫

使用open live write发布的博客

写心之所想 2022-12-30 阅读 84

官方教程的FAQ:

包含了几个工具 可以都看看

--------------------------------------------------------------------------------

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​​

​​使用open live write发布的博客_github​​

​​使用open live write发布的博客_Windows_02​​(界面血漂亮)

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

​​使用open live write发布的博客_Code_03​​、

    标红色的是OLW的主程序:

​​使用open live write发布的博客_Windows_04​​

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

​​使用open live write发布的博客_Windows_05​​

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

2、如何实现代码着色

   前奏:从的官网获取,在windows live writer下,可用WindowsLiveWriter.CNs.CodeHighlighter进行代码着色,是有有效的

   实验:将WindowsLiveWriter.CNs.CodeHighlighter.dll插件放到C:\Users\用户\AppData\Local\OpenLiveWriter\app-0.6.0.0\Plugins目录下,启动并未有见插件

​​使用open live write发布的博客_Code_06​​

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

​​使用open live write发布的博客_github_07​​

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

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

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

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

   插件安装之后:

​​使用open live write发布的博客_Code_08​​

​​使用open live write发布的博客_Code_09​​

3、代码着色项目下载
3.1 项目下载

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

​​使用open live write发布的博客_github_10​​

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

​​使用open live write发布的博客_Code_11​​

    OpenLiveWriter.CNs.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.CNs.CodeHighlighter.dll):

private string RemoteCodeHighlight()
{
string requestUriString = "";
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#代码展示如上​​接口还不支持go语言,有点遗憾,期待更新!

为人:谦逊、激情、博学、审问、慎思、明辨、 笃行
学问:纸上得来终觉浅,绝知此事要躬行
为事:工欲善其事,必先利其器。
态度:道阻且长,行则将至;行而不辍,未来可期
.....................................................................
------- 换了个头像,静静的想,默默的思恋,一丝淡淡的忧伤 ----------
------- 桃之夭夭,灼灼其华。之子于归,宜其室家。 ---------------
------- 桃之夭夭,有蕡其实。之子于归,宜其家室。 ---------------
------- 桃之夭夭,其叶蓁蓁。之子于归,宜其家人。 ---------------
=====================================================================
转载请标注出处!



举报

相关推荐

0 条评论