转换差异以降价带删除线? [英] Convert diff to markdown with strikeout?
问题描述
我想差异
的输出转换(在降价文件)
降价与<罢工>
和< EM>
标签,这样我可以看到什么了
被移离或添加到文档的新版本。 (这种
治疗是法律文件很常见的。)
I'd like to convert the output of diff
(on a Markdown file) to
Markdown with <strike>
and <em>
tags, so that I can see what has
been removed from or added to a new version of a document. (This kind of
treatment is very common for legal documents.)
的希望的输出例:
为什么的<击>我们击>学习编程语言的?的不是罢工>的<击>的不的顺序到...
Why do we
Westudy programming languages?notNot in order to ...
其中的许多 困难的是,差异的输出是面向行的,在这里我想 看到个别字的差异。有没有人有建议, 要使用什么算法,或建立在什么软件?
One of the many difficulties is that diff's output is line-oriented, where I want to see differences in individual words. Does anyone have suggestions as to what algorithm to use, or what software to build on?
推荐答案
使用 wdiff 。它已经做了你要找的字的字比较;它的输出转换成降价应该只是一些简单的规律EX pressions。
Use wdiff. It already does the word-by-word comparison you're looking for; converting its output to markdown should take just a few simple regular expressions.
例如:
$ cat foo
Why do we study programming languages? Not in order to
$ cat bar
We study programming languages not in order to
$ wdiff foo bar
[-Why do we-]{+We+} study programming [-languages? Not-] {+languages not+} in order to
$ wdiff foo bar | sed 's|\[-|<em>|g;s|-]|</em>|g;s|{+|<strike>|g;s|+}|</strike>|g'
<em>Why do we</em><strike>We</strike> study programming <em>languages? Not</em> <strike>languages not</strike> in order to
编辑:其实,wdiff有一些选项,使其更容易:
Actually, wdiff has some options that make it even easier:
$ wdiff -w '<em>' -x '</em>' -y '<strike>' -z '</strike>' foo bar
<em>Why do we</em><strike>We</strike> study programming <em>languages? Not</em> <strike>languages not</strike> in order to
这篇关于转换差异以降价带删除线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!