发布一个最新版Productivity Power Tools中的CopyAsHtml扩展的修改版(含工具和源码)
2011-02-25 09:16
519 查看
发布一个最新版Productivity Power Tools中的CopyAsHtml扩展的修改版(含工具和源码)
Productivity Power Tools是微软官方发布的一个用于VS2010的扩展,功能是在Visual Studio的文本编辑器中按下Ctrl+C或通过其它方式执行“复制”或者“剪切”功能的时候,生成一份HTML格式的源码放到剪贴板中,此时可以在网页编辑器、网页中的可视化编辑器中直接粘贴出和VS中格式相同的源码。今天这个工具发布了最新的版本,其中CopyAsHtml组件进行了更新,加入了选项对话框,个人觉得这个比较实用,所以将原来的组件修改迁移到这个版本中。值得一提的,原来我发布的修改版存在一个BUG,就是当选择的内容存在不需要的缩进时,会导致缩进丢失,感谢之前mangohappy给我的反馈和在我发布的源码基础上进行的改进。
1.这个和官方的组件相比有和更改?
和官方组件相比,变更如下:允许在生成最终代码时,忽略部分VS的文字编辑器样式(比如背景色,文字大小,文字样式等等)
使用OL来代替Pre显示代码区域,并允许加上class类名以便于在网页中进行代码样式的微调,支持显示行号(可以通过后期定义样式隐藏)
能在复制或剪切时自动移除公共缩进(见后说明,仅针对HTML)
2.什么是自动移除公共缩进?
这里指的公共缩进,就是指下面这个代码片段中所标注的区域:如果要复制这个方法,修改后的扩展在复制后将会自动将红框中的缩进删除掉,于是复制出来的代码是这样的:
public string GenerateHtml(NormalizedSnapshotSpanCollection spans, IWpfTextView textView)
{
if ((spans == null) || (spans.Count == 0))
{
return "";
}
((_DTE) this._serviceProvider.GetService(typeof(_DTE))).get_Properties("Productivity Power Tools", "HTML Copy");
IClassificationFormatMap classificationFormatMap = this._classificationFormatMappingService.GetClassificationFormatMap(textView);
IClassificationType classificationType = this._classificationTypeRegistry.GetClassificationType("text");
HtmlMarkupProvider htmlMarkupProvider = new HtmlMarkupProvider(classificationFormatMap, classificationType, textView);
IClassifier classifier = this._classifierAggregatorService.GetClassifier(textView.TextBuffer);
string str = new FormattedStringBuilder(htmlMarkupProvider, classifier, classificationType).AppendSnapshotSpans(spans);
IDisposable disposable = classifier as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
return str;
}
3.选项对话框的说明
我对选项对话框进行了修改,删除了一个选项,添加了几个选项:4.如何重定义代码块样式
建议在上述的选项对话框中设置CodeBlockClassName,这样通过ol.CodeBlockClassName既可以重新设置样式。比如我的博客中重定义的样式如下,需要的同学可以参考下:ol.codeBlock{
border: 1px dotted #6C93FF;
line-height:150%;
word-break:break-word;
font-family: Consolas, Verdana !important;
border-radius:5px;
}
ol.codeBlock font{
font-size:12px!important;
}
ol.codeBlock{
background-color: #E3E3FF !important;
list-style-position: outside;
margin-left:0px;
}
ol.codeBlock li{
background-color: #fff;
padding-left: 5px;
border-left: 1px solid #8A8AFF;
margin-left:50px;
}
ol.codeBlock li:nth-child(even){
background-color: #f5f5f5;
}
5.如何使用
下载附件,将解压后的 CopyAsHtml.dll 解压到 "%LocalAppData%\Microsoft\VisualStudio\10.0\Extensions\Microsoft\Productivity Power Tools\10.0.20214.15" 下并覆盖已有文件即可。源码需要VS2010才能打开。
6.下载链接
DLL下载:http://www.u-tide.com/fish/Service.asmx/Download/30/25源码下载:http://www.u-tide.com/fish/Service.asmx/Download/30/26
发布页面:http://www.u-tide.com/fish/soft/copyAsHtml_For_ProductiveTools2010/
最后发个疑问。为啥官方的扩展中这个dll只有25K,为啥我编译的会有40K呢?搞不明白。
相关文章推荐
- 分享一个VisualStudio2010插件——Productivity Power Tools
- 发布一个IP修改的工具
- Productivity Power Tools 动画演示--给力的插件工具
- Productivity Power Tools(Visual Studio 扩展) 最新亮点
- Productivity Power Tools(Visual Studio 扩展) 最新亮点
- 使用 Productivity Power Tools 高级扩展 来帮助你提高 VS2012 的工作效率
- Productivity Power Tools(Visual Studio 扩展) 最新亮点
- Productivity Power Tools(Visual Studio 扩展) 最新亮点
- 使用 Productivity Power Tools 高级扩展 来帮助你提高 VS2012 的工作效率
- Productivity Power Tools 是微软官方推出的 Visual Studio 扩展
- 使用 Productivity Power Tools 高级扩展 来帮助你提高 VS2012 的工作效率
- 分享一个小工具,提供源码,以便根据自己需要进行修改
- 使用 Productivity Power Tools 高级扩展 来帮助你提高 VS2012 的工作效率
- 一个快速查看API的汇编和机器码的工具.发布源码
- Productivity Power Tools工具
- VS扩展:标签左置 — productivity power tools
- VS扩展:标签左置 — productivity power tools
- 使用 Productivity Power Tools 高级扩展 来帮助你提高 VS2012 的工作效率
- Productivity Power Tools,对于Visual Studio 2017的15个扩展
- 发布一个很COOL的图片验证码程序[含源码](转)