💄 🐛 Fixed the copy code button display style.

This commit is contained in:
凡梦星尘 2022-06-21 14:55:07 +08:00
parent 9a83558e01
commit e6fccb0b4e
4 changed files with 34 additions and 136 deletions

View File

@ -2,6 +2,19 @@
opacity: 1; opacity: 1;
} }
.highlight {
background: var(--highlight-background);
.table-container, pre {
position: relative;
}
.table-container table tbody tr {
background: none;
}
}
.copy-btn { .copy-btn {
color: $black-dim; color: $black-dim;
cursor: pointer; cursor: pointer;
@ -9,32 +22,32 @@
opacity: 0; opacity: 0;
padding: 2px 6px; padding: 2px 6px;
position: absolute; position: absolute;
right: 8px;
top: 4px;
transition: opacity $transition-ease; transition: opacity $transition-ease;
background: var(--highlight-background);
@if $codeblock_copy_btn_style == 'flat' { @if $codeblock_copy_btn_style == 'flat' {
background: white; background: white;
border: 0; border: 0;
font-size: $font-size-smaller; font-size: $font-size-smaller;
right: 0;
top: 0;
} @else if $codeblock_copy_btn_style == 'mac' { } @else if $codeblock_copy_btn_style == 'mac' {
color: var(--highlight-foreground); color: var(--highlight-foreground);
font-size: 14px; font-size: 14px;
right: 0; border-radius: 3px;
top: 2px;
} @else { } @else {
background-color: $gainsboro; background-color: $gainsboro;
background-image: linear-gradient(#fcfcfc, $gainsboro); background-image: linear-gradient(#fcfcfc, $gainsboro);
border: 1px solid #d5d5d5; border: 1px solid #d5d5d5;
border-radius: 3px; border-radius: 3px;
font-size: $font-size-smaller; font-size: $font-size-smaller;
right: 4px;
top: 8px;
} }
} }
@if $codeblock_copy_btn_style == 'mac' { @if $codeblock_copy_btn_style == 'mac' {
figure.highlight { .highlight {
border-radius: 5px; border-radius: 5px;
box-shadow: 0 10px 30px 0 rgba(0, 0, 0, .4); box-shadow: 0 10px 30px 0 rgba(0, 0, 0, .4);
padding-top: 30px; padding-top: 30px;
@ -46,8 +59,8 @@
&::before { &::before {
background: #fc625d; background: #fc625d;
box-shadow: 20px 0 #fdbc40, 40px 0 #35cd4b; box-shadow: 20px 0 #fdbc40, 40px 0 #35cd4b;
left: 12px;
margin-top: -20px; margin-top: -20px;
margin-left: 10px;
position: absolute; position: absolute;
@include round-icon(12px); @include round-icon(12px);
} }

View File

@ -1,17 +1,5 @@
// Use `@use` to fix issue #67 @import 'copy-code';
// TODO find way to import file by dynmatic
// @import '(theme.highlight.enable && theme.highlight.light.file) ? theme.highlight.light.file : null';
// @import '(theme.prism.enable && theme.prism.light) ? theme.prism.light : null';
// @import '(theme.prism.enable && theme.prism.number) ? theme.prism.number : null';
/* @media (prefers-color-scheme: dark) {
@import '(theme.darkmode && theme.highlight.enable && theme.highlight.dark.file) ? theme.highlight.dark.file : null';
@import '(theme.darkmode && theme.prism.enable && theme.prism.dark) ? theme.prism.dark : null';
} */
// @import 'theme.codeblock.copy_button.enable ? "copy-code" : null';
// Placeholder: %code-inline %code-block
%code-inline { %code-inline {
background: var(--highlight-background); background: var(--highlight-background);
color: var(--highlight-foreground); color: var(--highlight-foreground);
@ -23,36 +11,14 @@
margin: 0 auto 20px; margin: 0 auto 20px;
} }
%figcaption {
background: var(--highlight-gutter-background);
color: var(--highlight-foreground);
display: flow-root;
font-size: $table-font-size;
line-height: 1.2;
padding: .5em;
a { pre {
color: var(--highlight-foreground); padding: 10px;
float: right;
&:hover {
border-bottom-color: var(--highlight-foreground);
}
}
} }
pre, code { pre, code {
font-family: $code-font-family; font-family: $code-font-family;
color: #fff;
} }
code {
@extend %code-inline;
border-radius: 3px;
font-size: $table-font-size;
padding: 2px 4px;
@include word-wrap();
}
kbd { kbd {
@extend %code-inline; @extend %code-inline;
@ -62,82 +28,4 @@ kbd {
font-family: inherit; font-family: inherit;
padding: .1em .3em; padding: .1em .3em;
white-space: nowrap; white-space: nowrap;
color: #fff; }
}
// `highlight.line_number: false` and `highlight.wrap: false`
// in Hexo config generates code.highlight elements
figure.highlight {
@extend %code-block;
position: relative;
pre {
border: 0;
margin: 0;
padding: 10px 0;
}
table {
border: 0;
margin: 0;
width: auto;
}
td {
border: 0;
padding: 0;
}
figcaption {
@extend %figcaption;
}
.gutter {
@include disable-user-select();
pre {
background: var(--highlight-gutter-background);
color: var(--highlight-gutter-foreground);
padding-left: 10px;
padding-right: 10px;
text-align: right;
}
}
.code pre {
padding-left: 10px;
width: 100%;
}
// See https://github.com/next-theme/hexo-theme-next/discussions/410
.marked {
background: rgba(0, 0, 0, .3);
}
}
// See https://github.com/hexojs/hexo-util/pull/229
pre .caption, pre figcaption {
@extend %figcaption;
margin-bottom: 10px;
}
.gist table {
width: auto;
td {
border: 0;
}
}
pre {
@extend %code-block;
overflow: auto;
padding: 10px;
position: relative;
code {
background: none;
padding: 0;
text-shadow: none;
}
}

View File

@ -47,10 +47,10 @@ $font_title_size : {{ default $P.font.title.size 1.375 }};
// Code & Code blocks // Code & Code blocks
// TODO find the configure variable // TODO find the configure variable
$highlight_dark_background : #000; $highlight_dark_background : #1c1b1b;
$highlight_dark_foreground : #222; $highlight_dark_foreground : #fff;
$highlight_light_background : #000; $highlight_light_background : #fff;
$highlight_light_foreground : #222; $highlight_light_foreground : #555;
$codeblock_copy_btn_style : {{ $P.codeblock.copyBtn.style }}; $codeblock_copy_btn_style : {{ $P.codeblock.copyBtn.style }};

View File

@ -40,15 +40,12 @@ NexT.utils = {
* One-click copy code support. * One-click copy code support.
*/ */
registerCopyCode: function() { registerCopyCode: function() {
let figure = document.querySelectorAll('figure.highlight'); let figure = document.querySelectorAll('.highlight pre');
if (figure.length === 0) figure = document.querySelectorAll('pre:not(.mermaid)'); if (figure.length === 0 || !CONFIG.copycode) return;
figure.forEach(element => { figure.forEach(element => {
element.querySelectorAll('.code .line span').forEach(span => { let cn = element.querySelector('code').className;
span.classList.forEach(name => { // TODO seems hard code need find other ways fixed it.
span.classList.replace(name, `hljs-${name}`); if (cn == '') return;
});
});
if (!CONFIG.copycode) return;
element.insertAdjacentHTML('beforeend', '<div class="copy-btn"><i class="fa fa-copy fa-fw"></i></div>'); element.insertAdjacentHTML('beforeend', '<div class="copy-btn"><i class="fa fa-copy fa-fw"></i></div>');
const button = element.querySelector('.copy-btn'); const button = element.querySelector('.copy-btn');
button.addEventListener('click', () => { button.addEventListener('click', () => {