|
28 | 28 |
|
29 | 29 | copyButton.addEventListener('click', function (e) { |
30 | 30 | if (e.target && e.target.matches('a.copy-code-button')) { |
31 | | - navigator.clipboard.writeText(codeBlock.innerText).then( |
32 | | - function () { |
33 | | - /* Chrome doesn't seem to blur automatically, |
34 | | - leaving the button in a focused state. */ |
35 | | - copyButton.blur() |
| 31 | + // for console text |
| 32 | + if (codeBlock.dataset.lang == 'console') { |
| 33 | + var bashText = codeBlock.innerText |
| 34 | + // remove $ from text |
| 35 | + navigator.clipboard.writeText(bashText.slice(2)).then( |
| 36 | + function () { |
| 37 | + /* Chrome doesn't seem to blur automatically, |
| 38 | + leaving the button in a focused state. */ |
| 39 | + copyButton.blur() |
| 40 | + copyButton.dataset.title = 'Copied ✓' |
| 41 | + setTimeout(function () { |
| 42 | + copyButton.dataset.title = 'Copy' |
| 43 | + }, 2000) |
| 44 | + }, |
| 45 | + function () { |
| 46 | + copyButton.dataset.title = 'Error' |
| 47 | + } |
| 48 | + ) |
| 49 | + } else { |
| 50 | + navigator.clipboard.writeText(codeBlock.innerText).then( |
| 51 | + function () { |
| 52 | + /* Chrome doesn't seem to blur automatically, |
| 53 | + leaving the button in a focused state. */ |
| 54 | + copyButton.blur() |
36 | 55 |
|
37 | | - copyButton.dataset.title = 'Copied ✓' |
| 56 | + copyButton.dataset.title = 'Copied ✓' |
38 | 57 |
|
39 | | - setTimeout(function () { |
40 | | - copyButton.dataset.title = 'Copy' |
41 | | - }, 2000) |
42 | | - }, |
43 | | - function () { |
44 | | - copyButton.dataset.title = 'Error' |
45 | | - } |
46 | | - ) |
| 58 | + setTimeout(function () { |
| 59 | + copyButton.dataset.title = 'Copy' |
| 60 | + }, 2000) |
| 61 | + }, |
| 62 | + function () { |
| 63 | + copyButton.dataset.title = 'Error' |
| 64 | + } |
| 65 | + ) |
| 66 | + } |
47 | 67 | } |
48 | 68 | }) |
49 | 69 | var pre = codeBlock.parentNode |
|
0 commit comments