pub struct ContentBuilder {
pub id: String,
/* private fields */
}Expand description
Content Builder
A builder for constructing EPUB content documents with various block types. This builder manages the creation and organization of content blocks including text, quotes, headings, images, audio, video, and MathML content.
Fields§
§id: StringThe unique identifier for the content document
This identifier is used to uniquely identify the content document within the EPUB container. If the identifier is not unique, only one content document will be included in the EPUB container; and the other content document will be ignored.
Implementations§
Source§impl ContentBuilder
impl ContentBuilder
Sourcepub fn new(id: &str, language: &str) -> Result<Self, EpubError>
pub fn new(id: &str, language: &str) -> Result<Self, EpubError>
Creates a new ContentBuilder instance
Initializes a ContentBuilder with the specified language code. A temporary directory is automatically created to store media files during construction.
§Parameters
language: The language code for the document
Sourcepub fn set_title(&mut self, title: &str) -> &mut Self
pub fn set_title(&mut self, title: &str) -> &mut Self
Sets the title of the document
Sets the title that will be displayed in the document’s head section.
§Parameters
title: The title text for the document
Sourcepub fn add_block(&mut self, block: Block) -> Result<&mut Self, EpubError>
pub fn add_block(&mut self, block: Block) -> Result<&mut Self, EpubError>
Adds a block to the document
Adds a constructed Block to the document.
§Parameters
block: The Block to add to the document
Sourcepub fn add_text_block(
&mut self,
content: &str,
footnotes: Vec<Footnote>,
) -> Result<&mut Self, EpubError>
pub fn add_text_block( &mut self, content: &str, footnotes: Vec<Footnote>, ) -> Result<&mut Self, EpubError>
Adds a text block to the document
Convenience method that creates and adds a Text block using the provided content and footnotes.
§Parameters
content: The text content of the paragraphfootnotes: A vector of footnotes associated with the text
Sourcepub fn add_quote_block(
&mut self,
content: &str,
footnotes: Vec<Footnote>,
) -> Result<&mut Self, EpubError>
pub fn add_quote_block( &mut self, content: &str, footnotes: Vec<Footnote>, ) -> Result<&mut Self, EpubError>
Adds a quote block to the document
Convenience method that creates and adds a Quote block using the provided content and footnotes.
§Parameters
content: The quoted textfootnotes: A vector of footnotes associated with the quote
Sourcepub fn add_title_block(
&mut self,
content: &str,
level: usize,
footnotes: Vec<Footnote>,
) -> Result<&mut Self, EpubError>
pub fn add_title_block( &mut self, content: &str, level: usize, footnotes: Vec<Footnote>, ) -> Result<&mut Self, EpubError>
Adds a heading block to the document
Convenience method that creates and adds a Title block with the specified level.
§Parameters
content: The heading textlevel: The heading level (1-6), corresponding to h1-h6 HTML tagsfootnotes: A vector of footnotes associated with the heading
Sourcepub fn add_image_block(
&mut self,
url: PathBuf,
alt: Option<String>,
caption: Option<String>,
footnotes: Vec<Footnote>,
) -> Result<&mut Self, EpubError>
pub fn add_image_block( &mut self, url: PathBuf, alt: Option<String>, caption: Option<String>, footnotes: Vec<Footnote>, ) -> Result<&mut Self, EpubError>
Adds an image block to the document
Convenience method that creates and adds an Image block with optional alt text, caption, and footnotes.
§Parameters
url: The path to the image filealt: Optional alternative text for the image (displayed when image cannot load)caption: Optional caption text to display below the imagefootnotes: A vector of footnotes associated with the caption or image
Sourcepub fn add_audio_block(
&mut self,
url: PathBuf,
fallback: String,
caption: Option<String>,
footnotes: Vec<Footnote>,
) -> Result<&mut Self, EpubError>
pub fn add_audio_block( &mut self, url: PathBuf, fallback: String, caption: Option<String>, footnotes: Vec<Footnote>, ) -> Result<&mut Self, EpubError>
Adds an audio block to the document
Convenience method that creates and adds an Audio block with fallback text, optional caption, and footnotes.
§Parameters
url: The path to the audio filefallback: Fallback text displayed when the audio cannot be playedcaption: Optional caption text to display below the audio playerfootnotes: A vector of footnotes associated with the caption or audio
Sourcepub fn add_video_block(
&mut self,
url: PathBuf,
fallback: String,
caption: Option<String>,
footnotes: Vec<Footnote>,
) -> Result<&mut Self, EpubError>
pub fn add_video_block( &mut self, url: PathBuf, fallback: String, caption: Option<String>, footnotes: Vec<Footnote>, ) -> Result<&mut Self, EpubError>
Adds a video block to the document
Convenience method that creates and adds a Video block with fallback text, optional caption, and footnotes.
§Parameters
url: The path to the video filefallback: Fallback text displayed when the video cannot be playedcaption: Optional caption text to display below the video playerfootnotes: A vector of footnotes associated with the caption or video
Sourcepub fn add_mathml_block(
&mut self,
element_str: String,
fallback_image: Option<PathBuf>,
caption: Option<String>,
footnotes: Vec<Footnote>,
) -> Result<&mut Self, EpubError>
pub fn add_mathml_block( &mut self, element_str: String, fallback_image: Option<PathBuf>, caption: Option<String>, footnotes: Vec<Footnote>, ) -> Result<&mut Self, EpubError>
Adds a MathML block to the document
Convenience method that creates and adds a MathML block with optional fallback image, caption, and footnotes.
§Parameters
element_str: The raw MathML markup stringfallback_image: Optional path to a fallback image displayed when MathML cannot rendercaption: Optional caption text to display below the MathML elementfootnotes: A vector of footnotes associated with the caption or equation
Sourcepub fn remove_last_block(&mut self) -> &mut Self
pub fn remove_last_block(&mut self) -> &mut Self
Removes the last block from the document
Discards the most recently added block. If no blocks exist, this method has no effect.
Sourcepub fn take_last_block(&mut self) -> Option<Block>
pub fn take_last_block(&mut self) -> Option<Block>
Takes ownership of the last block
Removes and returns the most recently added block without consuming the builder. This allows you to extract a block while keeping the builder alive.
§Return
Some(Block): If a block existsNone: If the blocks collection is empty
Sourcepub fn clear_blocks(&mut self) -> &mut Self
pub fn clear_blocks(&mut self) -> &mut Self
Clears all blocks from the document
Removes all blocks from the document while keeping the language and title settings intact.