remove $ prompt from code copy

This commit is contained in:
craig-osterhout 2022-10-21 09:03:57 -07:00
parent 8ebd41f2f6
commit 6fa06e8174
No known key found for this signature in database
GPG Key ID: 497A5E49261C73B5
1 changed files with 3 additions and 1 deletions

View File

@ -15,7 +15,9 @@ function copyCodeBlock(event) {
const copyButton = event.currentTarget const copyButton = event.currentTarget
const codeBlock = copyButton.parentElement.querySelector("pre.highlight code") const codeBlock = copyButton.parentElement.querySelector("pre.highlight code")
const code = codeBlock.innerText.trim() const code = codeBlock.innerText.trim()
window.navigator.clipboard.writeText(code) // remove "$ " prompt at start of lines in code
const strippedCode = code.replace(/^[\s]?\$\s+/gm, "")
window.navigator.clipboard.writeText(strippedCode)
// change the button text temporarily // change the button text temporarily
copyButton.textContent = "Copied!" copyButton.textContent = "Copied!"