( content: string, )
| 382 | } |
| 383 | |
| 384 | export function lexMarkdownPreservingPreformattedDiagrams( |
| 385 | content: string, |
| 386 | ): Token[] { |
| 387 | configureMarked() |
| 388 | const segments = detectPreformattedMarkdownSegments(content) |
| 389 | if (segments.length === 0) { |
| 390 | return marked.lexer(repairMalformedPipeTables(content)) |
| 391 | } |
| 392 | |
| 393 | const tokens: Token[] = [] |
| 394 | for (const segment of segments) { |
| 395 | if (segment.type === 'preformatted_diagram') { |
| 396 | tokens.push({ |
| 397 | type: 'code', |
| 398 | raw: segment.content, |
| 399 | text: segment.content, |
| 400 | lang: '', |
| 401 | } as Token) |
| 402 | continue |
| 403 | } |
| 404 | tokens.push(...marked.lexer(repairMalformedPipeTables(segment.content))) |
| 405 | } |
| 406 | return tokens |
| 407 | } |
| 408 | |
| 409 | export function configureMarked(): void { |
| 410 | if (markedConfigured) return |
no test coverage detected