feat(plugin): add copy to clipboard for highlighted code
parent
b913e648f3
commit
6495a9bf5b
|
@ -49,6 +49,9 @@ module.exports = function (hexo) {
|
||||||
if (_package === 'pace-js') {
|
if (_package === 'pace-js') {
|
||||||
_package = 'pace';
|
_package = 'pace';
|
||||||
}
|
}
|
||||||
|
if (_package === 'clipboard') {
|
||||||
|
_package = 'clipboard.js';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (provider !== null && cdn_providers.hasOwnProperty(provider)) {
|
if (provider !== null && cdn_providers.hasOwnProperty(provider)) {
|
||||||
provider = cdn_providers[provider];
|
provider = cdn_providers[provider];
|
||||||
|
|
|
@ -59,5 +59,10 @@ module.exports = {
|
||||||
[type]: 'boolean',
|
[type]: 'boolean',
|
||||||
[doc]: 'Show a loading progress bar at top of the page',
|
[doc]: 'Show a loading progress bar at top of the page',
|
||||||
[defaultValue]: true
|
[defaultValue]: true
|
||||||
|
},
|
||||||
|
clipboard: {
|
||||||
|
[type]: 'boolean',
|
||||||
|
[doc]: 'Show the copy button in the highlighted code area',
|
||||||
|
[defaultValue]: true
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -0,0 +1,6 @@
|
||||||
|
<% if (plugin !== false) { %>
|
||||||
|
<% if (!head) { %>
|
||||||
|
<%- _js(cdn('clipboard', '2.0.4', 'dist/clipboard.min.js'), true) %>
|
||||||
|
<%- _js('js/clipboard', true) %>
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
|
@ -232,6 +232,9 @@ img.thumbnail
|
||||||
/* ---------------------------------
|
/* ---------------------------------
|
||||||
* Custom modifiers
|
* Custom modifiers
|
||||||
* --------------------------------- */
|
* --------------------------------- */
|
||||||
|
.is-borderless
|
||||||
|
border: none
|
||||||
|
|
||||||
.is-size-7
|
.is-size-7
|
||||||
font-size: 0.85rem !important
|
font-size: 0.85rem !important
|
||||||
|
|
||||||
|
@ -340,6 +343,7 @@ img.thumbnail
|
||||||
figure.highlight
|
figure.highlight
|
||||||
padding: 0
|
padding: 0
|
||||||
width: 100%
|
width: 100%
|
||||||
|
position: relative
|
||||||
margin: 1em 0 1em !important
|
margin: 1em 0 1em !important
|
||||||
|
|
||||||
pre,
|
pre,
|
||||||
|
@ -393,6 +397,16 @@ figure.highlight
|
||||||
min-width: inherit
|
min-width: inherit
|
||||||
border-radius: inherit
|
border-radius: inherit
|
||||||
|
|
||||||
|
.copy
|
||||||
|
display: none
|
||||||
|
position: absolute
|
||||||
|
bottom: 0
|
||||||
|
right: 0
|
||||||
|
color: white
|
||||||
|
background: rgba(0, 0, 0, 0.5)
|
||||||
|
&:hover .copy
|
||||||
|
display: block
|
||||||
|
|
||||||
/* ---------------------------------
|
/* ---------------------------------
|
||||||
* Fix Gist Snippet
|
* Fix Gist Snippet
|
||||||
* --------------------------------- */
|
* --------------------------------- */
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
$('figure.highlight').each(function () {
|
||||||
|
var id = 'code-' + Date.now() + (Math.random() * 1000 | 0);
|
||||||
|
$(this).attr('id', id);
|
||||||
|
$(this).prepend($(`<button class="button is-borderless is-radiusless is-small copy" data-clipboard-target="#${id} .code" title="Copy"><i class="fas fa-copy"></i></button>`));
|
||||||
|
});
|
||||||
|
new ClipboardJS('.highlight .copy');
|
||||||
|
});
|
Loading…
Reference in New Issue