💄 🐛 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

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