Render embedded documentation instead of showing HTML source
## How fossil does it
`document_render()` (src/doc.c) dispatches on mimetype:
- `text/x-fossil-wiki`, `text/x-markdown`, `text/x-pikchr` — through its converters - `text/html` — **only if** `doc_is_embedded_html()` passes, which requires the file to begin with `
Fossil does **not** sanitize embedded documents. Its gate is a CSP (src/style.c:631):
default-src 'self' data:; script-src 'self' 'nonce-$nonce'; style-src 'self' 'unsafe-inline'; img-src * data:
Inline script cannot run without the per-response nonce, which repository content cannot know. Note `script-src 'self'` still permits a committed `.js` referenced by `src`, so the model also leans on operator trust plus the `default-csp` setting.
The wrapper is a real convention, not incidental: of the 10 `.html` files in fossil's tree, exactly 3 carry `class='fossil-doc'` — `www/permutedindex.html`, `www/caps/ref.html`, `www/server/index.html`. The other seven are meant to be served raw.
Fossil never rewrites relative links. It does not need to: at `/doc/trunk/www/permutedindex.html` a bare `quickstart.wiki` href resolves to `/doc/trunk/www/quickstart.wiki` on its own. Only `$ROOT` and `$CURRENT` are expanded, and narrowly — inside a tag, after `href=` or `action=` only. That page uses `$ROOT` four times.
## What quarry already has
`renderBody` (internal/api/register.go:1857) is already fossil's mimetype switch. `markup.Render` / `RenderFossilWiki` / `RenderPikchr` are the three converters. `file.get` already resolves symbolic versions like `trunk` through zit. A `/r/{repo}/doc/{version}/{path...}` route has the same shape as the existing file route, so relative links come free exactly as they do for fossil.
## What is missing
1. `/r/{repo}/doc/{version}/{path...}` route and a `doc.get` op 2. Embedded-HTML detection and title extraction (~40 lines; `doc_is_embedded_html` fully specifies it). The title must be read BEFORE sanitizing — the policy strips `class` and `data-title` from the wrapper div 3. `$ROOT` / `$CURRENT` expansion (~30 lines) 4. Raw passthrough for non-document types (images, CSS) so referenced assets resolve. This is where content-type and CSP decisions live, and it is a security decision rather than a rendering one
## Measured: the existing policy is nearly sufficient
Running `markup.Sanitize` over `www/permutedindex.html` (8,754 bytes):
- 125 of 126 links survive - all 126 list items survive - the `id` anchor survives - **lost**: the search `<form>`, and `class`/`data-title` on the wrapper div
## Decision to make
Fossil's answer to hostile HTML is *no sanitizer, one CSP*. Quarry has *a sanitizer, no doc route*. Doing both is strictly stronger than fossil and costs nothing extra since the sanitizer is already written, fuzz-tested and corpus-gated — but some legitimate pages render degraded, such as losing that search form.
Recommendation: ship sanitizer **and** CSP, then widen the policy from evidence. The corpus now carries fossil's, tk's and libspatialite's real doc trees to widen against, which beats widening from imagination.
Estimate: about a day for the fossil-doc path (items 1–3), another day for raw passthrough (item 4).
Shipped. /r/{repo}/doc/{ref}/{path} renders embedded documentation in site chrome instead of showing source. Verified live: /r/fossil/doc/trunk/www/permutedindex.html returns a rendered index with working links.