(transcript, sourceUrl)
| 71 | } |
| 72 | |
| 73 | function extractInputs(transcript, sourceUrl) { |
| 74 | const lines = transcript.replaceAll('\r\n', '\n').split('\n'); |
| 75 | const expressions = []; |
| 76 | |
| 77 | for (let index = 0; index < lines.length; index += 1) { |
| 78 | const start = lines[index].match(/^In\[\d+\]:=\s?(.*)$/); |
| 79 | if (!start) continue; |
| 80 | if (start[1].trim() === '') continue; |
| 81 | if (start[1].trim() === 'Quit[]') continue; |
| 82 | |
| 83 | const input = [start[1]]; |
| 84 | while ( |
| 85 | index + 1 < lines.length && |
| 86 | !isTiming(lines[index + 1]) && |
| 87 | !isSessionBoundary(lines[index + 1]) |
| 88 | ) { |
| 89 | input.push(lines[index + 1]); |
| 90 | index += 1; |
| 91 | } |
| 92 | |
| 93 | const expression = repairTerminalWrapping(input).join('\n').trim(); |
| 94 | if (expression) expressions.push(expression); |
| 95 | } |
| 96 | |
| 97 | return [ |
| 98 | `(* Extracted from ${sourceUrl}`, |
| 99 | ` Source index: ${INDEX_URL} *)`, |
| 100 | '', |
| 101 | ...expressions.flatMap((expression) => [expression, '']), |
| 102 | ].join('\n'); |
| 103 | } |
| 104 | |
| 105 | const indexResponse = await fetch(INDEX_URL); |
| 106 | if (!indexResponse.ok) { |
no test coverage detected