-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.htm
52 lines (46 loc) · 2.33 KB
/
index.htm
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
<!DOCTYPE html>
<html>
<head>
<title>htmldiff.js example</title>
<style type="text/css">
table {
border: 1px solid #d9d9d9;
}
td {
border: 1px solid #d9d9d9;
padding: 3px;
}
/* Diff related styles */
ins {
background-color: #cfc;
text-decoration: inherit;
}
del {
color: #999;
background-color: #FEC8C8;
}
ins.mod {
background-color: #FFE1AC;
}
</style>
</head>
<body>
<h1>htmldiff.js Example</h1>
<h2>Old Text</h2>
<div class="old-text"></div>
<h2>New Text</h2>
<div class="new-text"></div>
<h2>Diff</h2>
<div class="diff-text"></div>
<script src="html-diff.js"></script>
<script type="text/javascript">
var oldText = '<p>This is some sample text to demonstrate the capability of the <strong>HTML diff tool</strong>.</p><p>It is based on the C# implementation found <a href="https://github.com/Rohland/htmldiff.net">here</a> that is based off of the Ruby implementation found <a href="http://github.com/myobie/htmldiff">here</a>. Note how the link has no tooltip</p><table cellpadding="0" cellspacing="0"><tr><td>Some sample text</td><td>Some sample value</td></tr><tr><td>Data 1 (this row will be removed)</td><td>Data 2</td></tr></table>';
var newText = '<p>This is some sample text to demonstrate the awesome capabilities of the <strong>HTML diff tool</strong>.</p><br/><br/>Extra spacing here that was not here before.<p>It is based on the C# implementation found <a href="https://github.com/Rohland/htmldiff.net">here</a> that is based off of the Ruby implementation found <a title="Cool tooltip" href="http://github.com/myobie/htmldiff">here</a>. Note how the link has a tooltip now and the HTML diff algorithm has preserved formatting.</p><table cellpadding="0" cellspacing="0"><tr><td>Some sample <strong>bold text</strong></td><td>Some sample value</td></tr></table>';
var htmlDiff = new HtmlDiff(oldText, newText);
var output = htmlDiff.Build();
document.getElementsByClassName('old-text')[0].innerHTML = oldText;
document.getElementsByClassName('new-text')[0].innerHTML = newText;
document.getElementsByClassName('diff-text')[0].innerHTML = output;
</script>
</body>
</html>