Merge pull request #129 from sxz799/sxz799-patch-1

🐛 fixed修复复制代码时多余的空行
This commit is contained in:
凡梦星尘 2023-11-08 20:51:21 +08:00 committed by GitHub
commit 11685b9b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -278,7 +278,7 @@ NexT.utils = {
const button = element.querySelector('.copy-btn'); const button = element.querySelector('.copy-btn');
button.addEventListener('click', () => { button.addEventListener('click', () => {
const lines = element.querySelector('.code') || element.querySelector('code'); const lines = element.querySelector('.code') || element.querySelector('code');
const code = lines.innerText; const code = lines.innerText.replace(/(\n{2,})/g, '\n');
if (navigator.clipboard) { if (navigator.clipboard) {
// https://caniuse.com/mdn-api_clipboard_writetext // https://caniuse.com/mdn-api_clipboard_writetext
navigator.clipboard.writeText(code).then(() => { navigator.clipboard.writeText(code).then(() => {