Convert diff to markdown with strikeout?

前端 未结 3 584
别跟我提以往
别跟我提以往 2021-02-08 12:55

I\'d like to convert the output of diff (on a Markdown file) to Markdown with and tags, so that I can see what h

3条回答
  •  广开言路
    2021-02-08 13:21

    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.

    For example:

    $ 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|\[-||g;s|-]||g;s|{+||g;s|+}||g'
    Why do weWe study programming languages?  Not languages not in order to
    

    Edit: Actually, wdiff has some options that make it even easier:

    $ wdiff -w '' -x '' -y '' -z '' foo bar
    Why do weWe study programming languages?  Not languages not in order to
    

提交回复
热议问题