Skip to content

Commit

Permalink
feat: allow explicitly mark code element as .vp-copy-ignore (#3360)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 20, 2023
1 parent bdfc01c commit 93122ee
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/client/app/composables/copyCode.ts
Expand Up @@ -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()
Expand Down

0 comments on commit 93122ee

Please sign in to comment.