Skip to content

Commit 74c8a1f

Browse files
committed
Adding howto file for diff.
1 parent 04cd8f2 commit 74c8a1f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

doc/howto.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
A simple diff of two strings:
3+
4+
> require("diff")
5+
> for _, token in ipairs(diff.diff("This is a test", "This was a test!")) do
6+
>> print(token[1], token[2])
7+
>> end
8+
This same
9+
is out
10+
was in
11+
same
12+
a same
13+
same
14+
test out
15+
test! in
16+
same
17+
18+
That is, diff.diff(old, new) returns a table of pairs, each consisting of a string
19+
and it's status: "same" (the string is present in both), "in" (the string appeared
20+
in <i>new</i>, or "out" (the string was present in <i>old</i> but was removed).
21+
22+
Alternatively, you can just generate an HTML for this diff:
23+
24+
> = diff.diff("This is a test", "This was a test!"):to_html()
25+
This <del>is</del><ins>was</ins> a <del>test</del><ins>test!</ins>
26+

0 commit comments

Comments
 (0)