2018-01-16 21:26:13 -08:00
|
|
|
# Editor
|
|
|
|
|
|
2020-06-22 07:34:25 -07:00
|
|
|
In addition to providing runnable code playgrounds, mdBook optionally allows them
|
2018-08-02 21:34:26 -05:00
|
|
|
to be editable. In order to enable editable code blocks, the following needs to
|
|
|
|
|
be added to the ***book.toml***:
|
2018-01-16 21:26:13 -08:00
|
|
|
|
|
|
|
|
```toml
|
2020-06-22 07:34:25 -07:00
|
|
|
[output.html.playground]
|
2018-01-16 21:26:13 -08:00
|
|
|
editable = true
|
|
|
|
|
```
|
|
|
|
|
|
2018-08-02 21:34:26 -05:00
|
|
|
To make a specific block available for editing, the attribute `editable` needs
|
|
|
|
|
to be added to it:
|
2018-01-16 21:26:13 -08:00
|
|
|
|
2021-12-19 20:26:37 -08:00
|
|
|
~~~markdown
|
|
|
|
|
```rust,editable
|
2018-01-16 21:26:13 -08:00
|
|
|
fn main() {
|
|
|
|
|
let number = 5;
|
|
|
|
|
print!("{}", number);
|
|
|
|
|
}
|
2021-12-19 20:26:37 -08:00
|
|
|
```
|
|
|
|
|
~~~
|
2018-01-16 21:26:13 -08:00
|
|
|
|
2020-06-22 07:34:25 -07:00
|
|
|
The above will result in this editable playground:
|
2018-01-16 21:26:13 -08:00
|
|
|
|
|
|
|
|
```rust,editable
|
|
|
|
|
fn main() {
|
|
|
|
|
let number = 5;
|
|
|
|
|
print!("{}", number);
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-06-22 07:34:25 -07:00
|
|
|
Note the new `Undo Changes` button in the editable playgrounds.
|
2018-01-16 21:26:13 -08:00
|
|
|
|
|
|
|
|
## Customizing the Editor
|
|
|
|
|
|
2018-08-02 21:34:26 -05:00
|
|
|
By default, the editor is the [Ace](https://ace.c9.io/) editor, but, if desired,
|
2021-05-21 12:56:32 +02:00
|
|
|
the functionality may be overridden by providing a different folder:
|
2018-01-16 21:26:13 -08:00
|
|
|
|
|
|
|
|
```toml
|
2020-06-22 07:34:25 -07:00
|
|
|
[output.html.playground]
|
2018-01-16 21:26:13 -08:00
|
|
|
editable = true
|
|
|
|
|
editor = "/path/to/editor"
|
|
|
|
|
```
|
|
|
|
|
|
2018-08-02 21:34:26 -05:00
|
|
|
Note that for the editor changes to function correctly, the `book.js` inside of
|
2021-05-21 12:56:32 +02:00
|
|
|
the `theme` folder will need to be overridden as it has some couplings with the
|
2018-08-02 21:34:26 -05:00
|
|
|
default Ace editor.
|