Skip to content

Commit

Permalink
fix: prevent line numbers from being copied. vuejs#884
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanjay Soundarajan committed Jul 1, 2022
1 parent e15941f commit 98d2ef6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/client/theme-default/composables/copy-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,18 @@ function handleElement(el: HTMLElement) {
parent.classList.contains('language-sh') ||
parent.classList.contains('language-bash')

let { innerText: text = '' } = parent
// Select the <code> element inside the whole code block.
// The <code> element is currently nested inside the <pre> tag.
const codeBlockBody = parent.querySelector(
'pre > code'
) as HTMLElement | null

let text: string = '' // Give it a default value

// if the code block body is not null, then we can get the text from it
if (codeBlockBody) {
text = codeBlockBody?.innerText ?? ''
}

if (isShell) {
text = text.replace(/^ *\$ /gm, '')
Expand Down

0 comments on commit 98d2ef6

Please sign in to comment.