Struct epub_builder::Toc
source · pub struct Toc {
pub elements: Vec<TocElement>,
}Expand description
A Table Of Contents
It basically contains a list of TocElements.
Example
Creates a Toc, fills it, and render it to HTML:
use epub_builder::{Toc, TocElement};
Toc::new()
// add a level-1 element
.add(TocElement::new("intro.xhtml", "Introduction"))
// add a level-1 element with children
.add(TocElement::new("chapter_1.xhtml", "Chapter 1")
.child(TocElement::new("chapter_1.xhtml#section1", "1.1: Some section"))
.child(TocElement::new("chapter_1.xhtml#section2", "1.2: another section")))
// add a level-2 element, which will thus get "attached" to previous level-1 element
.add(TocElement::new("chapter_1.xhtml#section3", "1.3: yet another section")
.level(2))
// render the toc (non-numbered list, escape html) and returns a string
.render(false, true);Fields§
§elements: Vec<TocElement>The elements composing the TOC
Implementations§
source§impl Toc
impl Toc
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the toc is empty, false else.
Note that empty here means that the the toc has zero or one
element, since it’s still not worth displaying it in this case.
sourcepub fn add(&mut self, element: TocElement) -> &mut Self
pub fn add(&mut self, element: TocElement) -> &mut Self
Adds a TocElement to the Toc.
This will look at the element’s level and will insert it as a child of the last element of the Toc that has an inferior level.
Example
let mut toc = Toc::new();
// Insert an element at default level (1)
toc.add(TocElement::new("chapter_1.xhtml", "Chapter 1"));
// Insert an element at level 2
toc.add(TocElement::new("section_1.xhtml", "Section 1")
.level(2));
// "Section 1" is now a child of "Chapter 1"There are some cases where this behaviour might not be what you want; however, it makes sure that the TOC can still be renderer correctly for HTML and EPUB.
sourcepub fn render_epub(&mut self, escape_html: bool) -> String
pub fn render_epub(&mut self, escape_html: bool) -> String
Render the Toc in a toc.ncx compatible way, for EPUB.
escape_html: whether titles should be HTML-encoded or not (only applies to titles)
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Toc
impl Send for Toc
impl Sync for Toc
impl Unpin for Toc
impl UnwindSafe for Toc
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more