README.md

  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### References
 68
 69- Template Trait: `crates/docs_preprocessor/src/templates.rs`
 70- Example template: `crates/docs_preprocessor/src/templates/keybinding.rs`
 71- Client-side plugins: `docs/theme/plugins.js`
 72
 73## Postprocessor
 74
 75A 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.
 76
 77An example of the syntax can be found in `git.md`, as well as below:
 78
 79```md
 80---
 81title: Some more detailed title for this page
 82description: A page-specific description
 83---
 84
 85# Editor
 86```
 87
 88The above code will be transformed into (with non-relevant tags removed):
 89
 90```html
 91<head>
 92  <title>Editor | Some more detailed title for this page</title>
 93  <meta name="description" contents="A page-specific description" />
 94</head>
 95<body>
 96  <h1>Editor</h1>
 97</body>
 98```
 99
100If 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.
101
102### Implementation details
103
104Unfortunately, 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.
105So 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.
106
107### Known limitations
108
109The front matter parsing is extremely simple, which avoids needing to take on an additional dependency, or implement full YAML parsing.
110
111- 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.
112
113The following will not work:
114
115```md
116---
117title: Some
118  Multi-line
119  Title
120---
121```
122
123neither this:
124
125```md
126---
127title: "Some title"
128---
129```
130
131- The front matter must be at the top of the file, with only white-space preceding it.
132- The contents of the `title` and `description` will not be HTML escaped. They should be simple ASCII text with no unicode or emoji characters.