21
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HTMLでdiffを表示させてみる

Last updated at Posted at 2018-01-14

diff.jsdiff2htmlを用いてdiff画面を表示してみました。

概要

diff.jsを用いてunified diffを作成して、それをdiff2htmlに渡して表示しているだけです。

ソース

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>vue_pager</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/diff2html/2.3.3/diff2html.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsdiff/3.4.0/diff.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/diff2html/2.3.3/diff2html.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/diff2html/2.3.3/diff2html-ui.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const unifiedDiff = JsDiff.createPatch("fileName", "a\nb\nc\d\ne\n\nf", "a\nb\nac\d\ne\n\n\nf", "test", "test");
    const diff2htmlUi = new Diff2HtmlUI({diff: unifiedDiff});
    diff2htmlUi.draw('#app', {inputFormat: 'json', showFiles: true, matching: 'lines'});
});
</script>
</head>
<body>
<div id="app">
</div>
</body>
</html>

確認

参考

21
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?