我有一段文本的两个版本,我想生成其修订版的 HTML View ,类似于 Google Docs 或 Stack Overflow 显示的内容。我需要在 Python 中执行此操作。我不知道这种技术叫什么,但我假设它有一个名字,希望有一个 Python 库可以做到这一点。
版本 1:
William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.
版本 2:
William Henry "Bill" Gates III (born October 28, 1955)[2] is a business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen. He is American.
期望的输出:
William Henry "Bill" Gates III (born October 28, 1955)[2] is a
n Americanbusiness magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen. He is American.
使用 diff 命令不起作用,因为它告诉我哪些行不同,但没有告诉我哪些列/词不同。
$ echo 'William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.' > oldfile
$ echo 'William Henry "Bill" Gates III (born October 28, 1955)[2] is a business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen. He is American.' > newfile
$ diff -u oldfile newfile
--- oldfile 2010-04-30 13:32:43.000000000 -0700
+++ newfile 2010-04-30 13:33:09.000000000 -0700
@@ -1 +1 @@
-William Henry "Bill" Gates III (born October 28, 1955)[2] is an American business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen.
+William Henry "Bill" Gates III (born October 28, 1955)[2] is a business magnate, philanthropist, and chairman[3] of Microsoft, the software company he founded with Paul Allen. He is American.' > oldfile
最佳答案
Google Diff Merge Patch在纯 python 中有一个很好的 diff 实现。
关于python - 在 Python 中生成文本修订历史的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2747600/