( content: string, )
| 287 | } |
| 288 | |
| 289 | export function detectPreformattedMarkdownSegments( |
| 290 | content: string, |
| 291 | ): MarkdownSegment[] { |
| 292 | if (content.length === 0) { |
| 293 | return [] |
| 294 | } |
| 295 | |
| 296 | const lines = content.split('\n') |
| 297 | const lineOffsets = getLineStartOffsets(lines) |
| 298 | const segments: MarkdownSegment[] = [] |
| 299 | let markdownCursor = 0 |
| 300 | let lineIndex = 0 |
| 301 | let activeFence: { marker: '`' | '~'; size: number } | null = null |
| 302 | |
| 303 | while (lineIndex < lines.length) { |
| 304 | const line = lines[lineIndex] ?? '' |
| 305 | if (activeFence) { |
| 306 | if (isFenceClose(line, activeFence)) { |
| 307 | activeFence = null |
| 308 | } |
| 309 | lineIndex += 1 |
| 310 | continue |
| 311 | } |
| 312 | |
| 313 | const openingFence = detectFenceDelimiter(line) |
| 314 | if (openingFence) { |
| 315 | activeFence = openingFence |
| 316 | lineIndex += 1 |
| 317 | continue |
| 318 | } |
| 319 | |
| 320 | if (classifyPotentialDiagramLine(line) === 'other') { |
| 321 | lineIndex += 1 |
| 322 | continue |
| 323 | } |
| 324 | |
| 325 | const runStart = lineIndex |
| 326 | while ( |
| 327 | lineIndex < lines.length && |
| 328 | !detectFenceDelimiter(lines[lineIndex] ?? '') && |
| 329 | classifyPotentialDiagramLine(lines[lineIndex] ?? '') !== 'other' |
| 330 | ) { |
| 331 | lineIndex += 1 |
| 332 | } |
| 333 | const runEnd = lineIndex |
| 334 | |
| 335 | let candidateStart = runStart |
| 336 | while ( |
| 337 | candidateStart < runEnd && |
| 338 | (lines[candidateStart] ?? '').trim().length === 0 |
| 339 | ) { |
| 340 | candidateStart += 1 |
| 341 | } |
| 342 | |
| 343 | let candidateEnd = runEnd |
| 344 | while ( |
| 345 | candidateEnd > candidateStart && |
| 346 | (lines[candidateEnd - 1] ?? '').trim().length === 0 |
no test coverage detected