6
6
7
7
<script >
8
8
import {createPatch } from ' diff'
9
- import { Diff2Html } from ' diff2html'
9
+ import * as Diff2Html from ' diff2html'
10
10
import hljs from ' highlight.js'
11
11
import ' highlight.js/styles/googlecode.css'
12
- import ' diff2html/dist/ diff2html.css'
12
+ import ' diff2html/bundles/css/ diff2html.min .css'
13
13
export default {
14
14
name: ' code-diff' ,
15
15
props: {
@@ -28,6 +28,26 @@ export default {
28
28
outputFormat: {
29
29
type: String ,
30
30
default: ' line-by-line'
31
+ },
32
+ drawFileList: {
33
+ type: Boolean ,
34
+ defalut: false
35
+ },
36
+ renderNothingWhenEmpty: {
37
+ type: Boolean ,
38
+ default: false
39
+ },
40
+ diffStyle: {
41
+ type: String ,
42
+ default: ' word'
43
+ },
44
+ fileName: {
45
+ type: String ,
46
+ default: ' '
47
+ },
48
+ isShowNoChange: {
49
+ type: Boolean ,
50
+ default: false
31
51
}
32
52
},
33
53
directives: {
@@ -40,18 +60,32 @@ export default {
40
60
},
41
61
computed: {
42
62
html () {
43
- return this .createdHtml (this .oldString , this .newString , this .context , this .outputFormat )
63
+ return this .createdHtml (this .oldString , this .newString , this .context , this .outputFormat , this . drawFileList , this . renderNothingWhenEmpty , this . fileName , this . isShowNoChange )
44
64
}
45
65
},
46
66
methods: {
47
- createdHtml (oldString , newString , context , outputFormat ) {
67
+ createdHtml (oldString , newString , context , outputFormat , drawFileList , renderNothingWhenEmpty , fileName , isShowNoChange ) {
48
68
function hljs (html ) {
49
69
return html .replace (/ <span class="d2h-code-line-ctn">(. +? )<\/ span>/ g , ' <span class="d2h-code-line-ctn"><code>$1</code></span>' )
50
70
}
51
- let args = [' ' , oldString, newString, ' ' , ' ' , {context: context}]
71
+ if (isShowNoChange) {
72
+ oldString = ' File Without Change\t OldString: ======================== \n ' + oldString
73
+ newString = ' File Without Change\t NewString: ======================== \n ' + newString
74
+ }
75
+ let args = [fileName, oldString, newString, ' ' , ' ' , {context: context}]
52
76
let dd = createPatch (... args)
53
- let outStr = Diff2Html .getJsonFromDiff (dd, {inputFormat: ' diff' , outputFormat: outputFormat, showFiles: false , matching: ' lines' })
54
- let html = Diff2Html .getPrettyHtml (outStr, {inputFormat: ' json' , outputFormat: outputFormat, showFiles: false , matching: ' lines' })
77
+ let outStr = Diff2Html .parse (dd, {
78
+ inputFormat: ' diff' ,
79
+ outputFormat: outputFormat,
80
+ drawFileList: drawFileList,
81
+ matching: ' lines' ,
82
+ renderNothingWhenEmpty: renderNothingWhenEmpty})
83
+ let html = Diff2Html .html (outStr, {
84
+ inputFormat: ' json' ,
85
+ outputFormat: outputFormat,
86
+ drawFileList: drawFileList,
87
+ matching: ' lines' ,
88
+ renderNothingWhenEmpty: renderNothingWhenEmpty})
55
89
return hljs (html)
56
90
}
57
91
}
0 commit comments