Add docs_preprocessor crate to support Zed Docs (#16700)
This PR adds a mdbook preprocessor for supporting Zed's docs.
This initial version adds the following custom commands:
**Keybinding**
`{#kb prefix::action_name}` (e.g. `{#kb zed::OpenSettings}`)
Outputs a keybinding template like `<kbd
class="keybinding">{macos_keybinding}|{linux_keybinding}</kbd>`. This
template is processed on the client side through `mdbook` to show the
correct keybinding for the user's platform.
**Action**
`{#action prefix::action_name}` (e.g. `{#action zed::OpenSettings}`)
For now, simply outputs the action name in a readable manner. (e.g.
zed::OpenSettings -> zed: open settings)
In the future we'll add additional modes for this template, like create
a standard way to render `{action} ({keybinding})`.
## Example Usage
```
To open the assistant panel, toggle the right dock by using the {#action workspace::ToggleRightDock} action in the command palette or by using the
{#kb workspace::ToggleRightDock} shortcut.
```
Release Notes:
- N/A
This commit is contained in:
@@ -22,10 +22,34 @@ pub struct KeymapBlock {
|
||||
bindings: BTreeMap<String, KeymapAction>,
|
||||
}
|
||||
|
||||
impl KeymapBlock {
|
||||
pub fn context(&self) -> Option<&str> {
|
||||
self.context.as_deref()
|
||||
}
|
||||
|
||||
pub fn bindings(&self) -> &BTreeMap<String, KeymapAction> {
|
||||
&self.bindings
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Default, Clone)]
|
||||
#[serde(transparent)]
|
||||
pub struct KeymapAction(Value);
|
||||
|
||||
impl ToString for KeymapAction {
|
||||
fn to_string(&self) -> String {
|
||||
match &self.0 {
|
||||
Value::String(s) => s.clone(),
|
||||
Value::Array(arr) => arr
|
||||
.iter()
|
||||
.map(|v| v.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
_ => self.0.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl JsonSchema for KeymapAction {
|
||||
fn schema_name() -> String {
|
||||
"KeymapAction".into()
|
||||
@@ -135,6 +159,10 @@ impl KeymapFile {
|
||||
|
||||
serde_json::to_value(root_schema).unwrap()
|
||||
}
|
||||
|
||||
pub fn blocks(&self) -> &[KeymapBlock] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
fn no_action() -> Box<dyn gpui::Action> {
|
||||
|
||||
Reference in New Issue
Block a user