(source: nbformat.MultilineString)
| 239 | } |
| 240 | |
| 241 | export function splitMultilineString(source: nbformat.MultilineString): string[] { |
| 242 | // Make sure a multiline string is back the way Jupyter expects it |
| 243 | if (Array.isArray(source)) { |
| 244 | return source as string[]; |
| 245 | } |
| 246 | const str = source.toString(); |
| 247 | if (str.length > 0) { |
| 248 | // Each line should be a separate entry, but end with a \n if not last entry |
| 249 | const arr = str.split('\n'); |
| 250 | return arr |
| 251 | .map((s, i) => { |
| 252 | if (i < arr.length - 1) { |
| 253 | return `${s}\n`; |
| 254 | } |
| 255 | return s; |
| 256 | }) |
| 257 | .filter((s) => s.length > 0); // Skip last one if empty (it's the only one that could be length 0) |
| 258 | } |
| 259 | return []; |
| 260 | } |
| 261 | |
| 262 | // Took this from jupyter/notebook |
| 263 | // https://github.com/jupyter/notebook/blob/b8b66332e2023e83d2ee04f83d8814f567e01a4e/notebook/static/base/js/utils.js |
no test coverage detected