feat: allow explicitly mark code element as `.vp-copy-ignore` (#3360)

pull/3366/head
Anthony Fu 11 months ago committed by GitHub
parent bdfc01c9ec
commit 93122eee20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()

Loading…
Cancel
Save