diff --git a/CHANGELOG.md b/CHANGELOG.md index 6326c730..658cda35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### 未发布 +- **Markdown 链接里的 Windows 反斜杠**:`[x](C:\ws\_analysis\r.md)` 的 `\_` 被 Markdown 当作转义,路径少一个分隔符(变成 `C:\ws_analysis\r.md`),点击后 `ENOENT`。源代码改写现在把本地 destination 的反斜杠统一成正斜杠(Windows 两种写法都接受),UNC 前缀保持 `\\`,避免被解析成协议相对的 `//host/share`。修复 #1037。 - ⚡ **卡顿扫描与一轮低风险收敛**(前端页面 + 宿主 `/sidebar/*` 请求;逐条取证与误报核实见[扫描记录](docs/plans/2026-10-24-perf-scan.md)): - **文件树在隐藏页签里不再干活**:宿主把访问过的页签 body 常驻挂载,此前每个隐藏的文件树仍会在窗口获得焦点、刷新 tick 或另一个树展开目录时发 `fs.trees` 并重渲染整棵树;现在停靠树在隐藏时不加载(含折叠链预加载:隐藏后才返回的在飞层不会再拉下一节)、不监听焦点刷新,重新可见时由目录 watcher 对整套被 watch 的目录发一次批量 `fs.trees`(此前是每目录一次 POST;隐藏期间恰好没有缓存且展开集身份同时变化时最多两批,超过宿主 64 条路径上限仍按上限拆批)。 - **任务图滚轮缩放改为每帧一次提交**:高回报率滚轮/触控板此前每个 wheel 事件都重绘整张图,且每帧只保住一步缩放;现在与平移共用 `frame batcher`,同一帧的缩放量按步夹紧后完整复合、只提交一次(与逐帧应用等价);背景拖拽期间滚轮让位给拖拽,避免两种手势互相覆盖。 diff --git a/src/client/markdown-navigation.ts b/src/client/markdown-navigation.ts index b74cc391..d7d37082 100644 --- a/src/client/markdown-navigation.ts +++ b/src/client/markdown-navigation.ts @@ -301,6 +301,19 @@ function isLocalDestination(pathPart: string): boolean { return true } +/** + * A local path as a MARKDOWN destination. Markdown treats a backslash before + * ASCII punctuation as an escape, so `C:\ws\_analysis\r.md` parses to + * `C:\ws_analysis\r.md` — one separator gone, and the file cannot be found + * (issue #1037). Emitting forward slashes keeps every separator, and Windows + * accepts both spellings for the real open. A UNC prefix stays untouched: + * `\\server\share` must not become the scheme-relative `//server/share`. + */ +function markdownPathOf(path: string): string { + if (path.startsWith('\\\\')) return path + return path.replace(/\\/g, '/') +} + /** * Rewrite ONE destination for the host renderer (see the module comment). * Idempotent: an already-rewritten `%23` destination, a line destination and a @@ -316,16 +329,18 @@ function rewriteDestination(destination: string, docPath: string | undefined, cw // so the surface's delegate never offers an action it would not serve. if (!isLocalDestination(pathPart)) return destination const rest = separator === null ? '' : destination.slice(separator.at) - return `${pathPart}?${rest}` + return `${markdownPathOf(pathPart)}?${rest}` } - // Claimed. Nothing to carry without a fragment, `%23` is already ours, and a - // line destination belongs to the host's own grammar. - if (separator === null || separator.length === ENCODED_HASH.length) return destination - if (isHostLineFragment(fragment)) return destination + // Claimed. Nothing to carry without a fragment; `%23` is already ours. + if (separator === null) return markdownPathOf(pathPart) + if (separator.length === ENCODED_HASH.length) return destination + // A line destination belongs to the host's own grammar, but its PATH still + // needs the slash normalization (#1037). + if (isHostLineFragment(fragment)) return `${markdownPathOf(pathPart)}${destination.slice(separator.at)}` // A `?` inside the fragment must be encoded too: the host refuses a // destination that carries a query (it looks for the `?` before decoding), // so an unencoded one would turn the link back into plain text. - return `${pathPart}${ENCODED_HASH}${fragment.replace(/\?/g, '%3F')}` + return `${markdownPathOf(pathPart)}${ENCODED_HASH}${fragment.replace(/\?/g, '%3F')}` } /** diff --git a/tests/markdown-navigation.spec.ts b/tests/markdown-navigation.spec.ts index 3f0b54ff..445eb17b 100644 --- a/tests/markdown-navigation.spec.ts +++ b/tests/markdown-navigation.spec.ts @@ -178,6 +178,30 @@ describe('rewriteLocalMarkdownLinks', () => { expect(rewriteLocalMarkdownLinks('[x](./other.md)', DOC, CWD)).toBe('[x](./other.md)') }) + it('normalizes Windows backslashes so markdown cannot eat a separator (#1037)', () => { + // `\_` is a markdown escape: a link to `C:\ws\_analysis\r.md` used to reach + // the host as `C:\ws_analysis\r.md`, one separator short, and the open + // failed with ENOENT. Forward slashes survive the parse and Windows accepts + // them for the real open. + expect(rewriteLocalMarkdownLinks('[x](C:\\ws\\_analysis\\r.md)', DOC, CWD)) + .toBe('[x](C:/ws/_analysis/r.md)') + expect(rewriteLocalMarkdownLinks('[x](C:\\ws\\_a\\r.md#标题)', DOC, CWD)) + .toBe('[x](C:/ws/_a/r.md%23标题)') + // A line fragment keeps the host grammar; only the path is normalized. + expect(rewriteLocalMarkdownLinks('[x](C:\\ws\\_a\\r.md#L10)', DOC, CWD)) + .toBe('[x](C:/ws/_a/r.md#L10)') + // Relative Windows spellings are normalized the same way. + expect(rewriteLocalMarkdownLinks('[x](../src\\_a\\b.md)', DOC, CWD)) + .toBe('[x](../src/_a/b.md)') + // Remote links stay byte-identical, and a UNC prefix keeps its `\\` (it must + // not become the scheme-relative `//host/share`). + expect(rewriteLocalMarkdownLinks('[x](https://e.com/a_b)', DOC, CWD)).toBe('[x](https://e.com/a_b)') + expect(rewriteLocalMarkdownLinks('[x](\\\\srv\\share\\a_b.md)', DOC, CWD)).toBe('[x](\\\\srv\\share\\a_b.md)') + // Idempotent: an already-normalized destination survives another pass. + const once = rewriteLocalMarkdownLinks('[x](C:\\ws\\_a\\r.md)', DOC, CWD) + expect(rewriteLocalMarkdownLinks(once, DOC, CWD)).toBe(once) + }) + it('keeps every destination the plugin does not claim inert', () => { // `parseFileLink` refuses a destination carrying a query, so the appended // `?` is what stops a non-markdown local path from becoming a file-mention