Struct crowbook::Book [] [src]

pub struct Book {
    pub chapters: Vec<(Number, Vec<Token>)>,
    pub filenames: Vec<String>,
    pub options: BookOptions,
    pub root: PathBuf,
    pub logger: Logger,
    // some 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 Parserto 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();

Fields

Internal structure. You should not accesss this directly except if you are writing a new renderer.

A list of the filenames of the chapters

Options of the book

Root path of the book

Logger

Methods

impl Book
[src]

Creates a new Book with given options

Arguments

*options a list (or other iterator) of (key, value) tuples. Can be &[].

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

Creates a book from a single markdown file

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

  1. chapter_name.md adds the (custom numbered) chapter

Generates output files acccording to book options

Render book to pdf according to book options

Render book to epub according to book options

Render book to HTML directory according to book options

Render book to odt according to book options

Render book to html according to book options

Render book to pdf according to book options

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 Tokens).

Arguments

  • number: specifies if the chapter must be numbered, not numbered, or if its title must be hidden. See Number.
  • 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.

Adds a chapter, as a string, to the book

Book will then parse the string and store the AST (i.e., a vector of Tokens).

Arguments

  • number: specifies if the chapter must be numbered, not numbered, or if its title must be hidden. See Number.
  • content: the content of the chapter.

Returns an error if there was some errror parsing content.

Either clean a string or does nothing, according to book lang and autoclean options

Returns the template (default or modified version)

Returns the string corresponding to a number, title, and the numbering template

Returns a MapBuilder (used by Mustache for templating), to be used (and completed) by renderers. It fills it with the followings strings, corresponding to the matching Book options:

  • "author"
  • "title"
  • "lang"

It also uses the lang/xx.yaml file corresponding to the language and fills loc_xxx fiels with it that corresponds to translated versions