Skip to main content

Block

Enum Block 

Source
#[non_exhaustive]
pub enum Block {
#[non_exhaustive]
Text { content: String, footnotes: Vec<Footnote>, },
#[non_exhaustive]
Quote { content: String, footnotes: Vec<Footnote>, },
#[non_exhaustive]
Title { content: String, footnotes: Vec<Footnote>, level: usize, },
#[non_exhaustive]
Image { url: PathBuf, alt: Option<String>, caption: Option<String>, footnotes: Vec<Footnote>, },
#[non_exhaustive]
Audio { url: PathBuf, fallback: String, caption: Option<String>, footnotes: Vec<Footnote>, },
#[non_exhaustive]
Video { url: PathBuf, fallback: String, caption: Option<String>, footnotes: Vec<Footnote>, },
#[non_exhaustive]
MathML { element_str: String, fallback_image: Option<PathBuf>, caption: Option<String>, footnotes: Vec<Footnote>, }, }
Expand description

Content Block

The content block is the basic unit of content in a content document. It can be one of the following types: Text, Quote, Title, Image, Audio, Video, MathML.

For each type of block, we can add a footnote to it, where Text, Quote and Title’s footnote will be added to the content and Image, Audio, Video and MathML’s footnote will be added to the caption.

Each block type has its own structure and required fields. We show the structure of each block so that you can manually write css files for Content for a more beautiful interface.

In addition, the footnote index in the body has the following structure:

<a href="#footnote-1" id="ref-1" class="footnote-ref">[1]</a>

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

#[non_exhaustive]
Text

Text paragraph

This block represents a paragraph of text. The block structure is as follows:

<p class="content-block text-block">
    {{ text.content }}
</p>

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§content: String
§footnotes: Vec<Footnote>
§

#[non_exhaustive]
Quote

Quote paragraph

This block represents a paragraph of quoted text. The block structure is as follows:

<blockquote class="content-block quote-block">
    {{ quote.content }}
</blockquote>

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§content: String
§footnotes: Vec<Footnote>
§

#[non_exhaustive]
Title

Heading

The block structure is as follows:

<h1 class="content-block title-block">
    {{ title.content }}
</h1>

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§content: String
§footnotes: Vec<Footnote>
§level: usize

Heading level

The valid range is 1 to 6.

§

#[non_exhaustive]
Image

Image block

The block structure is as follows:

<figure class="content-block image-block">
    <img src="{{ image.url }}" alt="{{ image.alt }}" />
    <figcaption>
        {{ image.caption }}
    </figcaption>
</figure>

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§url: PathBuf

Image file path

§alt: Option<String>

Alternative text for the image

§caption: Option<String>

Caption for the image

§footnotes: Vec<Footnote>
§

#[non_exhaustive]
Audio

Audio block

The block structure is as follows:

<figure class="content-block audio-block">
    <audio src="{{ audio.url }}" controls>
       <p>{{ audio.fallback }}</p>
   </audio>
   <figcaption>
      Audio caption text
  </figcaption>
</figure>

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§url: PathBuf

Audio file path

§fallback: String

Fallback text for the audio

This is used when the audio file cannot be played.

§caption: Option<String>

Caption for the audio

§footnotes: Vec<Footnote>
§

#[non_exhaustive]
Video

Video block

The block structure is as follows:

<figure class="content-block video-block">
    <video src="{{ video.url }}" controls>
        <p>{{ video.fallback }}</p>
    </video>
    <figcaption>
        {{ video.caption }}
    </figcaption>
</figure>

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§url: PathBuf

Video file path

§fallback: String

Fallback text for the video

This is used when the video file cannot be played.

§caption: Option<String>

Caption for the video

§footnotes: Vec<Footnote>
§

#[non_exhaustive]
MathML

MathML block

The block structure is as follows:

<figure class="content-block mathml-block">
    {{ mathml.element_str as innerHTML }}
    <img src="{{ mathml.fallback_image }}" class="mathml-fallback" />
    <figcaption>
        {{ mathml.caption }}
    </figcaption>
</figure>
§Notes
  • The MathML markup is inserted directly without validation. Users must ensure the MathML is well-formed.
  • The fallback image is displayed when the reading system doesn’t support MathML.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§element_str: String

MathML element raw data

This field stores the raw data of the MathML markup, which we do not verify, and the user needs to make sure it is correct.

§fallback_image: Option<PathBuf>

Fallback image for the MathML block

This field stores the path to the fallback image, which will be displayed when the MathML markup cannot be rendered.

§caption: Option<String>

Caption for the MathML block

§footnotes: Vec<Footnote>

Implementations§

Trait Implementations§

Source§

impl Debug for Block

Source§

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

Formats the value using the given formatter. Read more
Source§

impl TryFrom<BlockBuilder> for Block

Source§

type Error = EpubError

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

fn try_from(builder: BlockBuilder) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Block

§

impl RefUnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnsafeUnpin for Block

§

impl UnwindSafe for Block

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> Same for T

Source§

type Output = T

Should always be Self
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.