]>
git.proxmox.com Git - rustc.git/blob - vendor/mdbook/src/lib.rs
3 //! **mdBook** is a tool for rendering a collection of markdown documents into
4 //! a form more suitable for end users like HTML or EPUB. It offers a command
5 //! line interface, but this crate can be used if more control is required.
7 //! This is the API doc, the [user guide] is also available if you want
8 //! information about the command line tool, format, structure etc. It is also
9 //! rendered with mdBook to showcase the features and default theme.
11 //! Some reasons why you would want to use the crate (over the cli):
13 //! - Integrate mdbook in a current project
14 //! - Extend the capabilities of mdBook
15 //! - Do some processing or test before building your book
16 //! - Accessing the public API to help create a new Renderer
19 //! > **Note:** While we try to ensure `mdbook`'s command-line interface and
20 //! > behaviour are backwards compatible, the tool's internals are still
21 //! > evolving and being iterated on. If you wish to prevent accidental
22 //! > breakages it is recommended to pin any tools building on top of the
23 //! > `mdbook` crate to a specific release.
27 //! If creating a new book from scratch, you'll want to get a `BookBuilder` via
28 //! the `MDBook::init()` method.
31 //! use mdbook::MDBook;
32 //! use mdbook::config::Config;
34 //! let root_dir = "/path/to/book/root";
36 //! // create a default config and change a couple things
37 //! let mut cfg = Config::default();
38 //! cfg.book.title = Some("My Book".to_string());
39 //! cfg.book.authors.push("Michael-F-Bryan".to_string());
41 //! MDBook::init(root_dir)
42 //! .create_gitignore(true)
45 //! .expect("Book generation failed");
48 //! You can also load an existing book and build it.
51 //! use mdbook::MDBook;
53 //! let root_dir = "/path/to/book/root";
55 //! let mut md = MDBook::load(root_dir)
56 //! .expect("Unable to load the book");
57 //! md.build().expect("Building failed");
60 //! ## Implementing a new Backend
62 //! `mdbook` has a fairly flexible mechanism for creating additional backends
63 //! for your book. The general idea is you'll add an extra table in the book's
64 //! `book.toml` which specifies an executable to be invoked by `mdbook`. This
65 //! executable will then be called during a build, with an in-memory
66 //! representation ([`RenderContext`]) of the book being passed to the
67 //! subprocess via `stdin`.
69 //! The [`RenderContext`] gives the backend access to the contents of
70 //! `book.toml` and lets it know which directory all generated artefacts should
71 //! be placed in. For a much more in-depth explanation, consult the [relevant
72 //! chapter] in the *For Developers* section of the user guide.
74 //! To make creating a backend easier, the `mdbook` crate can be imported
75 //! directly, making deserializing the `RenderContext` easy and giving you
76 //! access to the various methods for working with the [`Config`].
78 //! [user guide]: https://rust-lang-nursery.github.io/mdBook/
79 //! [`RenderContext`]: renderer/struct.RenderContext.html
80 //! [relevant chapter]: https://rust-lang-nursery.github.io/mdBook/for_developers/backends.html
81 //! [`Config`]: config/struct.Config.html
83 #![deny(missing_docs)]
86 extern crate error_chain
;
87 extern crate handlebars
;
88 extern crate itertools
;
90 extern crate lazy_static
;
94 extern crate pulldown_cmark
;
98 extern crate serde_derive
;
100 extern crate serde_json
;
102 extern crate tempfile
;
104 extern crate toml_query
;
108 extern crate pretty_assertions
;
117 /// The current version of `mdbook`.
119 /// This is provided as a way for custom preprocessors and renderers to do
120 /// compatibility checks.
121 pub const MDBOOK_VERSION
: &str = env
!("CARGO_PKG_VERSION");
123 pub use book
::BookItem
;
124 pub use book
::MDBook
;
125 pub use config
::Config
;
126 pub use renderer
::Renderer
;
128 /// The error types used through out this crate.
130 use std
::path
::PathBuf
;
134 Io(::std
::io
::Error
) #[doc = "A wrapper around `std::io::Error`"];
135 HandlebarsRender(::handlebars
::RenderError
) #[doc = "Handlebars rendering failed"];
136 HandlebarsTemplate(Box
<::handlebars
::TemplateError
>) #[doc = "Unable to parse the template"];
137 Utf8(::std
::string
::FromUtf8Error
) #[doc = "Invalid UTF-8"];
138 SerdeJson(::serde_json
::Error
) #[doc = "JSON conversion failed"];
142 TomlQuery(::toml_query
::error
::Error
, ::toml_query
::error
::ErrorKind
) #[doc = "A TomlQuery error"];
146 /// A subprocess exited with an unsuccessful return code.
147 Subprocess(message
: String
, output
: ::std
::process
::Output
) {
148 description("A subprocess failed")
149 display("{}: {}", message
, String
::from_utf8_lossy(&output
.stdout
))
152 /// An error was encountered while parsing the `SUMMARY.md` file.
153 ParseError(line
: usize, col
: usize, message
: String
) {
154 description("A SUMMARY.md parsing error")
155 display("Error at line {}, column {}: {}", line
, col
, message
)
158 /// The user tried to use a reserved filename.
159 ReservedFilenameError(filename
: PathBuf
) {
160 description("Reserved Filename")
161 display("{} is reserved for internal use", filename
.display())
166 // Box to halve the size of Error
167 impl From
<::handlebars
::TemplateError
> for Error
{
168 fn from(e
: ::handlebars
::TemplateError
) -> Error
{
169 From
::from(Box
::new(e
))