| 247 | // ───────────────────────────────────────────────────────────────────────────── |
| 248 | |
| 249 | function skipString(input: string, start: number): number { |
| 250 | if (input[start] !== '"') return start; |
| 251 | let i = start + 1; |
| 252 | while (i < input.length) { |
| 253 | const c = input[i]; |
| 254 | if (c === "\\") { |
| 255 | i += 2; // skip escape character and the escaped character |
| 256 | } else if (c === '"') { |
| 257 | return i + 1; // return index after the closing quote |
| 258 | } else { |
| 259 | i++; |
| 260 | } |
| 261 | } |
| 262 | return i; // return length if string was unclosed |
| 263 | } |
| 264 | |
| 265 | /** Extract code from markdown fences, or return as-is if no fences found. |
| 266 | * String-context-aware: skips ``` inside double-quoted strings. */ |