Struct crowbook::Book
[−]
[src]
pub struct Book { /* fields omitted */ }
A Book.
Probably the central structure for of Crowbook, as it is the one that calls the other ones.
It has the tasks of loading a configuration file, loading chapters
and using Parser
to parse them, and then calling various renderers
(HtmlRendrer
, LatexRenderer
, EpubRenderer
and/or OdtRenderer
)
to convert the AST into documents.
Examples
use crowbook::{Book, Number}; // Create a book with some options let mut book = Book::new(&[("author", "Joan Doe"), ("title", "An untitled book"), ("lang", "en")]); // Add content to the book book.add_chapter_as_str(Number::Default, "# The beginning#\nBla, bla, bla").unwrap(); // Render the book as html to stdout book.render_html(&mut std::io::stdout()).unwrap();Run
Methods
impl Book
[src]
fn new<'a, I>(options: I) -> Book where I: IntoIterator<Item=&'a (&'a str, &'a str)>
Creates a new Book
with given options
Arguments
*options
a list (or other iterator) of (key, value) tuples. Can be &[].
fn new_from_file<'a, I>(filename: &str, verbosity: InfoLevel, options: I) -> Result<Book> where I: IntoIterator<Item=&'a (&'a str, &'a str)>
Creates a new book from a file, with options
Arguments
filename
: the path of file to load. The directory of this file is used as a "root" directory for all paths referenced in books, whether chapter files, templates, cover images, and so on.- `verbosity: sets the book verbosity
options
: a list of (key, value) options to pass to the book
fn new_from_markdown_file<'a, I>(filename: &str, verbosity: InfoLevel, options: I) -> Result<Book> where I: IntoIterator<Item=&'a (&'a str, &'a str)>
Creates a book from a single markdown file
fn set_from_config(&mut self, s: &str) -> Result<()>
Sets options and load chapters according to configuration file
A line with "option: value" sets the option to value
chapter_name.md adds the (default numbered) chapter
chapter_name.md adds the (unnumbered) chapter
- chapter_name.md adds the (custom numbered) chapter
fn render_all(&self)
Generates output files acccording to book options
fn render_pdf(&self) -> Result<()>
Render book to pdf according to book options
fn render_epub(&self) -> Result<()>
Render book to epub according to book options
fn render_html_dir(&self) -> Result<()>
Render book to HTML directory according to book options
fn render_proof_html_dir(&self) -> Result<()>
Render book to HTML directory according to book options (proofread version)
fn render_proof_pdf(&self) -> Result<()>
Render book to PDF according to book options (proofread version)
fn render_odt(&self) -> Result<()>
Render book to odt according to book options
fn render_html<T: Write>(&self, f: &mut T) -> Result<()>
Render book to html according to book options
fn render_proof_html<T: Write>(&self, f: &mut T) -> Result<()>
Render book to html according to book options (proofread version)
fn render_tex<T: Write>(&self, f: &mut T) -> Result<()>
Render book to pdf according to book options
fn render_proof_tex<T: Write>(&self, f: &mut T) -> Result<()>
Render book to pdf according to book options (proofread version)
fn add_chapter(&mut self, number: Number, file: &str) -> Result<()>
Adds a chapter, as a file name, to the book
Book
will then parse the file and store the AST (i.e., a vector
of Token
s).
Arguments
number
: specifies if the chapter must be numbered, not numbered, or if its title must be hidden. SeeNumber
.file
: path of the file for this chapter
Returns an error if file
does not exist, could not be read, of if there was
some error parsing it.
fn add_chapter_as_str(&mut self, number: Number, content: &str) -> Result<()>
Adds a chapter, as a string, to the book
Book
will then parse the string and store the AST (i.e., a vector
of Token
s).
Arguments
number
: specifies if the chapter must be numbered, not numbered, or if its title must be hidden. SeeNumber
.content
: the content of the chapter.
Returns an error if there was some errror parsing content
.