pub struct CmdPreprocessor { /* private fields */ }
Expand description

A custom preprocessor which will shell out to a 3rd-party program.

§Preprocessing Protocol

When the supports_renderer() method is executed, CmdPreprocessor will execute the shell command $cmd supports $renderer. If the renderer is supported, custom preprocessors should exit with a exit code of 0, any other exit code be considered as unsupported.

The run() method is implemented by passing a (PreprocessorContext, Book) tuple to the spawned command ($cmd) as JSON via stdin. Preprocessors should then “return” a processed book by printing it to stdout as JSON. For convenience, the CmdPreprocessor::parse_input() function can be used to parse the input provided by mdbook.

Exiting with a non-zero exit code while preprocessing is considered an error. stderr is passed directly through to the user, so it can be used for logging or emitting warnings if desired.

§Examples

An example preprocessor is available in this project’s examples/ directory.

Implementations§

source§

impl CmdPreprocessor

source

pub fn new(name: String, cmd: String) -> CmdPreprocessor

Create a new CmdPreprocessor.

source

pub fn parse_input<R: Read>(reader: R) -> Result<(PreprocessorContext, Book)>

A convenience function custom preprocessors can use to parse the input written to stdin by a CmdRenderer.

source

pub fn cmd(&self) -> &str

The command this Preprocessor will invoke.

Trait Implementations§

source§

impl Clone for CmdPreprocessor

source§

fn clone(&self) -> CmdPreprocessor

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CmdPreprocessor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for CmdPreprocessor

source§

fn eq(&self, other: &CmdPreprocessor) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Preprocessor for CmdPreprocessor

source§

fn name(&self) -> &str

Get the Preprocessor’s name.
source§

fn run(&self, ctx: &PreprocessorContext, book: Book) -> Result<Book>

Run this Preprocessor, allowing it to update the book before it is given to a renderer.
source§

fn supports_renderer(&self, renderer: &str) -> bool

A hint to MDBook whether this preprocessor is compatible with a particular renderer. Read more
source§

impl StructuralPartialEq for CmdPreprocessor

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.