/** * Line endings are not content: every line-based scanner in the markdown * pipeline must read a CRLF document exactly like the same document with LF * endings. * * WHY THIS FILE EXISTS: the pipeline's scanners split a document on `\n` and * then reason about each line (`isBlank`, a closed-ATX heading, a closing * fence). A Windows checkout — `core.autocrlf=true`, which is both the * `ci-windows` lane and every user who clones on Windows — hands them `\r\n`, * and a `\r` left at the end of a line is invisible in the rendered output but * not to those predicates. Measured on this repo's own README before the fix: * the HTML-run splitter produced 4 segments instead of 36 (an HTML run stayed * open across the blank line that should have ended it and swallowed the * markdown after it), `splitMermaidBlocks` never closed a fence, and * `maskCodeRegions` masked everything from the first fence to the end of the * file, so the link rewriter stopped claiming every `.md` link after it. The * same document with LF endings was correct in all three. * * The invariant pinned here is that whole contract, scanner by scanner: the * CRLF spelling's output must equal the LF spelling's output once `\r` is * ignored. These cases are DISCRIMINATING by construction — reverting any of * the three `\r` fixes in `src/client` turns them red (the CRLF half diverges * from the LF half), which is exactly how the `ci-windows` failures got here: * only the CRLF half of each pair was ever exercised there. */ import { describe, expect, it } from 'vitest' import { analyzeMarkdownHtml, splitHtmlBlocks, type AnalyzedMarkdownHtml, type MdHtmlSegment, } from '../src/client/markdown-html.ts' import { splitMermaidBlocks, type MdBlock } from '../src/client/mermaid-blocks.ts' import { maskCodeRegions } from '../src/client/markdown-code.ts' import { rewriteLocalMarkdownLinks } from '../src/client/markdown-navigation.ts' import { rewriteLocalImageUrls } from '../src/client/markdown-images.ts' import type { SessionScope } from '../src/client/api.ts' /** One document, both spellings — every case below compares the two. */ const LF = [ '# 标题', '', '', '', '