File tree Expand file tree Collapse file tree 6 files changed +46
-9
lines changed Expand file tree Collapse file tree 6 files changed +46
-9
lines changed Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ module.exports = {
99
99
embed: ' ' ,
100
100
},
101
101
demoCodeMark: ' demo-code' ,
102
+ copyOptions: { ... },
102
103
}]
103
104
],
104
105
}
@@ -154,6 +155,12 @@ It passes [CodeSandbox options](https://codesandbox.io/docs/importing#define-api
154
155
155
156
插件的标记,即跟在 ` ::: ` 后的标记。
156
157
158
+ ### copyOptions
159
+ * 类型:` Object/Boolean `
160
+ * 默认值:` { align: 'top', selector: '.demo-and-code-wrapper div[class*="language-"] pre' } `
161
+
162
+ 透传 [ vuepress-plugin-code-copy] ( https://github.com/znicholasbrown/vuepress-plugin-code-copy#options ) 的参数,或传 ` false ` 禁用它。
163
+
157
164
## Related
158
165
* [ vuepress-plugin-demo-block] ( https://github.com/xiguaxigua/vuepress-plugin-demo-block )
159
166
Original file line number Diff line number Diff line change @@ -99,6 +99,7 @@ module.exports = {
99
99
embed: ' ' ,
100
100
},
101
101
demoCodeMark: ' demo-code' ,
102
+ copyOptions: { ... },
102
103
}]
103
104
],
104
105
}
@@ -154,6 +155,12 @@ It passes [CodeSandbox options](https://codesandbox.io/docs/importing#define-api
154
155
155
156
The mark of the plugin, follows the tag after ` ::: ` .
156
157
158
+ ### copyOptions
159
+ * Type: ` Object/Boolean `
160
+ * Default: ` { align: 'top', selector: '.demo-and-code-wrapper div[class*="language-"] pre' } `
161
+
162
+ It passes [ vuepress-plugin-code-copy] ( https://github.com/znicholasbrown/vuepress-plugin-code-copy#options ) 's options, or ` false ` to disable it.
163
+
157
164
## Related
158
165
* [ vuepress-plugin-demo-block] ( https://github.com/xiguaxigua/vuepress-plugin-demo-block )
159
166
@@ -179,4 +186,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
179
186
180
187
<!-- ALL-CONTRIBUTORS-LIST:END -->
181
188
182
- This project follows the [ all-contributors] ( https://github.com/all-contributors/all-contributors ) specification. Contributions of any kind welcome!
189
+ This project follows the [ all-contributors] ( https://github.com/all-contributors/all-contributors ) specification. Contributions of any kind welcome!
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " vuepress-plugin-demo-code" ,
3
- "version" : " 0.4.2 " ,
3
+ "version" : " 0.5.0 " ,
4
4
"description" : " 📝 Demo and code plugin for vuepress" ,
5
5
"main" : " src/index.js" ,
6
6
"files" : [
34
34
"dependencies" : {
35
35
"codesandbox" : " 2.1.10" ,
36
36
"markdown-it-container" : " ^2.0.0" ,
37
- "prismjs" : " ^1.17.1"
37
+ "prismjs" : " ^1.17.1" ,
38
+ "vuepress-plugin-code-copy" : " ^1.0.4"
38
39
},
39
40
"devDependencies" : {
40
41
"@babel/core" : " ^7.7.2" ,
Original file line number Diff line number Diff line change @@ -157,6 +157,19 @@ html {
157
157
.demo-and-code-wrapper {
158
158
padding : 20px 0 ;
159
159
160
+ // for vuepress-plugin-code-copy
161
+ .code-copy {
162
+ position : absolute ;
163
+ top : 20px ;
164
+ right : 0 ;
165
+
166
+ opacity : 1 ;
167
+
168
+ svg {
169
+ right : 10px ;
170
+ }
171
+ }
172
+
160
173
.code-control {
161
174
position : sticky ;
162
175
z-index : 9 ;
Original file line number Diff line number Diff line change
1
+ if ( typeof window !== 'undefined' ) {
2
+ // prevent highlighting automatically
3
+ window . Prism = { manual : true }
4
+ }
5
+
1
6
const prism = require ( 'prismjs' )
2
7
const escapeHtml = require ( 'escape-html' )
3
8
const loadLanguages = require ( 'prismjs/components/index' )
4
9
5
- // prevent Prism calling `highlightAll`
6
- prism . manual = true
7
-
8
- // loadLanguages(['markup', 'css', 'javascript'])
9
-
10
10
function wrap ( code , lang ) {
11
11
if ( lang === 'text' ) {
12
12
code = escapeHtml ( code )
Original file line number Diff line number Diff line change @@ -18,11 +18,20 @@ const defaults = {
18
18
}
19
19
20
20
module . exports = ( options = { } ) => {
21
- const { demoCodeMark = 'demo' } = options
21
+ const {
22
+ demoCodeMark = 'demo' ,
23
+ copyOptions = {
24
+ align : 'top' ,
25
+ selector : '.demo-and-code-wrapper div[class*="language-"] pre' ,
26
+ } ,
27
+ } = options
22
28
const END_TYPE = `container_${ demoCodeMark } _close`
23
29
24
30
return {
25
31
name : 'vuepress-plugin-demo-code' ,
32
+ plugins : [
33
+ [ 'code-copy' , copyOptions ] ,
34
+ ] ,
26
35
enhanceAppFiles : [
27
36
path . resolve ( __dirname , 'enhanceAppFile.js' ) ,
28
37
] ,
You can’t perform that action at this time.
0 commit comments