# Inline code

> Display a code fragment in a line of text with a monospace font.

Inline code adds the `code` mark. Use it for a function name, a command such as `cargo build`, or a short code fragment within a sentence.

## Try it

[Try the inline-code editor example](https://gpdoc.dev/docs/plugins/formatting/inline-code/#inline-code-example)

## Install

```sh
cargo add gpdoc-plugin-inline-code
```

## Example

Register the inline code formatter in the [Quickstart editor configuration](/docs/quickstart/#configure-the-editor). `inline_code()` uses this formatter by default.

```rust
use gpdoc::{EditorConfig, PluginViewExt};
use gpdoc_plugin_inline_code::{inline_code, inline_code_format};
use gpdoc_plugin_paragraph::paragraph;


let config = EditorConfig::builder()
    .plugin(paragraph())
    .plugin(inline_code().with_view(inline_code_format))
    .build()
    .expect("configure editor");
```

Surround `cargo build` with single backticks in a paragraph. The editor removes the backticks and displays the command in monospace.

## Commands

These commands take no arguments. Select text to change its formatting, or place the caret where you want to start typing. `editor.run` returns `Result<CommandOutcome, Error>`. A handled command returns `Applied(AppliedChange)`. Set and toggle return `NotApplicable` if no text can take the mark.

### `setCode`

Apply inline code to the selection or to the next characters typed at the caret.

```rust
editor.run(gpdoc_plugin_inline_code::Set)?;
```

### `toggleCode`

Switch inline code off when the whole eligible selection has the mark. On a mixed selection, apply it throughout.

```rust
editor.run(gpdoc_plugin_inline_code::Toggle)?;
```

### `unsetCode`

Clear inline code from the selection or turn it off for subsequent typing.

```rust
editor.run(gpdoc_plugin_inline_code::Unset)?;
```

## Keyboard shortcuts

Toggle inline code with **Command + E** on macOS or **Ctrl + E** on Windows and Linux.

Wrap a phrase in single backticks to apply inline code as you type. The `code` mark excludes other marks on the same text.