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`) and then run:
8
9```sh
10mdbook serve docs
11```
12
13It'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.
14
15Before committing, verify that the docs are formatted in the way Prettier expects with:
16
17```
18cd docs && pnpm dlx prettier@3.5.0 . --write && cd ..
19```
20
21## Preprocessor
22
23We have a custom mdBook preprocessor for interfacing with our crates (`crates/docs_preprocessor`).
24
25If for some reason you need to bypass the docs preprocessor, you can comment out `[preprocessor.zed_docs_preprocessor]` from the `book.toml`.
26
27## Images and videos
28
29To 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.
30
31Putting binary assets such as images in the Git repository will bloat the repository size over time.
32
33## Internal notes:
34
35- We have a Cloudflare router called `docs-proxy` that intercepts requests to `zed.dev/docs` and forwards them to the "docs" Cloudflare Pages project.
36- The CI uploads a new version to the Cloudflare Pages project from `.github/workflows/deploy_docs.yml` on every push to `main`.
37
38### Table of Contents
39
40The 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).
41
42Since all this preprocessor does is generate the static assets, we don't need to keep it around once they have been generated.
43
44## Referencing Keybindings and Actions
45
46When referencing keybindings or actions, use the following formats:
47
48### Keybindings
49
50`{#kb scope::Action}` - e.g., `{#kb zed::OpenSettings}`.
51
52This 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.
53
54By using the action name, we can ensure that the keybinding is always up-to-date rather than hardcoding the keybinding.
55
56#### Keymap Overlays
57
58`{#kb:keymap_name scope::Action}` - e.g., `{#kb:jetbrains editor::GoToDefinition}`.
59
60This 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.
61
62Supported overlays: `jetbrains`.
63
64### Actions
65
66`{#action scope::Action}` - e.g., `{#action zed::OpenSettings}`.
67
68This 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.
69
70### Creating New Templates
71
72Templates are functions that modify the source of the docs pages (usually with a regex match and replace).
73You can see how the actions and keybindings are templated in `crates/docs_preprocessor/src/main.rs` for reference on how to create new templates.
74
75## Consent Banner
76
77We 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:
78
79```
80mkdir c15t-bundle && cd c15t-bundle
81npm init -y
82npm install c15t@<version> esbuild
83echo "import { getOrCreateConsentRuntime } from 'c15t'; window.c15t = { getOrCreateConsentRuntime };" > entry.js
84npx esbuild entry.js --bundle --format=iife --minify --outfile=c15t@<version>.js
85cp c15t@<version>.js ../theme/c15t@<version>.js
86cd .. && rm -rf c15t-bundle
87```
88
89Replace `<version>` with the new version of `c15t` you are installing. Then update `book.toml` to reference the new bundle filename.
90
91### References
92
93- Template Trait: `crates/docs_preprocessor/src/templates.rs`
94- Example template: `crates/docs_preprocessor/src/templates/keybinding.rs`
95- Client-side plugins: `docs/theme/plugins.js`
96
97## Postprocessor
98
99A 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.
100
101An example of the syntax can be found in `git.md`, as well as below:
102
103```md
104---
105title: Some more detailed title for this page
106description: A page-specific description
107---
108
109# Editor
110```
111
112The above code will be transformed into (with non-relevant tags removed):
113
114```html
115<head>
116 <title>Editor | Some more detailed title for this page</title>
117 <meta name="description" contents="A page-specific description" />
118</head>
119<body>
120 <h1>Editor</h1>
121</body>
122```
123
124If 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.
125
126### Implementation details
127
128Unfortunately, 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.
129So 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.
130
131### Known limitations
132
133The front matter parsing is extremely simple, which avoids needing to take on an additional dependency, or implement full YAML parsing.
134
135- 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.
136
137The following will not work:
138
139```md
140---
141title: Some
142 Multi-line
143 Title
144---
145```
146
147neither this:
148
149```md
150---
151title: "Some title"
152---
153```
154
155- The front matter must be at the top of the file, with only white-space preceding it.
156- The contents of the `title` and `description` will not be HTML escaped. They should be simple ASCII text with no unicode or emoji characters.