EpubContent

Struct EpubContent 

Source
pub struct EpubContent<R: Read> {
    pub toc: TocElement,
    pub content: R,
    pub reftype: Option<ReferenceType>,
}
Expand description

Represents a XHTML file that can be added to an EPUB document.

This struct is designed to be used with the add_content method of the `EpubBuilder.

§Example

use epub_builder::{EpubContent, TocElement};

let page_content = "Some XHTML content";

// Creates a new EpubContent
let content = EpubContent::new("intro.xhtml", page_content.as_bytes())
// ... and sets a title so it is added to the TOC
    .title("Introduction")
// ... and add some toc information on the document structure
    .child(TocElement::new("intro.xhtml#1", "Section 1"))
    .child(TocElement::new("intro.xhtml#2", "Section 2"));

Fields§

§toc: TocElement

The title and url, plus sublevels

§content: R

The content

§reftype: Option<ReferenceType>

Properties. See EpubProperties

Implementations§

Source§

impl<R: Read> EpubContent<R>

Source

pub fn new<S: Into<String>>(href: S, content: R) -> Self

Creates a new EpubContent

By default, this element is at level 1, and it has no title (meaning it won’t be added to the Table of Contents.

Source

pub fn title<S: Into<String>>(self, title: S) -> Self

Set the title of this content. If no title is set, this part of the book will not be displayed in the table of content.

Source

pub fn raw_title<S: Into<String>>(self, raw_title: S) -> Self

Set the raw title of this content. Only useful if you disable HTML escaping and do it yourself.

This raw title must contain no HTML tags but should still be escaped, e.g. it can contain < or >, but you have to make sure you encode all of this properly.

Source

pub fn level(self, level: i32) -> Self

Set the level

Source

pub fn child(self, elem: TocElement) -> Self

Adds a sublevel to the toc

Source

pub fn reftype(self, reftype: ReferenceType) -> Self

Sets reference type of this content

If this is set, this will list this item as a reference in the guide section.

See www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.3

§Example

Reference an item as the title page:

use epub_builder::{EpubContent, ReferenceType};
let dummy = "Should be a XHTML file";
let item = EpubContent::new("title.xhtml", dummy.as_bytes())
     .title("Title")
     .reftype(ReferenceType::TitlePage);

Trait Implementations§

Source§

impl<R: Debug + Read> Debug for EpubContent<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for EpubContent<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for EpubContent<R>
where R: RefUnwindSafe,

§

impl<R> Send for EpubContent<R>
where R: Send,

§

impl<R> Sync for EpubContent<R>
where R: Sync,

§

impl<R> Unpin for EpubContent<R>
where R: Unpin,

§

impl<R> UnwindSafe for EpubContent<R>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.