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

Loading…
Cancel
Save