File tree Expand file tree Collapse file tree 5 files changed +55
-33
lines changed Expand file tree Collapse file tree 5 files changed +55
-33
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable global-require */
2
2
/* eslint-disable import/no-extraneous-dependencies */
3
3
import fs from 'fs' ;
4
- import hljs from 'highlight.js/lib/highlight' ;
5
- import javascript from 'highlight.js/lib/languages/javascript' ;
6
- import xml from 'highlight.js/lib/languages/xml' ;
7
- import 'highlight.js/styles/atom-one-light.css' ;
8
-
9
4
import Container from './helper/container.vue' ;
10
5
import Card from './helper/card.vue' ;
11
6
import Basic from './demo/Basic.vue' ;
@@ -23,9 +18,6 @@ import Disabled from './demo/Disabled.vue';
23
18
import docEn from './en.md' ;
24
19
import docZhCN from './zh-cn.md' ;
25
20
26
- hljs . registerLanguage ( 'javascript' , javascript ) ;
27
- hljs . registerLanguage ( 'xml' , xml ) ;
28
-
29
21
const components = [
30
22
{
31
23
id : 'Basic' ,
@@ -133,7 +125,6 @@ const App = {
133
125
} ;
134
126
} ,
135
127
mounted ( ) {
136
- hljs . initHighlighting ( ) ;
137
128
window . onhashchange = ( ) => {
138
129
this . currentId = this . getCurrentId ( ) ;
139
130
} ;
Original file line number Diff line number Diff line change 6
6
< meta http-equiv ="X-UA-Compatible " content ="ie=edge " />
7
7
< title > Document</ title >
8
8
< link rel ="stylesheet " href ="https://unpkg.com/normalize.css@8.0.1/normalize.css " />
9
+ < script src ="https://polyfill.io/v3/polyfill.js?features=Promise,fetch&flags=gated "> </ script >
9
10
</ head >
10
11
< body >
11
12
< div id ="app "> </ div >
Original file line number Diff line number Diff line change 10
10
<img v-else alt =" hide code" class =" icon-expand" src =" ../assets/collapse.svg" />
11
11
</section >
12
12
<section v-show =" codeVisible" class =" card-code" >
13
- <pre >
14
- <code class =" vue" >{{code}}</code >
15
- </pre >
13
+ <highlight-code :value =" code" ></highlight-code >
16
14
</section >
17
15
</div >
18
16
</template >
19
17
20
18
<script >
21
- // TODO: 替换img 图标, 本地
19
+ import HighlightCode from ' ./highlight-code ' ;
22
20
23
21
export default {
24
22
name: ' DemoCard' ,
23
+ components: { HighlightCode },
25
24
props: {
26
25
id: String ,
27
26
title: String ,
@@ -142,25 +141,5 @@ $border-color: #ebedf0;
142
141
143
142
.card-code {
144
143
border-top : 1px solid $border-color ;
145
- pre {
146
- margin : 0 ;
147
- background : #fff ;
148
- & ::after ,
149
- & ::before {
150
- width : 0 ;
151
- }
152
- // 添加优先级, 覆盖 引入的样式
153
- code {
154
- display : block ;
155
- background : #fff ;
156
- color : #314659 ;
157
- line-height : 2 ;
158
- border : 0 ;
159
- box-shadow : none ;
160
- padding : 16px 32px ;
161
- border-radius : 2px ;
162
- font-size : 14px ;
163
- }
164
- }
165
144
}
166
145
</style >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <pre class =" highlight-code" >
3
+ <code ref =" code" >{{value}}</code >
4
+ </pre >
5
+ </template >
6
+
7
+ <script >
8
+ /* eslint-disable import/no-extraneous-dependencies */
9
+ import hljs from ' highlight.js/lib/highlight' ;
10
+ import javascript from ' highlight.js/lib/languages/javascript' ;
11
+ import xml from ' highlight.js/lib/languages/xml' ;
12
+ import ' highlight.js/styles/atom-one-light.css' ;
13
+
14
+ hljs .registerLanguage (' javascript' , javascript);
15
+ hljs .registerLanguage (' xml' , xml);
16
+
17
+ export default {
18
+ props: {
19
+ value: {
20
+ type: String ,
21
+ },
22
+ },
23
+ mounted () {
24
+ hljs .highlightBlock (this .$refs .code );
25
+ },
26
+ };
27
+ </script >
28
+
29
+ <style lang="scss">
30
+ .highlight-code {
31
+ margin : 0 ;
32
+ background : #fff ;
33
+ & ::after ,
34
+ & ::before {
35
+ width : 0 ;
36
+ }
37
+ // 添加优先级, 覆盖 引入的样式
38
+ code {
39
+ display : block ;
40
+ background : #fff ;
41
+ color : #314659 ;
42
+ line-height : 2 ;
43
+ border : 0 ;
44
+ box-shadow : none ;
45
+ padding : 16px 32px ;
46
+ border-radius : 2px ;
47
+ font-size : 14px ;
48
+ }
49
+ }
50
+ </style >
Original file line number Diff line number Diff line change 7
7
< title > Document</ title >
8
8
< link rel ="stylesheet " href ="https://unpkg.com/normalize.css@8.0.1/normalize.css " />
9
9
< link rel ="stylesheet " href ="https://unpkg.com/vue2-datepicker/index.css " />
10
+ < script src ="https://polyfill.io/v3/polyfill.js?features=Promise,fetch&flags=gated "> </ script >
10
11
</ head >
11
12
< body >
12
13
< div id ="app "> </ div >
You can’t perform that action at this time.
0 commit comments