33 <td class =" lineNum" >
44 {{ data.lineNum }}
55 </td >
6- <td ref = " code " class =" code" >
7- <pre ><code :class =" `language-${language}`" v-html =" data.value " ></code ></pre >
6+ <td class =" code" >
7+ <pre ><code ref = " codeRef " :class =" `language-${language}`" v-html =" code " ></code ></pre >
88 </td >
99 </tr >
1010</template >
1111
1212<script lang="ts">
13- import { defineComponent , PropType , ref , onMounted } from ' vue'
13+ // @ts-ignore
14+ import { encode } from ' html-entities'
15+ import { defineComponent , PropType , ref , onMounted , watch , nextTick , computed } from ' vue'
1416import { Prism } from ' ./index'
15- import { Line } from ' ./utils'
17+ import { MODIFIED_TAG , Line } from ' ./utils'
1618
1719export default defineComponent ({
1820 props: {
@@ -25,34 +27,52 @@ export default defineComponent({
2527 required: true
2628 }
2729 },
28- setup () {
29- const code = ref (null )
30+ setup (props ) {
31+ const codeRef = ref (null )
32+ const code = computed (() => {
33+ return encode (props .data .value )
34+ .replace (new RegExp (` <${MODIFIED_TAG }> ` , ' gi' ), ' <span class="token modified">' )
35+ .replace (new RegExp (` </${MODIFIED_TAG }> ` , ' gi' ), ' </span>' )
36+ })
3037
3138 onMounted (() => {
32- Prism .highlightAllUnder (code .value as unknown as HTMLElement )
39+ watch (() => props .data .value , () => {
40+ nextTick (() => Prism .highlightElement (codeRef .value as unknown as HTMLElement ))
41+ }, { immediate: true })
3342 })
3443
35- return { code }
44+ return { codeRef , code }
3645 }
3746})
3847 </script >
3948
4049<style scoped lang="scss">
4150td {
42- padding : 0 10 px ;
51+ padding : 0 0.5 em ;
4352
4453 & .lineNum {
4554 width : 2em ;
4655 text-align : right ;
4756 color : #999 ;
4857 font-size : 0.9em ;
4958 }
59+
60+ pre [class *= " language-" ]:before {
61+ display : inline-block ;
62+ position : absolute ;
63+ left : 0 ;
64+ top : 0 ;
65+ opacity : 0.8 ;
66+ }
5067}
5168
5269pre [class *= " language-" ] {
53- padding : 0 ;
70+ display : block ;
71+ position : relative ;
5472 margin : 0 ;
55- overflow : auto ;
73+ padding : 0 ;
74+ padding-left : 1.5em ;
75+ overflow : visible ;
5676 background : none ;
5777 border-radius : 0 ;
5878}
@@ -63,6 +83,21 @@ tr.vue-diff-row-removed td {
6383 :deep (.token.modified ) {
6484 background-color : rgba (255 , 0 , 0 , .3 );
6585 }
86+
87+ pre [class *= " language-" ]:before {
88+ content : " -" ;
89+ }
90+
91+ }
92+
93+ .vue-diff-viewer-prev {
94+ tr .vue-diff-row-added td {
95+ background-color : rgba (128 , 128 , 128 , 0.1 );
96+
97+ pre [class *= " language-" ]:before {
98+ display : none ;
99+ }
100+ }
66101}
67102
68103tr .vue-diff-row-added td {
@@ -71,5 +106,19 @@ tr.vue-diff-row-added td {
71106 :deep (.token.modified ) {
72107 background-color : rgba (0 , 255 , 128 , .3 );
73108 }
109+
110+ pre [class *= " language-" ]:before {
111+ content : " +" ;
112+ }
113+ }
114+
115+ .vue-diff-viewer-current {
116+ tr .vue-diff-row-removed td {
117+ background-color : rgba (128 , 128 , 128 , 0.1 );
118+
119+ pre [class *= " language-" ]:before {
120+ display : none ;
121+ }
122+ }
74123}
75124 </style >
0 commit comments