1# Zed Docs
2
3Welcome to Zed's documentation.
4
5This is built on push to `main` and published automatically to [https://zed.dev/docs](https://zed.dev/docs).
6
7To preview the docs locally you will need to install [mdBook](https://rust-lang.github.io/mdBook/) (`cargo install mdbook@0.4.40`), generate the action metadata, and then serve:
8
9```sh
10script/generate-action-metadata
11mdbook serve docs
12```
13
14The first command dumps an action manifest to `crates/docs_preprocessor/actions.json`. Without it, the preprocessor cannot validate keybinding and action references in the docs and will report errors. You only need to re-run it when actions change.
15
16It's important to note the version number above. For an unknown reason, as of 2025-04-23, running 0.4.48 will cause odd URL behavior that breaks things.
17
18Before committing, verify that the docs are formatted in the way Prettier expects with:
19
20```
21cd docs && pnpm dlx prettier@3.5.0 . --write && cd ..
22```
23
24## Preprocessor
25
26We have a custom mdBook preprocessor for interfacing with our crates (`crates/docs_preprocessor`).
27
28If for some reason you need to bypass the docs preprocessor, you can comment out `[preprocessor.zed_docs_preprocessor]` from the `book.toml`.
29
30## Images and videos
31
32To add images or videos to the docs, upload them to another location (e.g., zed.dev, GitHub's asset storage) and then link out to them from the docs.
33
34Putting binary assets such as images in the Git repository will bloat the repository size over time.
35
36## Internal notes:
37
38- We have a Cloudflare router called `docs-proxy` that intercepts requests to `zed.dev/docs` and forwards them to the "docs" Cloudflare Pages project.
39- The CI uploads a new version to the Cloudflare Pages project from `.github/workflows/deploy_docs.yml` on every push to `main`.
40
41### Table of Contents
42
43The table of contents files (`theme/page-toc.js` and `theme/page-doc.css`) were initially generated by [`mdbook-pagetoc`](https://crates.io/crates/mdbook-pagetoc).
44
45Since all this preprocessor does is generate the static assets, we don't need to keep it around once they have been generated.
46
47## Referencing Keybindings and Actions
48
49When referencing keybindings or actions, use the following formats:
50
51### Keybindings
52
53`{#kb scope::Action}` - e.g., `{#kb zed::OpenSettings}`.
54
55This will output a code element like: `<code>Cmd + , | Ctrl + ,</code>`. We then use a client-side plugin to show the actual keybinding based on the user's platform.
56
57By using the action name, we can ensure that the keybinding is always up-to-date rather than hardcoding the keybinding.
58
59#### Keymap Overlays
60
61`{#kb:keymap_name scope::Action}` - e.g., `{#kb:jetbrains editor::GoToDefinition}`.
62
63This resolves the keybinding from a keymap overlay (e.g., JetBrains) first, falling back to the default keymap if the overlay doesn't define a binding for that action. This is useful for sections where the documentation expects a special base keymap to be configured.
64
65Supported overlays: `jetbrains`.
66
67### Actions
68
69`{#action scope::Action}` - e.g., `{#action zed::OpenSettings}`.
70
71This will render a human-readable version of the action name, e.g., "zed: open settings", and will allow us to implement things like additional context on hover, etc.
72
73### Creating New Templates
74
75Templates are functions that modify the source of the docs pages (usually with a regex match and replace).
76You can see how the actions and keybindings are templated in `crates/docs_preprocessor/src/main.rs` for reference on how to create new templates.
77
78## Consent Banner
79
80We pre-bundle the `c15t` package because the docs pipeline does not include a JS bundler. If you need to update `c15t` and rebuild the bundle, use:
81
82```
83mkdir c15t-bundle && cd c15t-bundle
84npm init -y
85npm install c15t@<version> esbuild
86echo "import { getOrCreateConsentRuntime } from 'c15t'; window.c15t = { getOrCreateConsentRuntime };" > entry.js
87npx esbuild entry.js --bundle --format=iife --minify --outfile=c15t@<version>.js
88cp c15t@<version>.js ../theme/c15t@<version>.js
89cd .. && rm -rf c15t-bundle
90```
91
92Replace `<version>` with the new version of `c15t` you are installing. Then update `book.toml` to reference the new bundle filename.
93
94### References
95
96- Template Trait: `crates/docs_preprocessor/src/templates.rs`
97- Example template: `crates/docs_preprocessor/src/templates/keybinding.rs`
98- Client-side plugins: `docs/theme/plugins.js`
99
100## Postprocessor
101
102A postprocessor is implemented as a sub-command of `docs_preprocessor` that wraps the built-in HTML renderer and applies post-processing to the HTML files, to add support for page-specific title and `meta` tag description values.
103
104An example of the syntax can be found in `git.md`, as well as below:
105
106```md
107---
108title: Some more detailed title for this page
109description: A page-specific description
110---
111
112# Editor
113```
114
115The above code will be transformed into (with non-relevant tags removed):
116
117```html
118<head>
119 <title>Editor | Some more detailed title for this page</title>
120 <meta name="description" contents="A page-specific description" />
121</head>
122<body>
123 <h1>Editor</h1>
124</body>
125```
126
127If no front matter is provided, or if one or both keys aren't provided, the `title` and `description` will be set based on the `default-title` and `default-description` keys in `book.toml` respectively.
128
129### Implementation details
130
131Unfortunately, mdBook does not support post-processing like it does pre-processing, and only supports defining one description to put in the `meta` tag per book rather than per file.
132So in order to apply post-processing (necessary to modify the HTML `head` tags) the global book description is set to a marker value `#description#` and the HTML renderer is replaced with a sub-command of `docs_preprocessor` that wraps the built-in HTML renderer and applies post-processing to the HTML files, replacing the marker value and the `<title>(.*)</title>` with the contents of the front matter if there is one.
133
134### Known limitations
135
136The front matter parsing is extremely simple, which avoids needing to take on an additional dependency, or implement full YAML parsing.
137
138- Double quotes and multi-line values are not supported, i.e. Keys and values must be entirely on the same line, with no double quotes around the value.
139
140The following will not work:
141
142```md
143---
144title: Some
145 Multi-line
146 Title
147---
148```
149
150neither this:
151
152```md
153---
154title: "Some title"
155---
156```
157
158- The front matter must be at the top of the file, with only white-space preceding it.
159- The contents of the `title` and `description` will not be HTML escaped. They should be simple ASCII text with no unicode or emoji characters.