Skip to content

Commit

Permalink
Fix copy button newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
qwtel committed Sep 8, 2024
1 parent b9a2917 commit 70606fe
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions _js/src/upgrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ const toggleClass = (element, ...cls) => {
const toc = main.querySelector('#markdown-toc');
if (toc) toc.classList.add('toc-hide');

if ('clipboard' in navigator) {
if ('clipboard' in navigator && 'ClipboardItem' in window) {
Array.from(main.querySelectorAll(CODE_BLOCK_SEL)).forEach((el) => {
const container = el?.parentNode?.parentNode;
const writeText = async () => {
await navigator.clipboard.writeText(el.innerText);
await navigator.clipboard.write([new ClipboardItem({ 'text/plain': new Blob([el.textContent], { type: 'text/plain' }) })]);
toggleClass(copyBtn, 'copy-success');
};
const copyBtn = createElement(
Expand Down

0 comments on commit 70606fe

Please sign in to comment.