feat: allow explicitly mark code element as `.vp-copy-ignore`

pull/3360/head
Anthony Fu 2 years ago
parent bdfc01c9ec
commit 680cb0b0d5

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

Loading…
Cancel
Save