让我们创建一个windows live writer的代码插入插件,按照你提供的步骤进行:
- 创建新的类库项目:
首先,我们需要在Visual Studio中创建一个新的类库项目。我们将这个项目命名为
LiveWriterCodePlugin。
- 添加必要的引用:
我们需要添加两个关键引用:
using WindowsLive.Writer.Api; using System.Windows.Forms;
第一个引用(
WindowsLive.Writer.Api)的DLL文件位于Windows Live Writer安装目录的根目录下,文件名为
WindowsLive.Writer.Api.dll。我们需要手动添加这个引用。
第二个引用(
System.Windows.Forms)是.NET Framework的一部分,Visual Studio会自动添加。
- 添加处理用户插入代码的类文件:
我们将创建一个名为
ContentProcessor的静态类,用于处理用户插入的代码:
using System.Web;", HttpUtility.HtmlEncode(originalContent)) : string.Empty); }public static class ContentProcessor { public static string ProcessedContent { get; private set; }
public static void Process(string originalContent) { ProcessedContent = (!string.IsNullOrEmpty(originalContent) ? string.Format("
}
- 创建Windows Form窗体:
我们将创建一个简单的Windows Form窗体,用于让用户输入代码。窗体中包含一个文本框和一个确定按钮。

为确定按钮添加点击事件处理程序:
易优制冷机械设备网站源码是基于易优cms开发,适合企业进行制冷设备展示使用。程序内核为Thinkphp5.0开发,后台简洁,为企业网站而生。 这是一套安装就能建站的程序,不定期更新程序BUG,更新网站功能。 我们提供的不仅是模板这么简单,我们还提供程序相关咨询、协助安装等服务。 默认不包含小程序插件,需要另外单独购买插件。 模板安装步骤 1、请将安装包ZIP上
private void button1_Click(object sender, EventArgs e)
{
ContentProcessor.Process(this.textBox1.Text);
this.Close();
}- 创建插件类文件:
我们将创建一个继承自
ContentSource的类,用于实现Windows Live Writer插件的功能:
[WriterPlugin("7c371eef-e350-4aae-af28-91613a9137e3", "xland", Description = "insert code plugin", Name = "xland", PublisherUrl = "https://www.php.cn/link/91a8651859745d25095a46fdda893cfa")]
[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);
}
}- 部署插件:
完成开发后,我们需要将生成的DLL文件放置在Windows Live Writer的安装目录下的
Plugins文件夹中。
- 使用插件:
现在,我们可以在Windows Live Writer中使用这个插件来插入代码。

- 自定义博客样式:
为了让插入的代码在博客中显示得更好,我们可以在博客园后台通过CSS定制页面,添加以下样式:
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+ /
}
这个样式可以防止代码行过长而撑破页面。
源代码下载:https://www.php.cn/link/7577c54ea4b4258f50a4477dbd1bca3a
通过以上步骤,我们就完成了一个简单的Windows Live Writer代码插入插件的开发和部署。










