forked from netj/markdown-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.md.in
104 lines (73 loc) · 2.61 KB
/
README.md.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Markdown-Diff
Markdown-Diff annotates word [diff][]s of [Markdown][] documents for easier review.
It reformats the output of [`wdiff`][] or `git --word-diff` in Markdown, so the changes to a Markdown document can be viewed inline.
It can also summarize commit history of Markdown documents in a Git repository as well as the changes made to them.
[Markdown]: https://en.wikipedia.org/wiki/Markdown
[diff]: https://en.wikipedia.org/wiki/Diff
[`wdiff`]: http://www.gnu.org/software/wdiff/
## Usage
### Download and Install the Scripts
* [markdown-format-wdiff](https://raw.github.com/netj/markdown-diff/master/markdown-format-wdiff)
* [markdown-git-changes](https://raw.github.com/netj/markdown-diff/master/markdown-git-changes)
Mark them as executable and put them in a directory that's on your `$PATH`, e.g., `~/bin/` or `/usr/local/bin/`, as shown in the following list of commands:
```bash
curl -RL \
-O https://raw.github.com/netj/markdown-diff/master/markdown-format-wdiff \
-O https://raw.github.com/netj/markdown-diff/master/markdown-git-changes
chmod +x markdown-format-wdiff markdown-git-changes
mkdir -p ~/bin
mv -f markdown-format-wdiff markdown-git-changes ~/bin/
export PATH=~/bin:"$PATH"
```
### Use with GNU wdiff
```bash
wdiff old.md new.md | markdown-format-wdiff >changes.md
```
### Use with Git
```bash
markdown-git-changes origin/master README.md >changes.md
```
### View the Output
```bash
# use a Markdown preview app, such as Marked
open changes.md
# or, compile it into HTML and view with your web browser
npm -g install marked
marked changes.md >changes.html
open changes.html
```
----
## An Example
<$ cd example $>
### old.md: Before Revision
```markdown
<$ cat old.md $>
```
<$ cat old.md | sed 's|^|> |' $>
### new.md: After Revision
```markdown
<$ cat new.md $>
```
<$ cat new.md | sed 's|^|> |' $>
### Unified Diff
Here's a unified diff of the two Markdown documents shown above. It's very hard to even recognize that there're any differences between the two.
```bash
diff -u old.md new.md
```
```diff
<$ diff -u old.md new.md | tee changes.diff $>
```
### Word Diff
Here's a word diff of them generated by GNU wdiff, which is slightly better for spotting the changes, but still ugly.
```bash
wdiff old.md new.md
```
```markdown
<$ wdiff old.md new.md | tee changes.wdiff $>
```
### Markdown-Diff
Finally, here's the word diff formatted by Markdown-Diff, which displays the changes on top of the actually rendered document, making the review very productive.
```bash
wdiff old.md new.md | markdown-format-wdiff
```
<$ wdiff old.md new.md | ../markdown-format-wdiff | tee changes.md | sed 's|^|> |' $>