|
1 | 1 | ;(function () {
|
2 | 2 | 'use strict'
|
| 3 | + var commandContinuationRx = /\\\s*$/ |
| 4 | + |
3 | 5 | ;[].slice.call(document.querySelectorAll('.doc pre.highlight, .doc .literalblock pre')).forEach(function (pre) {
|
4 | 6 | var code, language, lang, copy, toast, toolbox
|
5 | 7 | if (pre.classList.contains('highlight')) {
|
|
51 | 53 |
|
52 | 54 | function writeToClipboard (code) {
|
53 | 55 | var text = code.innerText
|
54 |
| - if (code.dataset.lang === 'console' && text.startsWith('$ ')) text = text.split('\n')[0].slice(2) |
| 56 | + if (code.dataset.lang === 'console' && text.startsWith('$ ')) { |
| 57 | + var lines = text.split('\n') |
| 58 | + var currentCommand = '' |
| 59 | + var commands = [] |
| 60 | + var commandContinuationFound = false |
| 61 | + for (var i = 0; i < lines.length; i++) { |
| 62 | + var line = lines[i] |
| 63 | + if (!commandContinuationFound && !line.startsWith('$ ')) { |
| 64 | + // ignore, command output |
| 65 | + } else { |
| 66 | + if (commandContinuationFound) { |
| 67 | + currentCommand += '\n' + line |
| 68 | + } else if (line.startsWith('$ ')) { |
| 69 | + currentCommand = line.slice(2) |
| 70 | + } |
| 71 | + commandContinuationFound = line.match(commandContinuationRx) |
| 72 | + if (!commandContinuationFound) { |
| 73 | + commands.push(currentCommand) |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + text = commands.join('; ') |
| 78 | + } |
55 | 79 | window.navigator.clipboard.writeText(text).then(
|
56 | 80 | function () {
|
57 | 81 | this.classList.add('clicked')
|
|
0 commit comments