The desktop shell serves the GUI from the dsh-app://app/ origin while the
Host listens on another site (__DSH_TRANSPORT__.streamBaseUrl). Markdown
preview images were rewritten to an absolute /sidebar/file URL on that
TRANSPORT origin, so from the shell page the request was cross-site: the
Connection fence rejected it (403, Sec-Fetch-Site + a SameSite=Strict
session cookie the shell never forwards for plain http subresources) and
MarkdownText fell back to the image's alt text. Disabling the plugin
worked because the built-in document preview resolves images against the
page base.
Resolve local markdown images through the renderer's pathImages vocabulary
on the PAGE base instead of pre-rewriting destinations: in a browser the
plugin media route stays byte-for-byte what it was, and in the desktop
shell the vocabulary maps to the Host's authenticated api/file route
(dsh-app://app/api/file?...), the only local-file shape the renderer
accepts from that page and the same shape the built-in document preview
uses. Images stay plain <img> elements, so the preview keeps the size the
browser/built-in previews have (no chat thumbnail cap or lightbox chrome).
The host file route requires an ABSOLUTE path (a relative one answers
400 "absolute path required"), while an editor tab opened from a chat
address can carry a workspace-relative path (the plugin's own media route
resolved that via its cwd parameter). The desktop branch therefore joins
the session workspace root before building the URL, and falls back to alt
text when no root is known instead of requesting a guaranteed 400.
Raw HTML <img src> leaves keep the direct rewrite, now also page-based.
Image references stay as authored, so the link pass leaves an
image-referenced definition alone (a link-only definition is still pinned
inert).
Regression coverage renders the real MarkdownText in jsdom with the
desktop page origin (markdown images must render as
dsh-app://app/api/file?..., raw-HTML images as dsh-app://app/sidebar/file...,
not alt text) and pins the relative-tab-path → absolute-target rule.
The http-page assertions are unchanged.
Design notes: docs/plans/2026-10-23-desktop-markdown-media-base.md
Two defects the independent verification rejected, plus the test gaps they
left behind.
1. `githubHeadingSlug` was not GitHub's slugger. It trimmed and collapsed
whitespace runs (GitHub does neither: every space becomes its own dash) and
kept `\p{M}`, which left the variation selector of `🖼️` inside the id. The
consequence was the issue's main scenario: the repo's OWN READMEs resolved
**0 of 15** table-of-contents anchors, and the click was claimed yet did
nothing (`scrollTop` stayed 0). The slug is now `toLowerCase()`, drop
pictographs / `\uFE00-\uFE0F` / regional indicators / `\p{C}`, drop
everything that is not a letter, digit, combining mark, space, `-` or `_`,
then each space → `-`. Emoji are removed here because GitHub removes them
while RENDERING the heading (to `<img>`) before its slugger runs; that is
the one deliberate difference from `github-slugger`, and it is what turns
`🚀 安装` into GitHub's real `-安装`.
2. Both source rewriters inlined a fence mask that only recognised ```, so a
link or image demonstrated inside a `~~~` fence was rewritten
(`[y](./b.md#u)` → `[y](./b.md%23u)`; the image half predates this feature:
`rewriteLocalImageUrls('~~~\n\n~~~')` already produced a
`/sidebar/file` URL on 58d7f71). One shared mask now lives in
`src/client/markdown-code.ts` (CommonMark: 3+ backticks OR 3+ tildes, a
closing fence no shorter than its opener, an unclosed fence running to the
end of the text) and both passes use it.
Evidence (all on the merged tree, HEAD after `git merge origin/dev`):
- Real `TextEditor` + real host `MarkdownText`, every TOC anchor clicked:
README.md `0/15 → 15/15`, README_EN.md `0/15 → 15/15` (shipped as a case in
tests/markdown-surface.spec.tsx; the id-level counts are 0/16 → 16/16).
- Parity against the actual `github-slugger@2.0.0` regex (vendored in
tests/helpers/github-slug-reference.ts), plus explicit emoji/VS16 cases.
- Mutation: restoring the old trim+collapse+`\p{M}` slug reddens 9 cases
(both README cases included); dropping the tilde fence reddens the new
fence case in BOTH the link and the image spec; forcing `scrollHostFor` to
return the container reddens the two new ancestor-scroller cases.
- `scrollHostFor`'s ancestor branch was unreachable from the shipped suite
(the mutation above used to leave 33/33 green): tests/markdown-surface.spec.tsx
now injects the computed style (`overflowY: auto` + `scrollHeight`/
`clientHeight`) and asserts the write lands on the ancestor, that neither
`window.scrollTo` nor `scrollIntoView` is called, and that the container's
own `scrollTop` is never written.
Also: the untrue "exactly like GitHub does" comment, four-form fence cases per
pass (``` / ```` / ~~~ / an inline span inside ~~~), a CHANGELOG entry, and the
recorded narrow edges (a destination with an escaped parenthesis or a
single-quoted title is not claimed — plain text, unchanged; `#L24` does not
jump to a line).
Gates: typecheck / lint clean, `vitest run --maxWorkers=3` 182 files, 2120
passed | 13 skipped; `pnpm build` complete; mount lane
(`DSH_CMD='npx -y --package @deepseek-ai/dsh@0.2.0-rc.1 dsh' pnpm test:mount`)
9 passed (2.0m), exit 0. The bare `pnpm test:mount` now dies in preflight
because the installed CLI is 0.2.0-rc.2 while the baseline pins 0.2.0-rc.1;
the lane count is 9 rather than the verifier's 11 because merging origin/dev
removed the two WCO/preset cases with the titleBar mechanism.
Markdown surfaces the plugin draws (editor preview, side-chat transcript,
changes reading pane, task note) now open local markdown links in the sidebar
and follow same-page / cross-file heading anchors.
The host renderer decides what a local destination even is: without a
`MarkdownDelegateProvider.openFile` a local link renders as plain text (there is
no `a[href]` to intercept), and `parseFileLink` accepts a fragment only in the
line grammar (`#L24`), so a heading fragment makes the whole destination
unparseable. So the claim is scoped by the provider (one per surface) and a
SOURCE pass carries a heading fragment past the parser as `%23` — the same shape
markdown-images.ts already uses for relative image destinations. Destinations
the plugin does not claim (non-markdown, remote, queried) keep rendering exactly
as they do today.
- `markdown-navigation.ts`: pure link judge + GitHub heading slugs (Chinese kept,
duplicates `-1`, authored ids reserved first), collapsed-anchor hiding, the
source rewrite, the jump that scrolls the surface's OWN scroller (never
`window`/`scrollIntoView`), and the session+path keyed pending fragment table.
- `use-markdown-surface.ts`: one hook per surface — the container callback ref
(DOM pass + mutation re-runs + pending fragment) and the delegate's `openFile`.