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
impl CmdPreprocessor
Sourcepub fn new(name: String, cmd: String) -> CmdPreprocessor
pub fn new(name: String, cmd: String) -> CmdPreprocessor
Create a new CmdPreprocessor
.
Sourcepub fn parse_input<R: Read>(reader: R) -> Result<(PreprocessorContext, Book)>
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
.
Trait Implementations§
Source§impl Clone for CmdPreprocessor
impl Clone for CmdPreprocessor
Source§fn clone(&self) -> CmdPreprocessor
fn clone(&self) -> CmdPreprocessor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more