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

Loading…
Cancel
Save