( content: string, index: number, )
| 67 | * @returns Start index of the enclosing code block or -1. |
| 68 | */ |
| 69 | const findEnclosingCodeBlockStart = ( |
| 70 | content: string, |
| 71 | index: number, |
| 72 | ): number => { |
| 73 | if (!isIndexInsideCodeBlock(content, index)) { |
| 74 | return -1; |
| 75 | } |
| 76 | let currentSearchPos = 0; |
| 77 | while (currentSearchPos < index) { |
| 78 | const blockStartIndex = content.indexOf('```', currentSearchPos); |
| 79 | if (blockStartIndex === -1 || blockStartIndex >= index) { |
| 80 | break; |
| 81 | } |
| 82 | const blockEndIndex = content.indexOf('```', blockStartIndex + 3); |
| 83 | if (blockStartIndex < index) { |
| 84 | if (blockEndIndex === -1 || index < blockEndIndex + 3) { |
| 85 | return blockStartIndex; |
| 86 | } |
| 87 | } |
| 88 | if (blockEndIndex === -1) break; |
| 89 | currentSearchPos = blockEndIndex + 3; |
| 90 | } |
| 91 | return -1; |
| 92 | }; |
| 93 | |
| 94 | export const findLastSafeSplitPoint = (content: string) => { |
| 95 | const enclosingBlockStart = findEnclosingCodeBlockStart( |
no test coverage detected