我想显示相同内容的版本之间的差异。最初我推出了自己的 WebControl,但是我想出的差分算法有点幼稚。
有人知道互联网上可能有用的 .Net 代码或 WebControl 吗? stackoverflow 使用的实现正是我正在寻找的东西,例如:
更新:2008 年 12 月 12 日 我已将 jsdiff 实现包装到一个独立的 Web 控件程序集中,并将其上传到 MSDN 代码库 Text differencing and syntax highlighting ASP.Net WebControls .
更新:2008 年 11 月 12 日 遇到以下javascript differencing library 。将尝试将其包装在自定义 WebControl 中。输出看起来与 stackoverflow 使用的类似:
最佳答案
我使用你提到的js库。
将 .js 文件包含在脚本标记内,将名为 asp:Literal 的内容添加到页面
<asp:Literal ID="litCompare" runat="server">
</asp:Literal>
并添加到代码隐藏:
litComparison.Text = "<pre id=\"lbDiffPre\" class=\"code\"> </pre>";
ClientScript.RegisterStartupScript(GetType(), "calccompare",
@"document.getElementById('lbDiffPre').innerHTML =
diffString(document.getElementById('" + edit1.ClientID + "').value,
document.getElementById('" + edit2.ClientID + "').value).
replace(/\r\n/g, '<br>';", true);
在我的例子中,我有 2 个控件也显示原始值,您可能希望将字符串字面地包含在 diffString() 函数中。额外的replace()将\r\n换行符转换为HTML换行符。
关于用于显示内容的修订或差异的 ASP.NET WebControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/359214/