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### Actions
57
58`{#action scope::Action}` - e.g., `{#action zed::OpenSettings}`.
59
60This 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.
61
62### Creating New Templates
63
64Templates are functions that modify the source of the docs pages (usually with a regex match and replace).
65You can see how the actions and keybindings are templated in `crates/docs_preprocessor/src/main.rs` for reference on how to create new templates.
66
67## Consent Banner
68
69We 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:
70
71```
72mkdir c15t-bundle && cd c15t-bundle
73npm init -y
74npm install c15t@<version> esbuild
75echo "import { getOrCreateConsentRuntime } from 'c15t'; window.c15t = { getOrCreateConsentRuntime };" > entry.js
76npx esbuild entry.js --bundle --format=iife --minify --outfile=c15t@<version>.js
77cp c15t@<version>.js ../theme/c15t@<version>.js
78cd .. && rm -rf c15t-bundle
79```
80
81Replace `<version>` with the new version of `c15t` you are installing. Then update `book.toml` to reference the new bundle filename.
82
83### References
84
85- Template Trait: `crates/docs_preprocessor/src/templates.rs`
86- Example template: `crates/docs_preprocessor/src/templates/keybinding.rs`
87- Client-side plugins: `docs/theme/plugins.js`
88
89## Postprocessor
90
91A 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.
92
93An example of the syntax can be found in `git.md`, as well as below:
94
95```md
96---
97title: Some more detailed title for this page
98description: A page-specific description
99---
100
101# Editor
102```
103
104The above code will be transformed into (with non-relevant tags removed):
105
106```html
107<head>
108 <title>Editor | Some more detailed title for this page</title>
109 <meta name="description" contents="A page-specific description" />
110</head>
111<body>
112 <h1>Editor</h1>
113</body>
114```
115
116If 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.
117
118### Implementation details
119
120Unfortunately, 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.
121So 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.
122
123### Known limitations
124
125The front matter parsing is extremely simple, which avoids needing to take on an additional dependency, or implement full YAML parsing.
126
127- 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.
128
129The following will not work:
130
131```md
132---
133title: Some
134 Multi-line
135 Title
136---
137```
138
139neither this:
140
141```md
142---
143title: "Some title"
144---
145```
146
147- The front matter must be at the top of the file, with only white-space preceding it.
148- The contents of the `title` and `description` will not be HTML escaped. They should be simple ASCII text with no unicode or emoji characters.