这里就照着一个插件的实现步骤进行记录:
<a href="http://www.cnblogs.com/yjf512/archive/2012/05/13/2498400.html#section1">需求说明</a>
<a href="http://www.cnblogs.com/yjf512/archive/2012/05/13/2498400.html#section2">开发准备</a>
<a href="http://www.cnblogs.com/yjf512/archive/2012/05/13/2498400.html#section3">开发步骤</a>
<a href="http://www.cnblogs.com/yjf512/archive/2012/05/13/2498400.html#section4">参考文章</a>
需求:将文章中的<h1></h1>标题自动生成目录,并插入到文章头部去。(一个目录生成器)
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131906301274.png"></a>
原先的文章源码比如是这样的:
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131906305909.png"></a>
插件处理后文章源码就变为:
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131918119678.png"></a>
插件做的工作:
1 生成<p>...</p>的目录标签并放在文章最前端
2 将<h1>标签加上瞄点(比如<a name="section2"></a>)
1 安装Live Writer(假设Live Writer安装在:C:\Program Files (x86)\Windows Live\Writer)
2 VS开发环境
(ps: 如果使用VS2010的朋友在下面建立项目的时候请将VS的.net版本修改为.net 3.0, 小哥我亲身尝试过 .net4.0开发的插件是没法使用的!!)
WindowsLive.Writer.Api.dll: (这个dll在安装目录下,比如我这边是C:\Program Files (x86)\Windows Live\Writer)
System.Windows.Forms.dll
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131906337597.png"></a>
设置Build Events 的Post-build event comment
XCOPY /D /Y /R "$(TargetPath)" "C:\Program Files (x86)\Windows Live\Writer\Plugins\"
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131906372675.png"></a>
CreateContent
CreateContentFromLiveClipboard
CreateContentFromUrl
这三个方法最大的区别是content的出处不一样。大多数人使用CreateContent方法就可以,它是将选中的区域select作为content的引用传入函数。
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131906395300.png"></a>
按照msdn的描述,Class1 类做了几件事:
1 继承ContentSource
2 重写虚函数CreateContent
3 设置 InsertableContentSourceAttribute属性
4 设置Writer Plugin属性:
参数分别为:GUID,plugin显示名字,博客发布地址,插件描述
直接F6 Build就可以
如果出现了
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131906421623.png"></a>
请确保两件事:
1 Live Writer没有启动
2 VS是administrator权限
build成功之后,启动Live Writer
在
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131906443377.png"></a>
插入这一栏中能看到刚刚加入的插件了,如上图的Insert Dire。如果找不到,请检查上面的1-5步骤是否成功
在VS中:debug -- Attach to Process
<a href="http://images.cnblogs.com/cnblogs_com/yjf512/201205/201205131906473669.png"></a>
选择WindowsLiveWriter.exe进程
在Live Writer中点击插件,VS跳到断点处。
本示例的源码和dll存放在github:
<a href="https://github.com/jianfengye/WLWInsertDirectory">https://github.com/jianfengye/WLWInsertDirectory</a>
本文转自轩脉刃博客园博客,原文链接:http://www.cnblogs.com/yjf512/archive/2012/05/13/2498400.html,如需转载请自行联系原作者