Skip to content

fix(markdown): 本地链接里的 Windows 反斜杠统一为正斜杠 - #1055

Merged
Menghuan1918 merged 1 commit into
omdsh-dev:devfrom
z11y11w:fix/1037-markdown-backslash
Oct 26, 2026
Merged

Menghuan1918 merged 1 commit into
omdsh-dev:devfrom
z11y11w:fix/1037-markdown-backslash

Conversation

@z11y11w

@z11y11w z11y11w commented Oct 25, 2026

Copy link
Copy Markdown

问题

Windows 路径写进 Markdown 链接时,分隔符会被吃掉:

[报告](C:\ws\_analysis\report.md)

点开后报 ENOENT,因为 Markdown 把 \_ 当作转义,实际打开的路径变成了 C:\ws_analysis\report.md——少了一个分隔符。\.、\*、\[ 等同样中招。

容易误判的地方:链接的 href 会把反斜杠规范成 /,所以只有「反斜杠 + ASCII 标点」那一处会丢,其余分隔符看起来正常,路径“像是对的”。

关联 issue: #1037

修复

在渲染前归一化,而不是在打开失败后猜路径:

  • rewriteDestination() 对所有本地 destination 的路径部分输出正斜杠(Windows 文件系统两种写法都接受);
  • 覆盖三条分支:无 fragment、line fragment(#L24)、heading fragment(%23标题);
  • UNC 前缀保持 \\,避免被解析成协议相对的 //host/share;
  • 远程链接(https://、mailto:)原样返回,不做任何改动;
  • 幂等:已经归一化的 destination 再跑一次结果不变。

改动文件:

  • src/client/markdown-navigation.ts
  • tests/markdown-navigation.spec.ts
  • CHANGELOG.md

测试

新增 6 条断言:

  1. 绝对 Windows 路径 → 正斜杠;
  2. heading fragment 的路径部分归一化,fragment 仍是 %23;
  3. line fragment 保留宿主语法,只归一化路径;
  4. 相对 Windows 路径同样归一化;
  5. 远程链接逐字不变;
  6. UNC 前缀保持 \\;
  7. 幂等。

验证

  • tsc --noEmit:通过
  • eslint:通过
  • 本机 vitest 4 在 Windows 上打包配置失败(Cannot convert undefined or null to object,空配置同样失败,与本次改动无关),因此本地用 Node 直接跑同一组用例通过;CI 会执行该 spec。

风险

  • 只影响本地链接的书写形式,不改变任何打开语义;
  • 已经手写正斜杠的链接行为不变。

Markdown 把 `\_` 当作转义,`[x](C:\ws\_analysis\r.md)` 解析后路径少一个分隔符(变成 `C:\ws_analysis\r.md`),点击时报 ENOENT(issue omdsh-dev#1037)。

- rewriteDestination 对所有本地 destination 的路径部分用正斜杠输出(Windows 接受两种写法);无 fragment / line fragment / heading fragment 三条分支都覆盖
- UNC 前缀保持 `\\`,避免被解析成协议相对的 `//host/share`
- 新增 6 条断言:绝对/相对 Windows 路径、heading/line fragment、远程链接、幂等

验证:tsc --noEmit 与 eslint 通过;同一组用例用 Node 直跑通过(本机 vitest 配置打包在 Windows 上失败,CI 执行该 spec)。
davidLi17 added a commit to davidLi17/DSH-better-sidebar that referenced this pull request Oct 25, 2026
Selectively backport open upstream PRs omdsh-dev#1040 (598714b), omdsh-dev#1055 (828452a), and omdsh-dev#1053 (f2ad4b1). Isolate Mermaid layout with authenticated sandbox messaging, recover from malformed diagrams, cancel/promote queued renders, preserve Windows Markdown separators and keep the bottom workbench toggle reachable.

Preserve LHG draft/image sidechat behavior and selective omdsh-dev#1050 performance fixes. Ship prebuilt lib without lifecycle hooks. Validation: 230 files, 2790 tests passed, 17 skipped; typecheck, lint, build, consumer types, pack and fresh official DSH rc1 install/start passed. Real browser UI and native Windows unverified; see maintenance record.
@Menghuan1918
Menghuan1918 merged commit 6b4f965 into omdsh-dev:dev Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants