『7x24小时有问必答』
说到对比两个文件差异,对于我们程序员来说,可以说是天天碰到。我们经常需要对比两份代码是否不同。但今天给大家推荐的是,一个对比两份Html代码最终效果差异的项目。

项目简介
一个基于.Net 4.5开发的对比Html文件、片段效果差异的项目。两份Html效果不一样的地方会通过颜色、删除线、背景色分别标记出来。

该项目使用场景一般是针对一些文章排版、错别字显示等情况,项目比较简单,感兴趣的可以了解下。

技术架构
1、平台:基于.Net Framework 4.5、netstandard2.0开发

2、开发工具:Visual Studio 2017
项目结构
使用方法
对比Html片段
var oldText = @"

This is some sample text to demonstrate the capability of the HTML diff tool.

It is based on the Ruby implementation found here. Note how the link has no tooltip

What about a number change: 123456?

Some sample textSome sample value
Data 1 (this row will be removed)Data 2
                    Here is a number 2 32


                    This date: 1 Jan 2016 is about to change (note how it is treated as a block change!)";

var newText = @"

This is some sample text to demonstrate the awesome capabilities of the HTML diff tool.



Extra spacing here that was not here before.

It is based on the Ruby implementation found here. Note how the link has a tooltip now and the HTML diff algorithm has preserved formatting.

What about a number change: 123356?

Some sample bold textSome sample value
                    Here is a number 2 32


                    This date: 22 Feb 2017 is about to change (note how it is treated as a block change!)";

var diffHelper = new HtmlDiff.HtmlDiff(oldText, newText);
litOldText.Text = oldText;
litNewText.Text = newText;

// Lets add a block expression to group blocks we care about (such as dates)
diffHelper.AddBlockExpression(new Regex(@"[\d]{1,2}[\s]*(Jan|Feb)[\s]*[\d]{4}", RegexOptions.IgnoreCase));

litDiffText.Text = diffHelper.Build();

效果

通过效果图,我们可以看出:
1、不一样的地方,通过橙色背景色标记;
2、增加的地方,通过绿色背景色标记;
3、删除的地方,通过粉色背景色+删除线标记。

自定义对比效果
标记效果,也可以自定义,只需在Css文件修改样式
/* ***************************************
** Diff related styles
*****************************************/

ins {
background-color: #cfc;
text-decoration:inherit;

}

del {
color: #999;
background-color:#FEC8C8;
}

ins.mod {
background-color: #FFE1AC;
}

项目地址:https://github.com/Rohland/htmldiff.net

- End -
推荐阅读

专注分享编程知识、热门有用有趣的开源项目
觉得好看 点个在看
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

上一主题上一主题         下一主题下一主题
QQ手机版小黑屋粤ICP备17165530号

关于我们·投诉举报· 用户帮助· 联系我们 · 本站服务 · 版权声明· 隐私政策 · 投搞指南

法律保护:PLC技术网,plcjs.com,plcjs.net等字样
Copyright 2010-2030. All rights reserved. 


微信公众号二维码 抖音二维码 百家号二维码 今日头条二维码哔哩哔哩二维码