(token: { type: string; raw: string; tokens?: unknown[] })
| 159 | const rawContentIndices = new Map<string, number[]>(); |
| 160 | |
| 161 | function walk(token: { type: string; raw: string; tokens?: unknown[] }) { |
| 162 | if (token.type === 'code' || token.type === 'codespan') { |
| 163 | if (!rawContentIndices.has(token.raw)) { |
| 164 | const indices: number[] = []; |
| 165 | let lastIndex = -1; |
| 166 | while ((lastIndex = content.indexOf(token.raw, lastIndex + 1)) !== -1) { |
| 167 | indices.push(lastIndex); |
| 168 | } |
| 169 | rawContentIndices.set(token.raw, indices); |
| 170 | } |
| 171 | |
| 172 | const indices = rawContentIndices.get(token.raw); |
| 173 | if (indices && indices.length > 0) { |
| 174 | // Assume tokens are processed in order of appearance. |
| 175 | // Dequeue the next available index for this raw content. |
| 176 | const idx = indices.shift()!; |
| 177 | regions.push([idx, idx + token.raw.length]); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if ('tokens' in token && token.tokens) { |
| 182 | for (const child of token.tokens) { |
| 183 | walk(child as { type: string; raw: string; tokens?: unknown[] }); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | for (const token of tokens) { |
| 189 | walk(token); |
no test coverage detected