diff --git a/src/client/app/composables/copyCode.ts b/src/client/app/composables/copyCode.ts index 0a07c281..2c458bb4 100644 --- a/src/client/app/composables/copyCode.ts +++ b/src/client/app/composables/copyCode.ts @@ -16,13 +16,15 @@ export function useCopyCode() { parent.className ) - let text = '' + const ignoredNodes = ['.vp-copy-ignore', '.diff.remove'] - sibling - .querySelectorAll('span.line:not(.diff.remove)') - .forEach((node) => (text += (node.textContent || '') + '\n')) + // Clone the node and remove the ignored nodes + const clone = sibling.cloneNode(true) as HTMLElement + clone + .querySelectorAll(ignoredNodes.join(',')) + .forEach((node) => node.remove()) - text = (text || sibling.textContent || '').slice(0, -1) + let text = clone.textContent || '' if (isShell) { text = text.replace(/^ *(\$|>) /gm, '').trim()