| 30 | // One pass instead of 10× includes scans. |
| 31 | const MD_SYNTAX_RE = /[#*`|[>\-_~]|\n\n|^\d+\. |\n\d+\. /; |
| 32 | function hasMarkdownSyntax(s: string): boolean { |
| 33 | // Sample first 500 chars — if markdown exists it's usually early (headers, |
| 34 | // code fence, list). Long tool outputs are mostly plain text tails. |
| 35 | return MD_SYNTAX_RE.test(s.length > 500 ? s.slice(0, 500) : s); |
| 36 | } |
| 37 | function cachedLexer(content: string): Token[] { |
| 38 | // Fast path: plain text with no markdown syntax → single paragraph token. |
| 39 | // Skips marked.lexer's full GFM parse (~3ms on long content). Not cached — |