File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments