Skip to content
gpdoc
Playground

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.

Terminal window
cargo add gpdoc-plugin-inline-code

Register the inline code formatter in the Quickstart editor configuration. inline_code() uses this formatter by default.

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.

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.

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

editor.run(gpdoc_plugin_inline_code::Set)?;

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

editor.run(gpdoc_plugin_inline_code::Toggle)?;

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

editor.run(gpdoc_plugin_inline_code::Unset)?;

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.