use crate::texts::{CH01, CH01_NAMED, CH02, CH03, ID, PLAIN, ROTATED};
use mbook::{Book, Landmark, Result};
pub(crate) fn book() -> Result<Book> {
let mut book = Book::new("The Example", "en")?;
book.meta_mut().set_id(ID)?;
book.meta_mut().add_author("A. Writer")?;
book.set_cover("img/cover.avif", PLAIN)?;
book.add_chapter("ch01.md", CH01)?;
book.add_chapter("ch02.md", CH02)?;
book.add_picture("img/fig-1.avif", ROTATED)?;
Ok(book)
}
pub(crate) fn annotated() -> Result<Book> {
let mut book = book()?;
if let Some(chapter) = book.chapter_mut("ch01.md") {
chapter.set_text(CH01_NAMED)?;
}
book.add_chapter("ch03.md", CH03)?;
Ok(book)
}
pub(crate) fn with_landmarks() -> Result<Book> {
let mut book = annotated()?;
book.set_landmarks(vec![
Landmark::new("start", "", "ch01.md"),
Landmark::new("preface", "", "ch01.md#the-station"),
Landmark::new("list-of-figures", "Figures", "ch01.md#fig-1"),
Landmark::new("x-letter", "The letter", "ch02.md"),
])?;
Ok(book)
}
#[cfg(feature = "read")]
pub(crate) fn bytes() -> Result<Vec<u8>> {
let mut bytes = Vec::new();
book()?.write(&mut bytes)?;
Ok(bytes)
}